Mercurial > hg > audiodb
comparison audioDB-internals.h @ 401:a8a5f2ca5380 api-inversion
Invert audioDB::l2norm / audiodb_l2norm()
We now have some functions that shouldn't be exported to the user of the
library, but are used in more than one source file; case in point:
audiodb_sync_header(). Make a new audioDB-internals.h file for them,
and while we're at it put the scary mmap()-related macros in there too.
We can't delete audioDB::unitNormAndInsertL2() quite yet, because it's
used in insertion too, but we can delete the non-append branches.
That's not very much code to lose, but every little helps.
author | mas01cr |
---|---|
date | Wed, 03 Dec 2008 14:53:20 +0000 |
parents | |
children | 58b88ab69424 |
comparison
equal
deleted
inserted
replaced
400:8c7453fb5bd9 | 401:a8a5f2ca5380 |
---|---|
1 /* We could go gcc-specific here and use typeof() instead of passing | |
2 * in an explicit type. Answers on a postcard as to whether that's a | |
3 * good plan or not. */ | |
4 #define mmap_or_goto_error(type, var, start, length) \ | |
5 { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \ | |
6 if(tmp == (void *) -1) { \ | |
7 goto error; \ | |
8 } \ | |
9 var = (type) tmp; \ | |
10 } | |
11 | |
12 #define maybe_munmap(table, length) \ | |
13 { if(table) { \ | |
14 munmap(table, length); \ | |
15 } \ | |
16 } | |
17 | |
18 static inline int audiodb_sync_header(adb_t *adb) { | |
19 off_t pos; | |
20 pos = lseek(adb->fd, (off_t) 0, SEEK_CUR); | |
21 if(pos == (off_t) -1) { | |
22 goto error; | |
23 } | |
24 if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) { | |
25 goto error; | |
26 } | |
27 if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { | |
28 goto error; | |
29 } | |
30 | |
31 /* can be fsync() if fdatasync() is racily exciting and new */ | |
32 fdatasync(adb->fd); | |
33 if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) { | |
34 goto error; | |
35 } | |
36 return 0; | |
37 | |
38 error: | |
39 return 1; | |
40 } |