comparison dump.cpp @ 410:d7e590d58c85 api-inversion

Pavlovian response to compiler warnings... ... attempt to squash them. For now we can get most of the way by writing a simple write_or_goto_error() macro for write(), and the equivalent for read(). One of the warnings, for the return value of chdir(), is silly, because we're already in an error case, and we really can't do anything sensible if the chdir fails. Try to deal with it anyway.
author mas01cr
date Thu, 11 Dec 2008 08:54:01 +0000
parents a8a5f2ca5380
children 62a0515f59be
comparison
equal deleted inserted replaced
409:99e6cbad7f76 410:d7e590d58c85
133 } else { 133 } else {
134 snprintf(fName, 256, "%05d.features", k); 134 snprintf(fName, 256, "%05d.features", k);
135 if ((ffd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 135 if ((ffd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
136 goto error; 136 goto error;
137 } 137 }
138 if ((write(ffd, &(adb->header->dim), sizeof(uint32_t))) < 0) { 138 write_or_goto_error(ffd, &(adb->header->dim), sizeof(uint32_t));
139 goto error;
140 }
141 139
142 /* FIXME: this repeated malloc()/free() of data buffers is 140 /* FIXME: this repeated malloc()/free() of data buffers is
143 inefficient. */ 141 inefficient. */
144 data_buffer_size = trackTable[k] * adb->header->dim * sizeof(double); 142 data_buffer_size = trackTable[k] * adb->header->dim * sizeof(double);
145 143
153 151
154 if ((read(adb->fd, data_buffer, data_buffer_size)) != (ssize_t) data_buffer_size) { 152 if ((read(adb->fd, data_buffer, data_buffer_size)) != (ssize_t) data_buffer_size) {
155 goto error; 153 goto error;
156 } 154 }
157 155
158 if ((write(ffd, data_buffer, data_buffer_size)) < 0) { 156 write_or_goto_error(ffd, data_buffer, data_buffer_size);
159 goto error;
160 }
161 157
162 free(data_buffer); 158 free(data_buffer);
163 159
164 fprintf(fLFile, "%s\n", fName); 160 fprintf(fLFile, "%s\n", fName);
165 close(ffd); 161 close(ffd);
187 uint32_t one = 1; 183 uint32_t one = 1;
188 snprintf(fName, 256, "%05d.power", k); 184 snprintf(fName, 256, "%05d.power", k);
189 if ((pfd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 185 if ((pfd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
190 goto error; 186 goto error;
191 } 187 }
192 if ((write(pfd, &one, sizeof(uint32_t))) < 0) { 188 write_or_goto_error(pfd, &one, sizeof(uint32_t));
193 goto error; 189 write_or_goto_error(pfd, powerTable + pos, trackTable[k] * sizeof(double));
194 }
195 if ((write(pfd, powerTable + pos, trackTable[k] * sizeof(double))) < 0) {
196 goto error;
197 }
198 fprintf(pLFile, "%s\n", fName); 190 fprintf(pLFile, "%s\n", fName);
199 close(pfd); 191 close(pfd);
200 pfd = 0; 192 pfd = 0;
201 } 193 }
202 194
292 maybe_munmap(featureFileNameTable, fileTableLength); 284 maybe_munmap(featureFileNameTable, fileTableLength);
293 maybe_munmap(timesFileNameTable, fileTableLength); 285 maybe_munmap(timesFileNameTable, fileTableLength);
294 maybe_munmap(powerFileNameTable, fileTableLength); 286 maybe_munmap(powerFileNameTable, fileTableLength);
295 287
296 if(directory_changed) { 288 if(directory_changed) {
297 chdir(cwd); 289 int gcc_warning_workaround = chdir(cwd);
290 directory_changed = gcc_warning_workaround;
298 } 291 }
299 return 1; 292 return 1;
300 } 293 }