signal.in.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* A GNU-like <signal.h>.
  2. Copyright (C) 2006-2009 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. #endif
  16. #if defined __need_sig_atomic_t || defined __need_sigset_t
  17. /* Special invocation convention inside glibc header files. */
  18. # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
  19. #else
  20. /* Normal invocation convention. */
  21. #ifndef _GL_SIGNAL_H
  22. /* The include_next requires a split double-inclusion guard. */
  23. #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
  24. #ifndef _GL_SIGNAL_H
  25. #define _GL_SIGNAL_H
  26. /* The definition of GL_LINK_WARNING is copied here. */
  27. /* Define pid_t, uid_t.
  28. Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
  29. #include <sys/types.h>
  30. /* On AIX, sig_atomic_t already includes volatile. C99 requires that
  31. 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
  32. Hence, redefine this to a non-volatile type as needed. */
  33. #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
  34. typedef int rpl_sig_atomic_t;
  35. # undef sig_atomic_t
  36. # define sig_atomic_t rpl_sig_atomic_t
  37. #endif
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if @GNULIB_SIGNAL_H_SIGPIPE@
  42. # ifndef SIGPIPE
  43. /* Define SIGPIPE to a value that does not overlap with other signals. */
  44. # define SIGPIPE 13
  45. # define GNULIB_defined_SIGPIPE 1
  46. /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
  47. 'write', 'stdio'. */
  48. # endif
  49. #endif
  50. #if !@HAVE_POSIX_SIGNALBLOCKING@
  51. /* Maximum signal number + 1. */
  52. # ifndef NSIG
  53. # define NSIG 32
  54. # endif
  55. /* This code supports only 32 signals. */
  56. typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
  57. /* A set or mask of signals. */
  58. # if !@HAVE_SIGSET_T@
  59. typedef unsigned int sigset_t;
  60. # endif
  61. /* Test whether a given signal is contained in a signal set. */
  62. extern int sigismember (const sigset_t *set, int sig);
  63. /* Initialize a signal set to the empty set. */
  64. extern int sigemptyset (sigset_t *set);
  65. /* Add a signal to a signal set. */
  66. extern int sigaddset (sigset_t *set, int sig);
  67. /* Remove a signal from a signal set. */
  68. extern int sigdelset (sigset_t *set, int sig);
  69. /* Fill a signal set with all possible signals. */
  70. extern int sigfillset (sigset_t *set);
  71. /* Return the set of those blocked signals that are pending. */
  72. extern int sigpending (sigset_t *set);
  73. /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
  74. Then, if SET is not NULL, affect the current set of blocked signals by
  75. combining it with *SET as indicated in OPERATION.
  76. In this implementation, you are not allowed to change a signal handler
  77. while the signal is blocked. */
  78. # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
  79. # define SIG_SETMASK 1 /* blocked_set = *set; */
  80. # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
  81. extern int sigprocmask (int operation, const sigset_t *set, sigset_t *old_set);
  82. # define signal rpl_signal
  83. /* Install the handler FUNC for signal SIG, and return the previous
  84. handler. */
  85. extern void (*signal (int sig, void (*func) (int))) (int);
  86. # if GNULIB_defined_SIGPIPE
  87. /* Raise signal SIG. */
  88. # undef raise
  89. # define raise rpl_raise
  90. extern int raise (int sig);
  91. # endif
  92. #endif /* !@HAVE_POSIX_SIGNALBLOCKING@ */
  93. #if !@HAVE_SIGACTION@
  94. # if !@HAVE_SIGINFO_T@
  95. /* Present to allow compilation, but unsupported by gnulib. */
  96. union sigval
  97. {
  98. int sival_int;
  99. void *sival_ptr;
  100. };
  101. /* Present to allow compilation, but unsupported by gnulib. */
  102. struct siginfo_t
  103. {
  104. int si_signo;
  105. int si_code;
  106. int si_errno;
  107. pid_t si_pid;
  108. uid_t si_uid;
  109. void *si_addr;
  110. int si_status;
  111. long si_band;
  112. union sigval si_value;
  113. };
  114. typedef struct siginfo_t siginfo_t;
  115. # endif /* !@HAVE_SIGINFO_T@ */
  116. /* We assume that platforms which lack the sigaction() function also lack
  117. the 'struct sigaction' type, and vice versa. */
  118. struct sigaction
  119. {
  120. union
  121. {
  122. void (*_sa_handler) (int);
  123. /* Present to allow compilation, but unsupported by gnulib. POSIX
  124. says that implementations may, but not must, make sa_sigaction
  125. overlap with sa_handler, but we know of no implementation where
  126. they do not overlap. */
  127. void (*_sa_sigaction) (int, siginfo_t *, void *);
  128. } _sa_func;
  129. sigset_t sa_mask;
  130. /* Not all POSIX flags are supported. */
  131. int sa_flags;
  132. };
  133. # define sa_handler _sa_func._sa_handler
  134. # define sa_sigaction _sa_func._sa_sigaction
  135. /* Unsupported flags are not present. */
  136. # define SA_RESETHAND 1
  137. # define SA_NODEFER 2
  138. # define SA_RESTART 4
  139. extern int sigaction (int, const struct sigaction *restrict,
  140. struct sigaction *restrict);
  141. #elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
  142. # define sa_sigaction sa_handler
  143. #endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
  144. /* Some systems don't have SA_NODEFER. */
  145. #ifndef SA_NODEFER
  146. # define SA_NODEFER 0
  147. #endif
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* _GL_SIGNAL_H */
  152. #endif /* _GL_SIGNAL_H */
  153. #endif