Blame lib/sig-handler.h

Packit Service c30d13
/* Convenience declarations when working with <signal.h>.
Packit Service c30d13
Packit Service c30d13
   Copyright (C) 2008-2018 Free Software Foundation, Inc.
Packit Service c30d13
Packit Service c30d13
   This program is free software: you can redistribute it and/or modify
Packit Service c30d13
   it under the terms of the GNU General Public License as published by
Packit Service c30d13
   the Free Software Foundation; either version 3 of the License, or
Packit Service c30d13
   (at your option) any later version.
Packit Service c30d13
Packit Service c30d13
   This program is distributed in the hope that it will be useful,
Packit Service c30d13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service c30d13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service c30d13
   GNU General Public License for more details.
Packit Service c30d13
Packit Service c30d13
   You should have received a copy of the GNU General Public License
Packit Service c30d13
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service c30d13
Packit Service c30d13
#ifndef _GL_SIG_HANDLER_H
Packit Service c30d13
#define _GL_SIG_HANDLER_H
Packit Service c30d13
Packit Service c30d13
#include <signal.h>
Packit Service c30d13
Packit Service c30d13
#ifndef _GL_INLINE_HEADER_BEGIN
Packit Service c30d13
 #error "Please include config.h first."
Packit Service c30d13
#endif
Packit Service c30d13
_GL_INLINE_HEADER_BEGIN
Packit Service c30d13
#ifndef SIG_HANDLER_INLINE
Packit Service c30d13
# define SIG_HANDLER_INLINE _GL_INLINE
Packit Service c30d13
#endif
Packit Service c30d13
Packit Service c30d13
/* Convenience type when working with signal handlers.  */
Packit Service c30d13
typedef void (*sa_handler_t) (int);
Packit Service c30d13
Packit Service c30d13
/* Return the handler of a signal, as a sa_handler_t value regardless
Packit Service c30d13
   of its true type.  The resulting function can be compared to
Packit Service c30d13
   special values like SIG_IGN but it is not portable to call it.  */
Packit Service c30d13
SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE
Packit Service c30d13
get_handler (struct sigaction const *a)
Packit Service c30d13
{
Packit Service c30d13
  /* POSIX says that special values like SIG_IGN can only occur when
Packit Service c30d13
     action.sa_flags does not contain SA_SIGINFO.  But in Linux 2.4,
Packit Service c30d13
     for example, sa_sigaction and sa_handler are aliases and a signal
Packit Service c30d13
     is ignored if sa_sigaction (after casting) equals SIG_IGN.  In
Packit Service c30d13
     this case, this implementation relies on the fact that the two
Packit Service c30d13
     are aliases, and simply returns sa_handler.  */
Packit Service c30d13
  return a->sa_handler;
Packit Service c30d13
}
Packit Service c30d13
Packit Service c30d13
_GL_INLINE_HEADER_END
Packit Service c30d13
Packit Service c30d13
#endif /* _GL_SIG_HANDLER_H */