This source file includes following definitions.
- execute_close_hooks
 
- execute_all_close_hooks
 
- execute_ioctl_hooks
 
- execute_all_ioctl_hooks
 
- register_fd_hook
 
- unregister_fd_hook
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 #include <config.h>
  19 
  20 
  21 #include "fd-hook.h"
  22 
  23 #include <stdlib.h>
  24 
  25 
  26 
  27 #if WINDOWS_SOCKETS
  28 
  29 
  30 
  31 static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
  32 
  33 int
  34 execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
     
  35                      int fd)
  36 {
  37   if (remaining_list == &anchor)
  38     
  39     return primary (fd);
  40   else
  41     return remaining_list->private_close_fn (remaining_list->private_next,
  42                                              primary, fd);
  43 }
  44 
  45 int
  46 execute_all_close_hooks (gl_close_fn primary, int fd)
     
  47 {
  48   return execute_close_hooks (anchor.private_next, primary, fd);
  49 }
  50 
  51 int
  52 execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
     
  53                      int fd, int request, void *arg)
  54 {
  55   if (remaining_list == &anchor)
  56     
  57     return primary (fd, request, arg);
  58   else
  59     return remaining_list->private_ioctl_fn (remaining_list->private_next,
  60                                              primary, fd, request, arg);
  61 }
  62 
  63 int
  64 execute_all_ioctl_hooks (gl_ioctl_fn primary,
     
  65                          int fd, int request, void *arg)
  66 {
  67   return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
  68 }
  69 
  70 void
  71 register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
     
  72 {
  73   if (close_hook == NULL)
  74     close_hook = execute_close_hooks;
  75   if (ioctl_hook == NULL)
  76     ioctl_hook = execute_ioctl_hooks;
  77 
  78   if (link->private_next == NULL && link->private_prev == NULL)
  79     {
  80       
  81       link->private_next = anchor.private_next;
  82       link->private_prev = &anchor;
  83       link->private_close_fn = close_hook;
  84       link->private_ioctl_fn = ioctl_hook;
  85       anchor.private_next->private_prev = link;
  86       anchor.private_next = link;
  87     }
  88   else
  89     {
  90       
  91       if (link->private_close_fn != close_hook
  92           || link->private_ioctl_fn != ioctl_hook)
  93         abort ();
  94     }
  95 }
  96 
  97 void
  98 unregister_fd_hook (struct fd_hook *link)
     
  99 {
 100   struct fd_hook *next = link->private_next;
 101   struct fd_hook *prev = link->private_prev;
 102 
 103   if (next != NULL && prev != NULL)
 104     {
 105       
 106       prev->private_next = next;
 107       next->private_prev = prev;
 108       
 109       link->private_next = NULL;
 110       link->private_prev = NULL;
 111       link->private_close_fn = NULL;
 112       link->private_ioctl_fn = NULL;
 113     }
 114 }
 115 
 116 #endif