Mercurial > hg > audiodb
comparison open.cpp @ 596:6ad0a6e67d4c
Take advantage of those new handy _or_goto_error macros
Use them in various places where previously we either elided the error
checking (various lseek() calls) or used a combination of calls
(replaced by malloc_and_fill_or_goto_error()).
In the process, fix what is probably a bug (or else introduce one, but I
don't think so): audiodb_track_id_datum() computed the offset into the
timesTable wrongly, forgetting to multiply by 2. (TODO: this should be
easily testable using the API).
Now all of LIBOBJS can be produced by my (Debian's) mingw32
cross-compiler, except for lshlib.o.
author | mas01cr |
---|---|
date | Tue, 11 Aug 2009 21:42:49 +0000 |
parents | cfa74bcc1249 |
children | b1723ae7675e |
comparison
equal
deleted
inserted
replaced
595:31a1556fc2d6 | 596:6ad0a6e67d4c |
---|---|
26 size_t key_table_length = 0; | 26 size_t key_table_length = 0; |
27 | 27 |
28 if(adb->header->length > 0) { | 28 if(adb->header->length > 0) { |
29 unsigned nfiles = adb->header->numFiles; | 29 unsigned nfiles = adb->header->numFiles; |
30 key_table_length = align_page_up(nfiles * ADB_FILETABLE_ENTRY_SIZE); | 30 key_table_length = align_page_up(nfiles * ADB_FILETABLE_ENTRY_SIZE); |
31 key_table = (char *)malloc(key_table_length); | 31 malloc_and_fill_or_goto_error(char *, key_table, adb->header->fileTableOffset, key_table_length); |
32 if(!key_table) { | |
33 goto error; | |
34 } | |
35 lseek_set_or_goto_error(adb->fd, adb->header->fileTableOffset); | |
36 read_or_goto_error(adb->fd, key_table, key_table_length); | |
37 for (unsigned int k = 0; k < nfiles; k++) { | 32 for (unsigned int k = 0; k < nfiles; k++) { |
38 adb->keys->push_back(key_table + k*ADB_FILETABLE_ENTRY_SIZE); | 33 adb->keys->push_back(key_table + k*ADB_FILETABLE_ENTRY_SIZE); |
39 (*adb->keymap)[(key_table + k*ADB_FILETABLE_ENTRY_SIZE)] = k; | 34 (*adb->keymap)[(key_table + k*ADB_FILETABLE_ENTRY_SIZE)] = k; |
40 } | 35 } |
41 free(key_table); | 36 free(key_table); |
42 } | 37 } |
43 | 38 |
44 return 0; | 39 return 0; |
45 | 40 |
46 error: | 41 error: |
47 if(key_table) { | 42 maybe_free(key_table); |
48 free(key_table); | |
49 } | |
50 return 1; | 43 return 1; |
51 } | 44 } |
52 | 45 |
53 static int audiodb_collect_track_lengths(adb_t *adb) { | 46 static int audiodb_collect_track_lengths(adb_t *adb) { |
54 uint32_t *track_table = 0; | 47 uint32_t *track_table = 0; |
55 size_t track_table_length = 0; | 48 size_t track_table_length = 0; |
56 if(adb->header->length > 0) { | 49 if(adb->header->length > 0) { |
57 unsigned nfiles = adb->header->numFiles; | 50 unsigned nfiles = adb->header->numFiles; |
58 track_table_length = align_page_up(nfiles * ADB_TRACKTABLE_ENTRY_SIZE); | 51 track_table_length = align_page_up(nfiles * ADB_TRACKTABLE_ENTRY_SIZE); |
59 track_table = (uint32_t *) malloc(track_table_length); | 52 malloc_and_fill_or_goto_error(uint32_t *, track_table, adb->header->trackTableOffset, track_table_length); |
60 if (!track_table) { | |
61 goto error; | |
62 } | |
63 lseek_set_or_goto_error(adb->fd, adb->header->trackTableOffset); | |
64 read_or_goto_error(adb->fd, track_table, track_table_length); | |
65 off_t offset = 0; | 53 off_t offset = 0; |
66 for (unsigned int k = 0; k < nfiles; k++) { | 54 for (unsigned int k = 0; k < nfiles; k++) { |
67 uint32_t track_length = track_table[k]; | 55 uint32_t track_length = track_table[k]; |
68 adb->track_lengths->push_back(track_length); | 56 adb->track_lengths->push_back(track_length); |
69 adb->track_offsets->push_back(offset); | 57 adb->track_offsets->push_back(offset); |
73 } | 61 } |
74 | 62 |
75 return 0; | 63 return 0; |
76 | 64 |
77 error: | 65 error: |
78 if(track_table) { | 66 maybe_free(track_table); |
79 free(track_table); | |
80 } | |
81 return 1; | 67 return 1; |
82 } | 68 } |
83 | 69 |
84 adb_t *audiodb_open(const char *path, int flags) { | 70 adb_t *audiodb_open(const char *path, int flags) { |
85 adb_t *adb = 0; | 71 adb_t *adb = 0; |
144 adb->cached_lsh = 0; | 130 adb->cached_lsh = 0; |
145 return adb; | 131 return adb; |
146 | 132 |
147 error: | 133 error: |
148 if(adb) { | 134 if(adb) { |
149 if(adb->header) { | 135 maybe_free(adb->header); |
150 free(adb->header); | 136 maybe_free(adb->path); |
151 } | |
152 if(adb->path) { | |
153 free(adb->path); | |
154 } | |
155 if(adb->keys) { | 137 if(adb->keys) { |
156 delete adb->keys; | 138 delete adb->keys; |
157 } | 139 } |
158 if(adb->keymap) { | 140 if(adb->keymap) { |
159 delete adb->keymap; | 141 delete adb->keymap; |