package/uclibc: Fix removal of libintl.h
[uclibc-ng.git] / libc / signal / sigset.c
blob55ad92ecf4a54567c326ff598931c05ce9d4d578
1 /* Copyright (C) 1998, 2000, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #define __need_NULL
20 #include <stddef.h>
21 #include <signal.h>
22 #include <string.h>
24 /* Set the disposition for SIG. */
25 __sighandler_t sigset (int sig, __sighandler_t disp)
27 struct sigaction act, oact;
28 sigset_t set;
30 /* Check signal extents to protect __sigismember. */
31 if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
33 __set_errno (EINVAL);
34 return SIG_ERR;
37 #ifdef SIG_HOLD
38 /* Handle SIG_HOLD first. */
39 if (disp == SIG_HOLD)
41 __sigemptyset (&set);
42 __sigaddset (&set, sig);
44 /* Add the signal set to the current signal mask. */
45 sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */
47 return SIG_HOLD;
49 #endif /* SIG_HOLD */
51 memset(&act, 0, sizeof(act));
52 act.sa_handler = disp;
53 /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */
54 if (sigaction (sig, &act, &oact) < 0)
55 return SIG_ERR;
57 /* Create an empty signal set. Add the specified signal. */
58 __sigemptyset (&set);
59 __sigaddset (&set, sig);
61 /* Remove the signal set from the current signal mask. */
62 sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */
64 return oact.sa_handler;