Function locking

Top 

Declaration:

int locking(long handle, int cmd, long length);

Description

Sets or resets file-sharing locks.

locking provides interface to the operating system file-sharing mechanism. handle specifies the opened file to be locked or unlocked. The region to be locked or unlocked starts at the current file position, and is length bytes long. Locks can be placed on arbitrary, nonoverlapping regions of any file. A program attempting to read or write into the locked region will retry the operation three times. If all three retries fail, the call fails with an error. cmd specifies the action to be taken:

 0    Unlock the region, which must have been previously locked.

 1    Lock the region. If the lock is unsuccessful, try once a second for 10 seconds before giving up.

 2    Lock the region. If the lock if unsuccessful, give up immediately.

Returned Value

On successful operations, locking returns 0. Otherwise, it returns -1 and the errno global variable is set to one of the following values:

 EACCES       File already locked or unlocked

 EBADF        Bad file number

 EDEADLOCK    File cannot be locked after 10 retries (cmd is LK_LOCK or LK_RLCK)

 EINVAL       Invalid cmd, or SHARE.EXE not loaded