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/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <sys\locking.h>
    int locking( int handle, int mode, long nbyte );

Description:
    The locking function locks or unlocks nbyte bytes of the file specified
    by handle.  Locking a region of a file prevents other processes from
    reading or writing the locked region until the region has been unlocked.
     The locking and unlocking takes place at the current file position.
     The argument mode specifies the action to be performed.  The possible
    values for mode are:

    LK_LOCK
        Locks the specified region.  The function will retry to lock the
        region after 1 second intervals until successful or until 10
        attempts have been made.

    LK_RLCK
        Same action as  LK_LOCK.

    LK_NBLCK
        Non-blocking lock:  makes only 1 attempt to lock the specified
        region.

    LK_NBRLCK
        Same action as  LK_NBLCK.

    LK_UNLCK
        Unlocks the specified region.  The region must have been previously
        locked.

    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 locking function returns zero if successful.  Otherwise, it returns
    -1 and  errno is set to indicate the error.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EACCES
        Indicates a locking violation (file already locked or unlocked).

    EBADF
        Indicates an invalid file handle.

    EDEADLOCK
        Indicates a locking violation.  This error is returned when mode is
        LK_LOCK or LK_RLCK and the file cannot be locked after 10 attempts.

    EINVAL
        Indicates that an invalid argument was given to the function.


See Also:
    creat, _dos_creat, _dos_open, lock, open, sopen, unlock

Example:
    #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 );
        }
      }

Classification:
    WATCOM

Systems:
    All

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