From d6f7078aab3050629a63d9b9d92f30e1ca5a9aa1 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 24 Jul 2021 15:04:18 +0000 Subject: Add cdb_init_at and cdb_init_fromfd, rename cdb_reader Signed-off-by: Laurent Bercot --- src/libstddjb/cdb_init.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'src/libstddjb/cdb_init.c') 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 -#include -#include -#include - #include #include 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 ; } -- cgit v1.2.3