- #include <stdio.h>
- #include <io.h>
- #include <share.h>
- #include <fcntl.h>
- #include <syslocking.h>
- void main(void)
- {
- int handle;
- if ((handle = sopen("\AUTOEXEC.BAT", O_RDONLY, SH_DENYNO)) == -1)
- printf("Error opening AUTOEXEC.BATn");
- else
- {
- printf("Trying to lock filen");
- if (locking(handle, LK_LOCK, 5L))
- printf("Error locking filen");
- else
- {
- printf("File locked--press Enter to continuen");
- getchar();
- close(handle);
- }
- }
- }