chiark / gitweb /
Infrastructure: Split the files into subdirectories.
[mLib] / sys / lock.h
CommitLineData
edb89af3 1/* -*-c-*-
2 *
edb89af3 3 * Simplified POSIX locking interface
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
edb89af3 9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
d4efbcd9 16 *
edb89af3 17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
d4efbcd9 21 *
edb89af3 22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
c6e0eaf0 28#ifndef MLIB_LOCK_H
29#define MLIB_LOCK_H
edb89af3 30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Magic constants ---------------------------------------------------*/
36
37enum {
38 LOCK_UNLOCK, /* Release a lock I obtained */
39 LOCK_EXCL, /* Obtain an exclusive lock */
40 LOCK_NONEXCL /* Obtain a nonexclusive lock */
41};
42
43/*----- Functions provided ------------------------------------------------*/
44
45/* --- @lock_file@ --- *
46 *
47 * Arguments: @int fd@ = file descriptor to lock
48 * @unsigned how@ = type of lock required
49 *
50 * Returns: 0 if OK, -1 if it failed.
51 *
52 * Use: Acquires a lock on the given file. The value @how@
53 * specifies the type of lock to acquire: @LOCK_EXCL@ gets
54 * an exclusive (write) lock; @LOCK_NONEXCL@ gets a non-
55 * exclusive (read) lock and @LOCK_UNLOCK@ releases any locks.
56 * Acquiring a lock gets timed out after a while with an
57 * error.
58 */
59
60extern int lock_file(int /*fd*/, unsigned /*how*/);
61
62/*----- That's all, folks -------------------------------------------------*/
63
64#ifdef __cplusplus
65 }
66#endif
67
68#endif