Changeset 30427
- Timestamp:
- Jan 28, 2011, 3:40:46 PM (15 years ago)
- File:
-
- 1 edited
-
tags/ipp-20101215/Ohana/src/tools/src/roc.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-20101215/Ohana/src/tools/src/roc.c
r29938 r30427 4 4 # include <regex.h> 5 5 6 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } } 6 // # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } } 7 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); exit(1); } } 7 8 8 9 # define ROC_HEADER_SIZE 0x1000 … … 30 31 31 32 usage(); 32 exit ( 1);33 exit (2); 33 34 } 34 35 35 36 int roc_create (int argc, char **argv) { 36 37 37 int i, j, n, Ninput, result, Nblocks, header_size, size_off, Noff, Nbytes, Nread; 38 int i, j, n, Ninput, result, Nblocks, header_size, size_off; 39 int status, Noff, Nbytes, Nread, Nwrite; 38 40 off_t maxSize, *sizes, *bytes_read; 39 41 char value; … … 121 123 myAssert (target, "failed to open output"); 122 124 123 fwrite (header, 1, header_size, target); 125 Nwrite = fwrite (header, 1, header_size, target); 126 myAssert (Nwrite == header_size, "failed to write header"); 124 127 125 128 ALLOCATE (inputData, char *, Ninput); … … 134 137 Nbytes = fread (inputData[i], 1, Nread, input[i]); 135 138 myAssert (Nbytes == Nread, "failed to read data"); 139 136 140 if (Nread < ROC_BLOCKSIZE) { 137 141 // if we have reached the end of the file, fill in the rest with NULLs … … 149 153 } 150 154 151 fwrite (outputData, 1, ROC_BLOCKSIZE, target); 152 } 155 Nwrite = fwrite (outputData, 1, ROC_BLOCKSIZE, target); 156 myAssert (Nwrite == ROC_BLOCKSIZE, "failed to write data block"); 157 } 158 159 status = fclose (target); 160 myAssert (!status, "failed to close rocfile"); 153 161 154 162 exit (0); … … 157 165 int roc_repair (int argc, char **argv) { 158 166 159 int i, j, n, Ninput, Nblocks, header_size, Nbytes, Nread, Nfile, Nwrite; 167 int i, j, n, Ninput, Nblocks, header_size, Nbytes; 168 int status, Nread, Nfile, Nwrite; 160 169 off_t *sizes, *bytes_read; 161 170 char value; … … 201 210 // read the full header 202 211 fseeko (target, 0, SEEK_SET); 203 fread (header, 1, header_size, target); 212 Nread = fread (header, 1, header_size, target); 213 myAssert (Nread == header_size, "failed to read header"); 204 214 205 215 ptr = header; … … 252 262 Nbytes = fread (inputData[i], 1, Nread, input[i]); 253 263 myAssert (Nbytes == Nread, "failed to read data"); 264 254 265 if (Nread < ROC_BLOCKSIZE) { 255 266 // if we have reached the end of the file, fill in the rest with NULLs … … 258 269 bytes_read[i] += Nread; 259 270 } 260 fread (targetData, 1, ROC_BLOCKSIZE, target); 271 Nread = fread (targetData, 1, ROC_BLOCKSIZE, target); 272 myAssert (Nread == ROC_BLOCKSIZE, "failed to read from target"); 261 273 262 274 for (j = 0; j < ROC_BLOCKSIZE; j++) { … … 278 290 for (i = 0; i < Ninput; i++) { 279 291 if (i == Nfile) continue; 280 fclose(input[i]); 281 } 282 fclose (output); 283 fclose (target); 292 status = fclose(input[i]); 293 myAssert (!status, "failed to close input"); 294 } 295 status = fclose (output); 296 myAssert (!status, "failed to close output file"); 297 298 status = fclose (target); 299 myAssert (!status, "failed to close rocfile"); 284 300 285 301 exit (0);
Note:
See TracChangeset
for help on using the changeset viewer.
