Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int lock( int handle,
              unsigned long offset,
              unsigned long nbytes );

Description:
    The lock function locks nbytes amount of data in the file designated by
    handle starting at byte offset in the file.  This prevents other
    processes from reading or writing into the locked region until an
     unlock has been done for this locked region of the file.

    Multiple regions of a file can be locked, but no overlapping regions are
    allowed.  You cannot 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.

    With DOS, locking is supported by version 3.0 or later.  Note that
    SHARE.COM or SHARE.EXE must be installed.

Returns:
    The lock function returns zero if successful, and -1 when an error
    occurs.  When an error has occurred,  errno contains a value indicating
    the type of error that has been detected.

Example:
    #include <stdio.h>
    #include <fcntl.h>
    #include <io.h>

    void main()
      {
        int handle;
        char buffer[20];

        handle = open( "file", O_RDWR | O_TEXT );
        if( handle != -1 ) {
          if( lock( handle, 0L, 20L ) ) {
            printf( "Lock failed\n" );
          } else {
            read( handle, buffer, 20 );
            /* update the buffer here */
            lseek( handle, 0L, SEEK_SET );
            write( handle, buffer, 20 );
            unlock( handle, 0L, 20L );
          }
          close( handle );
        }
      }

Classification:
    WATCOM

Systems:
    All, Netware

See Also:
    locking, open, sopen, unlock

See Also: unlock

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson