3 .\" Manual for file locking
5 .\" (c) 1999, 2001, 2005, 2009, 2023, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH lock 3mLib "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
34 .\"--------------------------------------------------------------------------
36 lock \- oversimplified file locking interface
38 .\"--------------------------------------------------------------------------
42 .B "#include <mLib/lock.h>"
46 .B " LOCK_UNLOCK = ...,"
47 .B " LOCK_EXCL = ...,"
48 .B " LOCK_NONEXCL = ..."
51 .BI "int lock_file(int " fd ", unsigned " how );
54 .\"--------------------------------------------------------------------------
59 function provides an extremely simplistic interface to POSIX
61 locking. It locks only entire files, not sections of files. It doesn't
62 have a nonblocking `is this file locked?' function.
66 should be a file descriptor on an open file, and
68 is a constant which describes how the file is to be locked. The
74 Lock the file exclusively. Attempts to lock the file exclusively or
75 nonexclusively will fail until the file is unlocked.
78 Lock the file nonexclusively. Until the file is unlocked, attempts to
79 lock it exclusively will fail, but other nonexclusive locks will
83 Unlocks a locked file. Any locks afterwards can succeed.
87 function will block if it can't obtain a lock immediately. It will time
88 itself out after a short while (10 seconds in the current
89 implementation) if the lock doesn't become available.
93 returns zero. On failure, \-1 is returned, and
95 is set to an appropriate value. Most of the error returns are from
97 (q.v.). If the lock operation times out,
102 .\"--------------------------------------------------------------------------
108 .\"--------------------------------------------------------------------------
111 Mark Wooding, <mdw@distorted.org.uk>
113 .\"----- That's all, folks --------------------------------------------------