mas01cr@401: /* We could go gcc-specific here and use typeof() instead of passing mas01cr@401: * in an explicit type. Answers on a postcard as to whether that's a mas01cr@401: * good plan or not. */ mas01cr@401: #define mmap_or_goto_error(type, var, start, length) \ mas01cr@401: { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \ mas01cr@401: if(tmp == (void *) -1) { \ mas01cr@401: goto error; \ mas01cr@401: } \ mas01cr@401: var = (type) tmp; \ mas01cr@401: } mas01cr@401: mas01cr@401: #define maybe_munmap(table, length) \ mas01cr@401: { if(table) { \ mas01cr@401: munmap(table, length); \ mas01cr@401: } \ mas01cr@401: } mas01cr@401: mas01cr@401: static inline int audiodb_sync_header(adb_t *adb) { mas01cr@401: off_t pos; mas01cr@401: pos = lseek(adb->fd, (off_t) 0, SEEK_CUR); mas01cr@401: if(pos == (off_t) -1) { mas01cr@401: goto error; mas01cr@401: } mas01cr@401: if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) { mas01cr@401: goto error; mas01cr@401: } mas01cr@401: if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { mas01cr@401: goto error; mas01cr@401: } mas01cr@401: mas01cr@401: /* can be fsync() if fdatasync() is racily exciting and new */ mas01cr@401: fdatasync(adb->fd); mas01cr@401: if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) { mas01cr@401: goto error; mas01cr@401: } mas01cr@401: return 0; mas01cr@401: mas01cr@401: error: mas01cr@401: return 1; mas01cr@401: }