home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12106a < prev    next >
Text File  |  1991-09-08  |  1KB  |  32 lines

  1. //  Listing 5 - Functions to read records for class binaryfile
  2. //  (See Listing 3 for the class definition)
  3.  
  4. //  =============================================
  5. //  Function for class binaryfile to read sequentially
  6. //      forwards and backwards through the file, or to
  7. //      read the first or last record in the file
  8. //
  9. int binaryfile::fileread (enum READMODE r) {
  10.     return fileread (r == FirstRecord ? 1L :
  11.            (r == NextRecord ? recnbr + 1L :
  12.               (r == PreviousRecord ? recnbr - 1L :
  13.                   /*LastRecord*/ getcount())));
  14. }
  15.  
  16. //  =============================================
  17. //  Function for class binaryfile to read a specific record
  18. //
  19. int binaryfile::fileread (long number) {
  20.     if (number > count && share == WriteShared) {
  21.     countrecords(); // recount number of records in file 
  22.     }
  23.     if (number <= 0L || number > count) return 0; // out of bounds
  24.     recnbr = number;
  25.     if (share == WriteShared 
  26.     && (mode == Update || mode == AnyWrite) 
  27.     && lockrecord (number)) 
  28.     return -10;  // error trap for lock failure
  29.     lseek (handle, ((recnbr - 1) * length) + header, SEEK_SET);
  30.     return read (handle, record, length);
  31. }
  32.