Imported Upstream version 4.5.10
[platform/upstream/findutils.git] / gnulib / lib / close-hook.h
1 /* Hook for making the close() function extensible.
2    Copyright (C) 2009-2011 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    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
22 extern "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.  */
33 struct 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.  */
46 typedef 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.  */
50 extern 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.  */
54 extern 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.  */
59 extern void register_close_hook (close_hook_fn hook, struct close_hook *link);
60
61 /* Removes a function from the list of close hooks.  */
62 extern 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 */