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