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

  1. //  Listing 8 - Functions to lock and unlock records 
  2. //  (See Listing 3 for the class definition)
  3. //  These functions use Turbo C MS-DOS locking facilities
  4.  
  5. //  =============================================
  6. //  Function to lock a record if the file was opened with
  7. //      shared write access allowed from other programs
  8. //  
  9. int binaryfile::lockrecord (long number) {
  10.     if (share != WriteShared) return 0;
  11.     if (locked > 0L) unlockrecord();  // Unlock currently locked record
  12.     return (lock (handle,    // Turbo C lock function
  13.         (((locked = number) - 1) * length) + header, length) ?
  14.         (int)(locked = -1L) : 0);
  15. }
  16.  
  17. //  =============================================
  18. //  Function to unlock a record if currently locked
  19. //
  20. void binaryfile::unlockrecord () {
  21.     if (share != WriteShared || locked <= 0L) return;
  22.     locked = (long) unlock (handle,  // Turbo C unlock function
  23.         ((locked - 1) * length) + header, length);
  24. }
  25.  
  26. // End of file
  27.