]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/signal/sigpause.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / signal / sigpause.c
1 /* Copyright (C) 1991,92,94-98,2000,2002,2003,2004
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library 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 GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #define __UCLIBC_HIDE_DEPRECATED__
21 /* psm: need the BSD version of sigpause here */
22 #include <errno.h>
23 #define __FAVOR_BSD
24 #include <signal.h>
25 #include <stddef.h>             /* For NULL.  */
26 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
27 #include <sysdep-cancel.h>
28 #endif
29
30 #include "sigset-cvt-mask.h"
31
32 /* Set the mask of blocked signals to MASK,
33    wait for a signal to arrive, and then restore the mask.  */
34 int __sigpause (int sig_or_mask, int is_sig)
35 {
36   sigset_t set;
37
38   if (is_sig)
39     {
40       /* The modern X/Open implementation is requested.  */
41       sigprocmask (SIG_BLOCK, NULL, &set);
42       /* Bound-check sig_or_mask, remove it from the set.  */
43       if (sigdelset (&set, sig_or_mask) < 0)
44         return -1;
45     }
46   else
47     sigset_set_old_mask (&set, sig_or_mask);
48
49   /* Note the sigpause() is a cancellation point.  But since we call
50      sigsuspend() which itself is a cancellation point we do not have
51      to do anything here.  */
52   return sigsuspend (&set);
53 }
54 libc_hidden_def(__sigpause)
55
56 #undef sigpause
57
58 /* We have to provide a default version of this function since the
59    standards demand it.  The version which is a bit more reasonable is
60    the BSD version.  So make this the default.  */
61 int sigpause (int mask)
62 {
63 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
64   if (SINGLE_THREAD_P)
65     return __sigpause (mask, 0);
66
67   int oldtype = LIBC_CANCEL_ASYNC ();
68
69   int result = __sigpause (mask, 0);
70
71   LIBC_CANCEL_RESET (oldtype);
72
73   return result;
74 #else
75   return __sigpause (mask, 0);
76 #endif
77 }