More portability enhancements.
[mLib] / man / lock.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
2.TH lock 3mLib "23 May 1999" mLib
3.SH NAME
4lock \- oversimplified file locking interface
5.SH SYNOPSIS
6.nf
7.B "#include <mLib/lock.h>
8
9.BI "int lock_file(int " fd ", unsigned " how );
10.fi
11.SH DESCRIPTION
12The
13.B lock_file
14function provides an extremely simplistic interface to POSIX
15.BR fcntl (2)
16locking. It locks only entire files, not sections of files. It doesn't
17have a nonblocking `is this file locked?' function.
18.PP
19On entry,
20.I fd
21should be a file descriptor on an open file, and
22.I how
23is a constant which describes how the file is to be locked. The
24possible values of
25.I how
26are:
27.TP
28.B LOCK_EXCL
29Lock the file exclusively. Attempts to lock the file exclusively or
30nonexclusively will fail until the file is unlocked.
31.TP
32.B LOCK_NONEXCL
33Lock the file nonexclusively. Until the file is unlocked, attempts to
34lock it exclusively will fail, but other nonexclusive locks will
35succeed.
36.TP
37.B LOCK_UNLOCK
38Unlocks a locked file. Any locks afterwards can succeed.
39.PP
40The
41.B lock_file
42function will block if it can't obtain a lock immediately. It will time
43itself out after a short while (10 seconds in the current
44implementation) if the lock doesn't become available.
45.PP
46If the call succeeds,
47.B lock_file
48returns zero. On failure, \-1 is returned, and
49.B errno
50is set to an appropriate value. Most of the error returns are from
51.BR fcntl (2)
52(q.v.). If the lock operation times out,
53.B errno
54is set to
55.BR EINTR .
56.SH AUTHOR
57Mark Wooding, <mdw@nsict.org>