chiark / gitweb /
Import gnupg2_2.1.17.orig.tar.bz2
[gnupg2.git] / common / dotlock.h
1 /* dotlock.h - dotfile locking declarations
2  * Copyright (C) 2000, 2001, 2006, 2011 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify it
7  * under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * GnuPG is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  *
26  * You should have received a copies of the GNU General Public License
27  * and the GNU Lesser General Public License along with this program;
28  * if not, see <https://www.gnu.org/licenses/>.
29  *
30  * ALTERNATIVELY, this file may be distributed under the terms of the
31  * following license, in which case the provisions of this license are
32  * required INSTEAD OF the GNU Lesser General License or the GNU
33  * General Public License. If you wish to allow use of your version of
34  * this file only under the terms of the GNU Lesser General License or
35  * the GNU General Public License, and not to allow others to use your
36  * version of this file under the terms of the following license,
37  * indicate your decision by deleting this paragraph and the license
38  * below.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  *
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, and the entire permission notice in its entirety,
46  *    including the disclaimer of warranties.
47  * 2. Redistributions in binary form must reproduce the above copyright
48  *    notice, this list of conditions and the following disclaimer in the
49  *    documentation and/or other materials provided with the distribution.
50  * 3. The name of the author may not be used to endorse or promote
51  *    products derived from this software without specific prior
52  *    written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
55  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
57  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
58  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
59  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
62  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
64  * OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66
67 #ifndef GNUPG_COMMON_DOTLOCK_H
68 #define GNUPG_COMMON_DOTLOCK_H
69
70 /* See dotlock.c for a description.  */
71
72 #ifdef DOTLOCK_EXT_SYM_PREFIX
73 # ifndef _DOTLOCK_PREFIX
74 #  define _DOTLOCK_PREFIX1(x,y)  x ## y
75 #  define _DOTLOCK_PREFIX2(x,y) _DOTLOCK_PREFIX1(x,y)
76 #  define _DOTLOCK_PREFIX(x)    _DOTLOCK_PREFIX2(DOTLOCK_EXT_SYM_PREFIX,x)
77 # endif /*_DOTLOCK_PREFIX*/
78 # define dotlock_disable          _DOTLOCK_PREFIX(dotlock_disable)
79 # define dotlock_create           _DOTLOCK_PREFIX(dotlock_create)
80 # define dotlock_set_fd           _DOTLOCK_PREFIX(dotlock_set_fd)
81 # define dotlock_get_fd           _DOTLOCK_PREFIX(dotlock_get_fd)
82 # define dotlock_destroy          _DOTLOCK_PREFIX(dotlock_destroy)
83 # define dotlock_take             _DOTLOCK_PREFIX(dotlock_take)
84 # define dotlock_release          _DOTLOCK_PREFIX(dotlock_release)
85 # define dotlock_remove_lockfiles _DOTLOCK_PREFIX(dotlock_remove_lockfiles)
86 #endif /*DOTLOCK_EXT_SYM_PREFIX*/
87
88 #ifdef __cplusplus
89 extern "C"
90 {
91 #if 0
92 }
93 #endif
94 #endif
95
96
97 struct dotlock_handle;
98 typedef struct dotlock_handle *dotlock_t;
99
100 void dotlock_disable (void);
101 dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags);
102 void dotlock_set_fd (dotlock_t h, int fd);
103 int  dotlock_get_fd (dotlock_t h);
104 void dotlock_destroy (dotlock_t h);
105 int dotlock_take (dotlock_t h, long timeout);
106 int dotlock_release (dotlock_t h);
107 void dotlock_remove_lockfiles (void);
108
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif /*GNUPG_COMMON_DOTLOCK_H*/