diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-07-24 15:04:18 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-07-24 15:04:18 +0000 |
commit | d6f7078aab3050629a63d9b9d92f30e1ca5a9aa1 (patch) | |
tree | 89582baaf2e88fa8341b08c8b9097bc5161cb59f /src/libstddjb/cdb_init.c | |
parent | dd6bb6c6b8298ebeff2d1882becb36580b969d6f (diff) | |
download | skalibs-d6f7078aab3050629a63d9b9d92f30e1ca5a9aa1.tar.gz skalibs-d6f7078aab3050629a63d9b9d92f30e1ca5a9aa1.tar.xz skalibs-d6f7078aab3050629a63d9b9d92f30e1ca5a9aa1.zip |
Add cdb_init_at and cdb_init_fromfd, rename cdb_reader
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/cdb_init.c')
-rw-r--r-- | src/libstddjb/cdb_init.c | 24 |
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 ; } |