summaryrefslogtreecommitdiffstats
path: root/gl/close-hook.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/close-hook.h')
-rw-r--r--gl/close-hook.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/gl/close-hook.h b/gl/close-hook.h
new file mode 100644
index 0000000..1e11551
--- /dev/null
+++ b/gl/close-hook.h
@@ -0,0 +1,72 @@
1/* Hook for making the close() function extensible.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17
18#ifndef CLOSE_HOOK_H
19#define CLOSE_HOOK_H
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26/* Currently, this entire code is only needed for the handling of sockets
27 on native Windows platforms. */
28#if WINDOWS_SOCKETS
29
30
31/* An element of the list of close hooks.
32 The fields of this structure are considered private. */
33struct close_hook
34{
35 /* Doubly linked list. */
36 struct close_hook *private_next;
37 struct close_hook *private_prev;
38 /* Function that treats the types of FD that it knows about and calls
39 execute_close_hooks (FD, REMAINING_LIST) as a fallback. */
40 int (*private_fn) (int fd, const struct close_hook *remaining_list);
41};
42
43/* This type of function closes FD, applying special knowledge for the FD
44 types it knows about, and calls execute_close_hooks (FD, REMAINING_LIST)
45 for the other FD types. */
46typedef int (*close_hook_fn) (int fd, const struct close_hook *remaining_list);
47
48/* Execute the close hooks in REMAINING_LIST.
49 Return 0 or -1, like close() would do. */
50extern int execute_close_hooks (int fd, const struct close_hook *remaining_list);
51
52/* Execute all close hooks.
53 Return 0 or -1, like close() would do. */
54extern int execute_all_close_hooks (int fd);
55
56/* Add a function to the list of close hooks.
57 The LINK variable points to a piece of memory which is guaranteed to be
58 accessible until the corresponding call to unregister_close_hook. */
59extern void register_close_hook (close_hook_fn hook, struct close_hook *link);
60
61/* Removes a function from the list of close hooks. */
62extern void unregister_close_hook (struct close_hook *link);
63
64
65#endif
66
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* CLOSE_HOOK_H */