IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30306


Ignore:
Timestamp:
Jan 19, 2011, 3:43:53 PM (15 years ago)
Author:
eugene
Message:

additional error checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/tools/src/roc.c

    r29938 r30306  
    44# include <regex.h>
    55
    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); } }
    78
    89# define ROC_HEADER_SIZE  0x1000
     
    3031
    3132  usage();
    32   exit (1);
     33  exit (2);
    3334}
    3435
    3536int roc_create (int argc, char **argv) {
    3637
    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;
    3840  off_t maxSize, *sizes, *bytes_read;
    3941  char value;
     
    121123  myAssert (target, "failed to open output");
    122124
    123   fwrite (header, 1, header_size, target);
     125  Nwrite = fwrite (header, 1, header_size, target);
     126  myAssert (Nwrite == header_size, "failed to write header");
    124127
    125128  ALLOCATE (inputData, char *, Ninput);
     
    134137      Nbytes = fread (inputData[i], 1, Nread, input[i]);
    135138      myAssert (Nbytes == Nread, "failed to read data");
     139
    136140      if (Nread < ROC_BLOCKSIZE) {
    137141        // if we have reached the end of the file, fill in the rest with NULLs
     
    149153    }
    150154
    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");
    153161
    154162  exit (0);
     
    157165int roc_repair (int argc, char **argv) {
    158166
    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;
    160169  off_t *sizes, *bytes_read;
    161170  char value;
     
    201210  // read the full header
    202211  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");
    204214
    205215  ptr = header;
     
    252262      Nbytes = fread (inputData[i], 1, Nread, input[i]);
    253263      myAssert (Nbytes == Nread, "failed to read data");
     264
    254265      if (Nread < ROC_BLOCKSIZE) {
    255266        // if we have reached the end of the file, fill in the rest with NULLs
     
    258269      bytes_read[i] += Nread;
    259270    }
    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");
    261273   
    262274    for (j = 0; j < ROC_BLOCKSIZE; j++) {
     
    278290  for (i = 0; i < Ninput; i++) {
    279291    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");
    284300
    285301  exit (0);
Note: See TracChangeset for help on using the changeset viewer.