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