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 >
Wrap
Text File
|
1991-09-08
|
989b
|
27 lines
// Listing 8 - Functions to lock and unlock records
// (See Listing 3 for the class definition)
// These functions use Turbo C MS-DOS locking facilities
// =============================================
// Function to lock a record if the file was opened with
// shared write access allowed from other programs
//
int binaryfile::lockrecord (long number) {
if (share != WriteShared) return 0;
if (locked > 0L) unlockrecord(); // Unlock currently locked record
return (lock (handle, // Turbo C lock function
(((locked = number) - 1) * length) + header, length) ?
(int)(locked = -1L) : 0);
}
// =============================================
// Function to unlock a record if currently locked
//
void binaryfile::unlockrecord () {
if (share != WriteShared || locked <= 0L) return;
locked = (long) unlock (handle, // Turbo C unlock function
((locked - 1) * length) + header, length);
}
// End of file