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 Written by Bruno Haible <bruno@clisp.org>, 2009.
7 This program is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* Currently, this entire code is only needed for the handling of sockets
28 on native Windows platforms. */
31 /* The first and last link in the doubly linked list.
32 Initially the list is empty. */
33 static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
36 execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
39 if (remaining_list == &anchor)
40 /* End of list reached. */
43 return remaining_list->private_close_fn (remaining_list->private_next,
48 execute_all_close_hooks (gl_close_fn primary, int fd)
50 return execute_close_hooks (anchor.private_next, primary, fd);
54 execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
55 int fd, int request, void *arg)
57 if (remaining_list == &anchor)
58 /* End of list reached. */
59 return primary (fd, request, arg);
61 return remaining_list->private_ioctl_fn (remaining_list->private_next,
62 primary, fd, request, arg);
66 execute_all_ioctl_hooks (gl_ioctl_fn primary,
67 int fd, int request, void *arg)
69 return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
73 register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
75 if (close_hook == NULL)
76 close_hook = execute_close_hooks;
77 if (ioctl_hook == NULL)
78 ioctl_hook = execute_ioctl_hooks;
80 if (link->private_next == NULL && link->private_prev == NULL)
82 /* Add the link to the doubly linked list. */
83 link->private_next = anchor.private_next;
84 link->private_prev = &anchor;
85 link->private_close_fn = close_hook;
86 link->private_ioctl_fn = ioctl_hook;
87 anchor.private_next->private_prev = link;
88 anchor.private_next = link;
92 /* The link is already in use. */
93 if (link->private_close_fn != close_hook
94 || link->private_ioctl_fn != ioctl_hook)
100 unregister_fd_hook (struct fd_hook *link)
102 struct fd_hook *next = link->private_next;
103 struct fd_hook *prev = link->private_prev;
105 if (next != NULL && prev != NULL)
107 /* The link is in use. Remove it from the doubly linked list. */
108 prev->private_next = next;
109 next->private_prev = prev;
110 /* Clear the link, to mark it unused. */
111 link->private_next = NULL;
112 link->private_prev = NULL;
113 link->private_close_fn = NULL;
114 link->private_ioctl_fn = NULL;