From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/cdb_read.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/libstddjb/cdb_read.c (limited to 'src/libstddjb/cdb_read.c') diff --git a/src/libstddjb/cdb_read.c b/src/libstddjb/cdb_read.c new file mode 100644 index 0000000..76fbd63 --- /dev/null +++ b/src/libstddjb/cdb_read.c @@ -0,0 +1,24 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include + +int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32 pos) +{ + if (c->map) + { + if ((pos > c->size) || (c->size - pos < len)) return (errno = EPROTO, -1) ; + byte_copy(buf, len, c->map + pos) ; + } + else + { + if (seek_set(c->fd, pos) < 0) return -1 ; + if (allread(c->fd, buf, len) < len) return -1 ; + } + return 0 ; +} -- cgit v1.2.3