Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / sigwait.c
bloba304ed978bcdbd1dfba444e649abb9d6e303228b
1 /* Copyright (C) 1997,1998,2000,2002-2004,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 #include <signal.h>
20 #define __need_NULL
21 #include <stddef.h>
22 #include <string.h>
24 #include <sysdep-cancel.h>
25 #include <sys/syscall.h>
26 #include <bp-checks.h>
28 #ifdef __NR_rt_sigtimedwait
30 /* Return any pending signal or wait for one for the given time. */
31 static int
32 do_sigwait (const sigset_t *set, int *sig)
34 int ret;
36 #ifdef SIGCANCEL
37 sigset_t tmpset;
38 if (set != NULL
39 && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
40 # ifdef SIGSETXID
41 || __builtin_expect (__sigismember (set, SIGSETXID), 0)
42 # endif
45 /* Create a temporary mask without the bit for SIGCANCEL set. */
46 // We are not copying more than we have to.
47 memcpy (&tmpset, set, _NSIG / 8);
48 __sigdelset (&tmpset, SIGCANCEL);
49 # ifdef SIGSETXID
50 __sigdelset (&tmpset, SIGSETXID);
51 # endif
52 set = &tmpset;
54 #endif
56 /* XXX The size argument hopefully will have to be changed to the
57 real size of the user-level sigset_t. */
58 #ifdef INTERNAL_SYSCALL
59 INTERNAL_SYSCALL_DECL (err);
61 ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, CHECK_SIGSET (set),
62 NULL, NULL, _NSIG / 8);
63 while (INTERNAL_SYSCALL_ERROR_P (ret, err)
64 && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR);
65 if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
67 *sig = ret;
68 ret = 0;
70 else
71 ret = INTERNAL_SYSCALL_ERRNO (ret, err);
72 #else
74 ret = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
75 NULL, NULL, _NSIG / 8);
76 while (ret == -1 && errno == EINTR);
77 if (ret != -1)
79 *sig = ret;
80 ret = 0;
82 else
83 ret = errno;
84 #endif
86 return ret;
89 int
90 __sigwait (set, sig)
91 const sigset_t *set;
92 int *sig;
94 if (SINGLE_THREAD_P)
95 return do_sigwait (set, sig);
97 int oldtype = LIBC_CANCEL_ASYNC ();
99 int result = do_sigwait (set, sig);
101 LIBC_CANCEL_RESET (oldtype);
103 return result;
105 libc_hidden_def (__sigwait)
106 weak_alias (__sigwait, sigwait)
107 #else
108 # include <sysdeps/posix/sigwait.c>
109 #endif
110 strong_alias (__sigwait, __libc_sigwait)