5a9d77cd4183fe7a241ac849f83746c3c566189e
[debian/tar] / gnu / fd-hook.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Hook for making making file descriptor functions close(), ioctl() extensible.
4    Copyright (C) 2009-2013 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published
8    by the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19
20 #ifndef FD_HOOK_H
21 #define FD_HOOK_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27
28 /* Currently, this entire code is only needed for the handling of sockets
29    on native Windows platforms.  */
30 #if WINDOWS_SOCKETS
31
32
33 /* Type of function that closes FD.  */
34 typedef int (*gl_close_fn) (int fd);
35
36 /* Type of function that applies a control request to FD.  */
37 typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
38
39 /* An element of the list of file descriptor hooks.
40    In CLOS (Common Lisp Object System) speak, it consists of an "around"
41    method for the close() function and an "around" method for the ioctl()
42    function.
43    The fields of this structure are considered private.  */
44 struct fd_hook
45 {
46   /* Doubly linked list.  */
47   struct fd_hook *private_next;
48   struct fd_hook *private_prev;
49   /* Function that treats the types of FD that it knows about and calls
50      execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback.  */
51   int (*private_close_fn) (const struct fd_hook *remaining_list,
52                            gl_close_fn primary,
53                            int fd);
54   /* Function that treats the types of FD that it knows about and calls
55      execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
56      fallback.  */
57   int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
58                            gl_ioctl_fn primary,
59                            int fd, int request, void *arg);
60 };
61
62 /* This type of function closes FD, applying special knowledge for the FD
63    types it knows about, and calls
64    execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
65    for the other FD types.
66    In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
67    and PRIMARY is the "primary" method for close().  */
68 typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
69                               gl_close_fn primary,
70                               int fd);
71
72 /* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
73    Return 0 or -1, like close() would do.  */
74 extern int execute_close_hooks (const struct fd_hook *remaining_list,
75                                 gl_close_fn primary,
76                                 int fd);
77
78 /* Execute all close hooks, with PRIMARY as "primary" method.
79    Return 0 or -1, like close() would do.  */
80 extern int execute_all_close_hooks (gl_close_fn primary, int fd);
81
82 /* This type of function applies a control request to FD, applying special
83    knowledge for the FD types it knows about, and calls
84    execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
85    for the other FD types.
86    In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
87    and PRIMARY is the "primary" method for ioctl().  */
88 typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
89                               gl_ioctl_fn primary,
90                               int fd, int request, void *arg);
91
92 /* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
93    Return 0 or -1, like ioctl() would do.  */
94 extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
95                                 gl_ioctl_fn primary,
96                                 int fd, int request, void *arg);
97
98 /* Execute all ioctl hooks, with PRIMARY as "primary" method.
99    Return 0 or -1, like ioctl() would do.  */
100 extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
101                                     int fd, int request, void *arg);
102
103 /* Add a function pair to the list of file descriptor hooks.
104    CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
105    The LINK variable points to a piece of memory which is guaranteed to be
106    accessible until the corresponding call to unregister_fd_hook.  */
107 extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
108                               struct fd_hook *link);
109
110 /* Removes a hook from the list of file descriptor hooks.  */
111 extern void unregister_fd_hook (struct fd_hook *link);
112
113
114 #endif
115
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #endif /* FD_HOOK_H */