unlock locked data in a file
#include <unistd.h> int unlock( int filedes, unsigned long offset, unsigned long nbytes );
The unlock() function unlocks nbytes amount of previously locked data in the file designated by filedes, starting at byte offset in the file. This allows other processes to lock this region of the file.
Multiple regions of a file can be locked, but no overlapping regions are allowed. You can't unlock multiple regions in the same call, even if the regions are contiguous. All locked regions of a file should be unlocked before closing a file or exiting the program.
#include <stdio.h> #include <fcntl.h> #include <unistd.h> void main() { int filedes ; char buffer[20]; filedes = open( "file", O_RDWR ); if( filedes != -1 ) { if( lock( filedes , 0L, 20L ) ) { printf( "Lock failed\n" ); } else { read( filedes , buffer, 20 ); /* update the buffer here */ lseek( filedes , 0L, SEEK_SET ); write( filedes , buffer, 20 ); unlock( filedes , 0L, 20L ); } close( filedes ); } }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
errno, lock(), locking(), open(), sopen()