Blame gnulib/tests/fd-hook.h

Packit Service a2ae7a
/* Hook for making file descriptor functions close(), ioctl() extensible.
Packit Service a2ae7a
   Copyright (C) 2009-2019 Free Software Foundation, Inc.
Packit Service a2ae7a
Packit Service a2ae7a
   This program is free software: you can redistribute it and/or modify it
Packit Service a2ae7a
   under the terms of the GNU General Public License as published
Packit Service a2ae7a
   by the Free Software Foundation; either version 3 of the License, or
Packit Service a2ae7a
   (at your option) any later version.
Packit Service a2ae7a
Packit Service a2ae7a
   This program is distributed in the hope that it will be useful,
Packit Service a2ae7a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2ae7a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service a2ae7a
   General Public License for more details.
Packit Service a2ae7a
Packit Service a2ae7a
   You should have received a copy of the GNU General Public License
Packit Service a2ae7a
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service a2ae7a
Packit Service a2ae7a
Packit Service a2ae7a
#ifndef FD_HOOK_H
Packit Service a2ae7a
#define FD_HOOK_H
Packit Service a2ae7a
Packit Service a2ae7a
#ifdef __cplusplus
Packit Service a2ae7a
extern "C" {
Packit Service a2ae7a
#endif
Packit Service a2ae7a
Packit Service a2ae7a
Packit Service a2ae7a
/* Currently, this entire code is only needed for the handling of sockets
Packit Service a2ae7a
   on native Windows platforms.  */
Packit Service a2ae7a
#if WINDOWS_SOCKETS
Packit Service a2ae7a
Packit Service a2ae7a
Packit Service a2ae7a
/* Type of function that closes FD.  */
Packit Service a2ae7a
typedef int (*gl_close_fn) (int fd);
Packit Service a2ae7a
Packit Service a2ae7a
/* Type of function that applies a control request to FD.  */
Packit Service a2ae7a
typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
Packit Service a2ae7a
Packit Service a2ae7a
/* An element of the list of file descriptor hooks.
Packit Service a2ae7a
   In CLOS (Common Lisp Object System) speak, it consists of an "around"
Packit Service a2ae7a
   method for the close() function and an "around" method for the ioctl()
Packit Service a2ae7a
   function.
Packit Service a2ae7a
   The fields of this structure are considered private.  */
Packit Service a2ae7a
struct fd_hook
Packit Service a2ae7a
{
Packit Service a2ae7a
  /* Doubly linked list.  */
Packit Service a2ae7a
  struct fd_hook *private_next;
Packit Service a2ae7a
  struct fd_hook *private_prev;
Packit Service a2ae7a
  /* Function that treats the types of FD that it knows about and calls
Packit Service a2ae7a
     execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback.  */
Packit Service a2ae7a
  int (*private_close_fn) (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                           gl_close_fn primary,
Packit Service a2ae7a
                           int fd);
Packit Service a2ae7a
  /* Function that treats the types of FD that it knows about and calls
Packit Service a2ae7a
     execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
Packit Service a2ae7a
     fallback.  */
Packit Service a2ae7a
  int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                           gl_ioctl_fn primary,
Packit Service a2ae7a
                           int fd, int request, void *arg);
Packit Service a2ae7a
};
Packit Service a2ae7a
Packit Service a2ae7a
/* This type of function closes FD, applying special knowledge for the FD
Packit Service a2ae7a
   types it knows about, and calls
Packit Service a2ae7a
   execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
Packit Service a2ae7a
   for the other FD types.
Packit Service a2ae7a
   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
Packit Service a2ae7a
   and PRIMARY is the "primary" method for close().  */
Packit Service a2ae7a
typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                              gl_close_fn primary,
Packit Service a2ae7a
                              int fd);
Packit Service a2ae7a
Packit Service a2ae7a
/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
Packit Service a2ae7a
   Return 0 or -1, like close() would do.  */
Packit Service a2ae7a
extern int execute_close_hooks (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                                gl_close_fn primary,
Packit Service a2ae7a
                                int fd);
Packit Service a2ae7a
Packit Service a2ae7a
/* Execute all close hooks, with PRIMARY as "primary" method.
Packit Service a2ae7a
   Return 0 or -1, like close() would do.  */
Packit Service a2ae7a
extern int execute_all_close_hooks (gl_close_fn primary, int fd);
Packit Service a2ae7a
Packit Service a2ae7a
/* This type of function applies a control request to FD, applying special
Packit Service a2ae7a
   knowledge for the FD types it knows about, and calls
Packit Service a2ae7a
   execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
Packit Service a2ae7a
   for the other FD types.
Packit Service a2ae7a
   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
Packit Service a2ae7a
   and PRIMARY is the "primary" method for ioctl().  */
Packit Service a2ae7a
typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                              gl_ioctl_fn primary,
Packit Service a2ae7a
                              int fd, int request, void *arg);
Packit Service a2ae7a
Packit Service a2ae7a
/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
Packit Service a2ae7a
   Return 0 or -1, like ioctl() would do.  */
Packit Service a2ae7a
extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
Packit Service a2ae7a
                                gl_ioctl_fn primary,
Packit Service a2ae7a
                                int fd, int request, void *arg);
Packit Service a2ae7a
Packit Service a2ae7a
/* Execute all ioctl hooks, with PRIMARY as "primary" method.
Packit Service a2ae7a
   Return 0 or -1, like ioctl() would do.  */
Packit Service a2ae7a
extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
Packit Service a2ae7a
                                    int fd, int request, void *arg);
Packit Service a2ae7a
Packit Service a2ae7a
/* Add a function pair to the list of file descriptor hooks.
Packit Service a2ae7a
   CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
Packit Service a2ae7a
   The LINK variable points to a piece of memory which is guaranteed to be
Packit Service a2ae7a
   accessible until the corresponding call to unregister_fd_hook.  */
Packit Service a2ae7a
extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
Packit Service a2ae7a
                              struct fd_hook *link);
Packit Service a2ae7a
Packit Service a2ae7a
/* Removes a hook from the list of file descriptor hooks.  */
Packit Service a2ae7a
extern void unregister_fd_hook (struct fd_hook *link);
Packit Service a2ae7a
Packit Service a2ae7a
Packit Service a2ae7a
#endif
Packit Service a2ae7a
Packit Service a2ae7a
Packit Service a2ae7a
#ifdef __cplusplus
Packit Service a2ae7a
}
Packit Service a2ae7a
#endif
Packit Service a2ae7a
Packit Service a2ae7a
#endif /* FD_HOOK_H */