Mercurial > hg > audiodb
view audioDB-internals.h @ 413:9de6d0676907 api-inversion
Add a partial libtests/ implementation of tests/0037.
Partial because still no "nsequence", though I have a plan for that.
The audiodb_batchinsert is a little bit weird; I think I'd have used an
adb_insert_t*[] (array of pointers) rather than an array of structures
directly. I might think about that some more later.
author | mas01cr |
---|---|
date | Fri, 12 Dec 2008 15:37:17 +0000 |
parents | d7e590d58c85 |
children | 6e6f4c1cc14d |
line wrap: on
line source
typedef struct adb_datum_internal { uint32_t nvectors; uint32_t dim; const char *key; void *data; void *times; void *power; } adb_datum_internal_t; struct adb { char *path; int fd; int flags; adb_header_t *header; std::set<std::string> *keys; }; /* We could go gcc-specific here and use typeof() instead of passing * in an explicit type. Answers on a postcard as to whether that's a * good plan or not. */ #define mmap_or_goto_error(type, var, start, length) \ { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \ if(tmp == (void *) -1) { \ goto error; \ } \ var = (type) tmp; \ } #define maybe_munmap(table, length) \ { if(table) { \ munmap(table, length); \ } \ } #define write_or_goto_error(fd, buffer, size) \ { ssize_t tmp = size; \ if(write(fd, buffer, size) != tmp) { \ goto error; \ } \ } #define read_or_goto_error(fd, buffer, size) \ { ssize_t tmp = size; \ if(read(fd, buffer, size) != tmp) { \ goto error; \ } \ } static inline int audiodb_sync_header(adb_t *adb) { off_t pos; pos = lseek(adb->fd, (off_t) 0, SEEK_CUR); if(pos == (off_t) -1) { goto error; } if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) { goto error; } if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { goto error; } /* can be fsync() if fdatasync() is racily exciting and new */ fdatasync(adb->fd); if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) { goto error; } return 0; error: return 1; }