comparison create.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 a82a2d9b2451
children 913a95f06998
comparison
equal deleted inserted replaced
409:99e6cbad7f76 410:d7e590d58c85
1 #include "audioDB.h" 1 #include "audioDB.h"
2 extern "C" { 2 extern "C" {
3 #include "audioDB_API.h" 3 #include "audioDB_API.h"
4 } 4 }
5 #include "audioDB-internals.h"
6
5 /* Make a new database. 7 /* Make a new database.
6 8
7 IF size(featuredata) < O2_LARGE_ADB_SIZE 9 IF size(featuredata) < O2_LARGE_ADB_SIZE
8 The database consists of: 10 The database consists of:
9 11
100 header->powerTableOffset = ALIGN_PAGE_UP(header->timesTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks); 102 header->powerTableOffset = ALIGN_PAGE_UP(header->timesTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
101 header->l2normTableOffset = ALIGN_PAGE_UP(header->powerTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks); 103 header->l2normTableOffset = ALIGN_PAGE_UP(header->powerTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
102 header->dbSize = header->l2normTableOffset; 104 header->dbSize = header->l2normTableOffset;
103 } 105 }
104 106
105 if (write(fd, header, O2_HEADERSIZE) != O2_HEADERSIZE) { 107 write_or_goto_error(fd, header, O2_HEADERSIZE);
106 goto error;
107 }
108 108
109 // go to the location corresponding to the last byte 109 // go to the location corresponding to the last byte
110 if (lseek (fd, header->dbSize - 1, SEEK_SET) == -1) { 110 if (lseek (fd, header->dbSize - 1, SEEK_SET) == -1) {
111 goto error; 111 goto error;
112 } 112 }
113 113
114 // write a dummy byte at the last location 114 // write a dummy byte at the last location
115 if (write (fd, "", 1) != 1) { 115 write_or_goto_error(fd, "", 1);
116 goto error;
117 }
118 116
119 free(header); 117 free(header);
120 return audiodb_open(path, O_RDWR); 118 return audiodb_open(path, O_RDWR);
121 119
122 error: 120 error: