This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/locking.c

29 lines
675 B
C

#include <stdio.h>
#include <sys/locking.h>
#include <share.h>
#include <fcntl.h>
#include <io.h>
void main()
{
int handle;
unsigned nbytes;
unsigned long offset;
auto char buffer[512];
nbytes = 512;
offset = 1024;
handle = sopen( "db.fil", O_RDWR, SH_DENYNO );
if( handle != -1 ) {
lseek( handle, offset, SEEK_SET );
locking( handle, LK_LOCK, nbytes );
read( handle, buffer, nbytes );
/* update data in the buffer */
lseek( handle, offset, SEEK_SET );
write( handle, buffer, nbytes );
lseek( handle, offset, SEEK_SET );
locking( handle, LK_UNLCK, nbytes );
close( handle );
}
}