diff options
Diffstat (limited to 'contrib/cdb/cdb_init.c')
-rw-r--r-- | contrib/cdb/cdb_init.c | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/contrib/cdb/cdb_init.c b/contrib/cdb/cdb_init.c index bfc6dd0c2..278506d21 100644 --- a/contrib/cdb/cdb_init.c +++ b/contrib/cdb/cdb_init.c @@ -18,8 +18,7 @@ cdb_hash(const void *buf, unsigned len) return hash; } -int -cdb_init(struct cdb *cdbp, int fd) +int cdb_init(struct cdb *cdbp, int fd) { struct stat st; unsigned char *mem; @@ -29,7 +28,7 @@ cdb_init(struct cdb *cdbp, int fd) #endif /* get file size */ - if (fstat (fd, &st) < 0) + if (fstat(fd, &st) < 0) return -1; /* trivial sanity check: at least toc should be here */ if (st.st_size < 2048) @@ -39,16 +38,16 @@ cdb_init(struct cdb *cdbp, int fd) #ifdef _WIN32 hFile = (HANDLE) _get_osfhandle(fd); if (hFile == (HANDLE) -1) - return -1; + return -1; hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (!hMapping) - return -1; - mem = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); + return -1; + mem = (unsigned char *) MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); CloseHandle(hMapping); if (!mem) - return -1; + return -1; #else - mem = (unsigned char*) mmap (NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); + mem = (unsigned char *) mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); if (mem == MAP_FAILED) return -1; #endif /* _WIN32 */ @@ -60,7 +59,7 @@ cdb_init(struct cdb *cdbp, int fd) cdbp->cdb_vpos = cdbp->cdb_vlen = 0; cdbp->cdb_kpos = cdbp->cdb_klen = 0; - dend = cdb_unpack (mem); + dend = cdb_unpack(mem); if (dend < 2048) dend = 2048; else if (dend >= fsize) @@ -70,21 +69,20 @@ cdb_init(struct cdb *cdbp, int fd) return 0; } -void -cdb_free(struct cdb *cdbp) +void cdb_free(struct cdb *cdbp) { if (cdbp->cdb_mem) { #ifdef _WIN32 - UnmapViewOfFile((void*) cdbp->cdb_mem); + UnmapViewOfFile((void *) cdbp->cdb_mem); #else - munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); + munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); #endif /* _WIN32 */ cdbp->cdb_mem = NULL; } cdbp->cdb_fsize = 0; if (cdbp->loop) { - ev_stat_stop (cdbp->loop, &cdbp->stat_ev); + ev_stat_stop(cdbp->loop, &cdbp->stat_ev); } } @@ -98,43 +96,41 @@ cdb_get(const struct cdb *cdbp, unsigned len, unsigned pos) return cdbp->cdb_mem + pos; } -int -cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) +int cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) { - const void *data = cdb_get (cdbp, len, pos); + const void *data = cdb_get(cdbp, len, pos); if (!data) return -1; - memcpy (buf, data, len); + memcpy(buf, data, len); return 0; } static void -cdb_timer_callback (EV_P_ ev_stat *w, int revents) +cdb_timer_callback(EV_P_ ev_stat *w, int revents) { struct cdb *cdbp = w->data; - gint nfd; + int nfd; /* Check cdb file for modifications */ - if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) { + if ((nfd = open(cdbp->filename, O_RDONLY)) != -1) { if (cdbp->cdb_mem) { #ifdef _WIN32 - UnmapViewOfFile((void*) cdbp->cdb_mem); + UnmapViewOfFile((void *) cdbp->cdb_mem); #else - munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); + munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); #endif /* _WIN32 */ cdbp->cdb_mem = NULL; } - (void)close (cdbp->cdb_fd); + (void) close(cdbp->cdb_fd); cdbp->cdb_fsize = 0; - (void)cdb_init (cdbp, nfd); + (void) cdb_init(cdbp, nfd); } } -void -cdb_add_timer (struct cdb *cdbp, EV_P_ ev_tstamp seconds) +void cdb_add_timer(struct cdb *cdbp, EV_P_ ev_tstamp seconds) { cdbp->loop = loop; - ev_stat_init (&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); + ev_stat_init(&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); cdbp->stat_ev.data = cdbp; - ev_stat_start (EV_A_ &cdbp->stat_ev); + ev_stat_start(EV_A_ & cdbp->stat_ev); } |