(root)/
sed-4.9/
gnulib-tests/
signal.in.h
       1  /* A GNU-like <signal.h>.
       2  
       3     Copyright (C) 2006-2022 Free Software Foundation, Inc.
       4  
       5     This file is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU Lesser General Public License as
       7     published by the Free Software Foundation; either version 2.1 of the
       8     License, or (at your option) any later version.
       9  
      10     This file is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public License
      16     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      17  
      18  #if __GNUC__ >= 3
      19  @PRAGMA_SYSTEM_HEADER@
      20  #endif
      21  @PRAGMA_COLUMNS@
      22  
      23  #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
      24  /* Special invocation convention:
      25     - Inside glibc header files.
      26     - On glibc systems we have a sequence of nested includes
      27       <signal.h> -> <ucontext.h> -> <signal.h>.
      28       In this situation, the functions are not yet declared, therefore we cannot
      29       provide the C++ aliases.
      30     - On glibc systems with GCC 4.3 we have a sequence of nested includes
      31       <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
      32       In this situation, some of the functions are not yet declared, therefore
      33       we cannot provide the C++ aliases.  */
      34  
      35  # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
      36  
      37  #else
      38  /* Normal invocation convention.  */
      39  
      40  #ifndef _@GUARD_PREFIX@_SIGNAL_H
      41  
      42  #define _GL_ALREADY_INCLUDING_SIGNAL_H
      43  
      44  /* Define pid_t, uid_t.
      45     Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
      46     On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
      47     us; so include <sys/types.h> now, before the second inclusion guard.  */
      48  #include <sys/types.h>
      49  
      50  /* The include_next requires a split double-inclusion guard.  */
      51  #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
      52  
      53  #undef _GL_ALREADY_INCLUDING_SIGNAL_H
      54  
      55  #ifndef _@GUARD_PREFIX@_SIGNAL_H
      56  #define _@GUARD_PREFIX@_SIGNAL_H
      57  
      58  /* For testing the OpenBSD version.  */
      59  #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
      60      && defined __OpenBSD__
      61  # include <sys/param.h>
      62  #endif
      63  
      64  /* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, OSF/1 4.0, Solaris 2.6, Android,
      65     OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
      66     But avoid namespace pollution on glibc systems.*/
      67  #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
      68      && ((defined __APPLE__ && defined __MACH__) \
      69          || (defined __FreeBSD__ && __FreeBSD__ < 8) \
      70          || (defined __OpenBSD__ && OpenBSD < 201205) \
      71          || defined __osf__ || defined __sun || defined __ANDROID__ \
      72          || defined __KLIBC__) \
      73      && ! defined __GLIBC__
      74  # include <pthread.h>
      75  #endif
      76  
      77  /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
      78  
      79  /* The definition of _GL_ARG_NONNULL is copied here.  */
      80  
      81  /* The definition of _GL_WARN_ON_USE is copied here.  */
      82  
      83  /* On AIX, sig_atomic_t already includes volatile.  C99 requires that
      84     'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
      85     Hence, redefine this to a non-volatile type as needed.  */
      86  #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
      87  # if !GNULIB_defined_sig_atomic_t
      88  typedef int rpl_sig_atomic_t;
      89  #  undef sig_atomic_t
      90  #  define sig_atomic_t rpl_sig_atomic_t
      91  #  define GNULIB_defined_sig_atomic_t 1
      92  # endif
      93  #endif
      94  
      95  /* A set or mask of signals.  */
      96  #if !@HAVE_SIGSET_T@
      97  # if !GNULIB_defined_sigset_t
      98  typedef unsigned int sigset_t;
      99  #  define GNULIB_defined_sigset_t 1
     100  # endif
     101  #endif
     102  
     103  /* Define sighandler_t, the type of signal handlers.  A GNU extension.  */
     104  #if !@HAVE_SIGHANDLER_T@
     105  # ifdef __cplusplus
     106  extern "C" {
     107  # endif
     108  # if !GNULIB_defined_sighandler_t
     109  typedef void (*sighandler_t) (int);
     110  #  define GNULIB_defined_sighandler_t 1
     111  # endif
     112  # ifdef __cplusplus
     113  }
     114  # endif
     115  #endif
     116  
     117  
     118  #if @GNULIB_SIGNAL_H_SIGPIPE@
     119  # ifndef SIGPIPE
     120  /* Define SIGPIPE to a value that does not overlap with other signals.  */
     121  #  define SIGPIPE 13
     122  #  define GNULIB_defined_SIGPIPE 1
     123  /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
     124     'write', 'stdio'.  */
     125  # endif
     126  #endif
     127  
     128  
     129  /* Maximum signal number + 1.  */
     130  #ifndef NSIG
     131  # if defined __TANDEM
     132  #  define NSIG 32
     133  # endif
     134  #endif
     135  
     136  
     137  #if @GNULIB_PTHREAD_SIGMASK@
     138  # if @REPLACE_PTHREAD_SIGMASK@
     139  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     140  #   undef pthread_sigmask
     141  #   define pthread_sigmask rpl_pthread_sigmask
     142  #  endif
     143  _GL_FUNCDECL_RPL (pthread_sigmask, int,
     144                    (int how,
     145                     const sigset_t *restrict new_mask,
     146                     sigset_t *restrict old_mask));
     147  _GL_CXXALIAS_RPL (pthread_sigmask, int,
     148                    (int how,
     149                     const sigset_t *restrict new_mask,
     150                     sigset_t *restrict old_mask));
     151  # else
     152  #  if !(@HAVE_PTHREAD_SIGMASK@ || defined pthread_sigmask)
     153  _GL_FUNCDECL_SYS (pthread_sigmask, int,
     154                    (int how,
     155                     const sigset_t *restrict new_mask,
     156                     sigset_t *restrict old_mask));
     157  #  endif
     158  _GL_CXXALIAS_SYS (pthread_sigmask, int,
     159                    (int how,
     160                     const sigset_t *restrict new_mask,
     161                     sigset_t *restrict old_mask));
     162  # endif
     163  # if __GLIBC__ >= 2
     164  _GL_CXXALIASWARN (pthread_sigmask);
     165  # endif
     166  #elif defined GNULIB_POSIXCHECK
     167  # undef pthread_sigmask
     168  # if HAVE_RAW_DECL_PTHREAD_SIGMASK
     169  _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
     170                   "use gnulib module pthread_sigmask for portability");
     171  # endif
     172  #endif
     173  
     174  
     175  #if @GNULIB_RAISE@
     176  # if @REPLACE_RAISE@
     177  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     178  #   undef raise
     179  #   define raise rpl_raise
     180  #  endif
     181  _GL_FUNCDECL_RPL (raise, int, (int sig));
     182  _GL_CXXALIAS_RPL (raise, int, (int sig));
     183  # else
     184  #  if !@HAVE_RAISE@
     185  _GL_FUNCDECL_SYS (raise, int, (int sig));
     186  #  endif
     187  _GL_CXXALIAS_SYS (raise, int, (int sig));
     188  # endif
     189  # if __GLIBC__ >= 2
     190  _GL_CXXALIASWARN (raise);
     191  # endif
     192  #elif defined GNULIB_POSIXCHECK
     193  # undef raise
     194  /* Assume raise is always declared.  */
     195  _GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
     196                   "use gnulib module raise for portability");
     197  #endif
     198  
     199  
     200  #if @GNULIB_SIGPROCMASK@
     201  # if !@HAVE_POSIX_SIGNALBLOCKING@
     202  
     203  #  ifndef GNULIB_defined_signal_blocking
     204  #   define GNULIB_defined_signal_blocking 1
     205  #  endif
     206  
     207  /* Maximum signal number + 1.  */
     208  #  ifndef NSIG
     209  #   define NSIG 32
     210  #  endif
     211  
     212  /* This code supports only 32 signals.  */
     213  #  if !GNULIB_defined_verify_NSIG_constraint
     214  typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
     215  #   define GNULIB_defined_verify_NSIG_constraint 1
     216  #  endif
     217  
     218  # endif
     219  
     220  /* When also using extern inline, suppress the use of static inline in
     221     standard headers of problematic Apple configurations, as Libc at
     222     least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
     223     <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
     224     Perhaps Apple will fix this some day.  */
     225  #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
     226       && (defined __i386__ || defined __x86_64__))
     227  # undef sigaddset
     228  # undef sigdelset
     229  # undef sigemptyset
     230  # undef sigfillset
     231  # undef sigismember
     232  #endif
     233  
     234  /* Test whether a given signal is contained in a signal set.  */
     235  # if @HAVE_POSIX_SIGNALBLOCKING@
     236  /* This function is defined as a macro on Mac OS X.  */
     237  #  if defined __cplusplus && defined GNULIB_NAMESPACE
     238  #   undef sigismember
     239  #  endif
     240  # else
     241  _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
     242                                      _GL_ARG_NONNULL ((1)));
     243  # endif
     244  _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
     245  _GL_CXXALIASWARN (sigismember);
     246  
     247  /* Initialize a signal set to the empty set.  */
     248  # if @HAVE_POSIX_SIGNALBLOCKING@
     249  /* This function is defined as a macro on Mac OS X.  */
     250  #  if defined __cplusplus && defined GNULIB_NAMESPACE
     251  #   undef sigemptyset
     252  #  endif
     253  # else
     254  _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
     255  # endif
     256  _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
     257  _GL_CXXALIASWARN (sigemptyset);
     258  
     259  /* Add a signal to a signal set.  */
     260  # if @HAVE_POSIX_SIGNALBLOCKING@
     261  /* This function is defined as a macro on Mac OS X.  */
     262  #  if defined __cplusplus && defined GNULIB_NAMESPACE
     263  #   undef sigaddset
     264  #  endif
     265  # else
     266  _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
     267                                    _GL_ARG_NONNULL ((1)));
     268  # endif
     269  _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
     270  _GL_CXXALIASWARN (sigaddset);
     271  
     272  /* Remove a signal from a signal set.  */
     273  # if @HAVE_POSIX_SIGNALBLOCKING@
     274  /* This function is defined as a macro on Mac OS X.  */
     275  #  if defined __cplusplus && defined GNULIB_NAMESPACE
     276  #   undef sigdelset
     277  #  endif
     278  # else
     279  _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
     280                                    _GL_ARG_NONNULL ((1)));
     281  # endif
     282  _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
     283  _GL_CXXALIASWARN (sigdelset);
     284  
     285  /* Fill a signal set with all possible signals.  */
     286  # if @HAVE_POSIX_SIGNALBLOCKING@
     287  /* This function is defined as a macro on Mac OS X.  */
     288  #  if defined __cplusplus && defined GNULIB_NAMESPACE
     289  #   undef sigfillset
     290  #  endif
     291  # else
     292  _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
     293  # endif
     294  _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
     295  _GL_CXXALIASWARN (sigfillset);
     296  
     297  /* Return the set of those blocked signals that are pending.  */
     298  # if !@HAVE_POSIX_SIGNALBLOCKING@
     299  _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
     300  # endif
     301  _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
     302  _GL_CXXALIASWARN (sigpending);
     303  
     304  /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
     305     Then, if SET is not NULL, affect the current set of blocked signals by
     306     combining it with *SET as indicated in OPERATION.
     307     In this implementation, you are not allowed to change a signal handler
     308     while the signal is blocked.  */
     309  # if !@HAVE_POSIX_SIGNALBLOCKING@
     310  #  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
     311  #  define SIG_SETMASK 1  /* blocked_set = *set; */
     312  #  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
     313  _GL_FUNCDECL_SYS (sigprocmask, int,
     314                    (int operation,
     315                     const sigset_t *restrict set,
     316                     sigset_t *restrict old_set));
     317  # endif
     318  _GL_CXXALIAS_SYS (sigprocmask, int,
     319                    (int operation,
     320                     const sigset_t *restrict set,
     321                     sigset_t *restrict old_set));
     322  _GL_CXXALIASWARN (sigprocmask);
     323  
     324  /* Install the handler FUNC for signal SIG, and return the previous
     325     handler.  */
     326  # ifdef __cplusplus
     327  extern "C" {
     328  # endif
     329  # if !GNULIB_defined_function_taking_int_returning_void_t
     330  typedef void (*_gl_function_taking_int_returning_void_t) (int);
     331  #  define GNULIB_defined_function_taking_int_returning_void_t 1
     332  # endif
     333  # ifdef __cplusplus
     334  }
     335  # endif
     336  # if !@HAVE_POSIX_SIGNALBLOCKING@
     337  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     338  #   define signal rpl_signal
     339  #  endif
     340  _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
     341                    (int sig, _gl_function_taking_int_returning_void_t func));
     342  _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
     343                    (int sig, _gl_function_taking_int_returning_void_t func));
     344  # else
     345  /* On OpenBSD, the declaration of 'signal' may not be present at this point,
     346     because it occurs in <sys/signal.h>, not <signal.h> directly.  */
     347  #  if defined __OpenBSD__
     348  _GL_FUNCDECL_SYS (signal, _gl_function_taking_int_returning_void_t,
     349                    (int sig, _gl_function_taking_int_returning_void_t func));
     350  #  endif
     351  _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
     352                    (int sig, _gl_function_taking_int_returning_void_t func));
     353  # endif
     354  # if __GLIBC__ >= 2
     355  _GL_CXXALIASWARN (signal);
     356  # endif
     357  
     358  # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
     359  /* Raise signal SIGPIPE.  */
     360  _GL_EXTERN_C int _gl_raise_SIGPIPE (void);
     361  # endif
     362  
     363  #elif defined GNULIB_POSIXCHECK
     364  # undef sigaddset
     365  # if HAVE_RAW_DECL_SIGADDSET
     366  _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
     367                   "use the gnulib module sigprocmask for portability");
     368  # endif
     369  # undef sigdelset
     370  # if HAVE_RAW_DECL_SIGDELSET
     371  _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
     372                   "use the gnulib module sigprocmask for portability");
     373  # endif
     374  # undef sigemptyset
     375  # if HAVE_RAW_DECL_SIGEMPTYSET
     376  _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
     377                   "use the gnulib module sigprocmask for portability");
     378  # endif
     379  # undef sigfillset
     380  # if HAVE_RAW_DECL_SIGFILLSET
     381  _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
     382                   "use the gnulib module sigprocmask for portability");
     383  # endif
     384  # undef sigismember
     385  # if HAVE_RAW_DECL_SIGISMEMBER
     386  _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
     387                   "use the gnulib module sigprocmask for portability");
     388  # endif
     389  # undef sigpending
     390  # if HAVE_RAW_DECL_SIGPENDING
     391  _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
     392                   "use the gnulib module sigprocmask for portability");
     393  # endif
     394  # undef sigprocmask
     395  # if HAVE_RAW_DECL_SIGPROCMASK
     396  _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
     397                   "use the gnulib module sigprocmask for portability");
     398  # endif
     399  #endif /* @GNULIB_SIGPROCMASK@ */
     400  
     401  
     402  #if @GNULIB_SIGACTION@
     403  # if !@HAVE_SIGACTION@
     404  
     405  #  if !@HAVE_SIGINFO_T@
     406  
     407  #   if !GNULIB_defined_siginfo_types
     408  
     409  /* Present to allow compilation, but unsupported by gnulib.  */
     410  union sigval
     411  {
     412    int sival_int;
     413    void *sival_ptr;
     414  };
     415  
     416  /* Present to allow compilation, but unsupported by gnulib.  */
     417  struct siginfo_t
     418  {
     419    int si_signo;
     420    int si_code;
     421    int si_errno;
     422    pid_t si_pid;
     423    uid_t si_uid;
     424    void *si_addr;
     425    int si_status;
     426    long si_band;
     427    union sigval si_value;
     428  };
     429  typedef struct siginfo_t siginfo_t;
     430  
     431  #    define GNULIB_defined_siginfo_types 1
     432  #   endif
     433  
     434  #  endif /* !@HAVE_SIGINFO_T@ */
     435  
     436  /* We assume that platforms which lack the sigaction() function also lack
     437     the 'struct sigaction' type, and vice versa.  */
     438  
     439  #  if !GNULIB_defined_struct_sigaction
     440  
     441  struct sigaction
     442  {
     443    union
     444    {
     445      void (*_sa_handler) (int);
     446      /* Present to allow compilation, but unsupported by gnulib.  POSIX
     447         says that implementations may, but not must, make sa_sigaction
     448         overlap with sa_handler, but we know of no implementation where
     449         they do not overlap.  */
     450      void (*_sa_sigaction) (int, siginfo_t *, void *);
     451    } _sa_func;
     452    sigset_t sa_mask;
     453    /* Not all POSIX flags are supported.  */
     454    int sa_flags;
     455  };
     456  #   define sa_handler _sa_func._sa_handler
     457  #   define sa_sigaction _sa_func._sa_sigaction
     458  /* Unsupported flags are not present.  */
     459  #   define SA_RESETHAND 1
     460  #   define SA_NODEFER 2
     461  #   define SA_RESTART 4
     462  
     463  #   define GNULIB_defined_struct_sigaction 1
     464  #  endif
     465  
     466  _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
     467                                     struct sigaction *restrict));
     468  
     469  # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
     470  
     471  #  define sa_sigaction sa_handler
     472  
     473  # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
     474  
     475  _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
     476                                     struct sigaction *restrict));
     477  _GL_CXXALIASWARN (sigaction);
     478  
     479  #elif defined GNULIB_POSIXCHECK
     480  # undef sigaction
     481  # if HAVE_RAW_DECL_SIGACTION
     482  _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
     483                   "use the gnulib module sigaction for portability");
     484  # endif
     485  #endif
     486  
     487  /* Some systems don't have SA_NODEFER.  */
     488  #ifndef SA_NODEFER
     489  # define SA_NODEFER 0
     490  #endif
     491  
     492  
     493  #endif /* _@GUARD_PREFIX@_SIGNAL_H */
     494  #endif /* _@GUARD_PREFIX@_SIGNAL_H */
     495  #endif