summaryrefslogtreecommitdiff
path: root/src/libstddjb/cdb_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/cdb_init.c')
-rw-r--r--src/libstddjb/cdb_init.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/libstddjb/cdb_init.c b/src/libstddjb/cdb_init.c
index 7a6c2f6..fad6a2c 100644
--- a/src/libstddjb/cdb_init.c
+++ b/src/libstddjb/cdb_init.c
@@ -1,31 +1,17 @@
/* ISC license. */
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <stdint.h>
-#include <errno.h>
-
#include <skalibs/djbunix.h>
#include <skalibs/cdb.h>
int cdb_init (cdb *c, char const *file)
{
- char *map ;
- struct stat st ;
int fd = openc_read(file) ;
if (fd < 0) return 0 ;
- if (fstat(fd, &st) < 0) goto err ;
- if (st.st_size > UINT32_MAX) goto eoverf ;
- map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
- if (map == MAP_FAILED) goto err ;
- c->map = map ;
- c->size = st.st_size ;
+ if (!cdb_init_fromfd(c, fd))
+ {
+ fd_close(fd) ;
+ return 0 ;
+ }
fd_close(fd) ;
return 1 ;
-
- eoverf:
- errno = EOVERFLOW ;
- err:
- fd_close(fd) ;
- return 0 ;
}