1 | #include <lib.h>
|
---|
2 | /* XXX - these have to be hidden because signal() uses them and signal() is
|
---|
3 | * ANSI and not POSIX. It would be surely be better to use macros for the
|
---|
4 | * library and system uses, and perhaps macros as well as functions for the
|
---|
5 | * POSIX user interface. The macros would not need underlines. It may be
|
---|
6 | * inconvenient to match the exact semantics of the current functions
|
---|
7 | * because the interface is bloated by reporting errors. For library and
|
---|
8 | * system uses, the signal number is mostly already known to be valid
|
---|
9 | * before the sigset-changing routines are called.
|
---|
10 | */
|
---|
11 | #define sigaddset _sigaddset
|
---|
12 | #define sigdelset _sigdelset
|
---|
13 | #define sigemptyset _sigemptyset
|
---|
14 | #define sigfillset _sigfillset
|
---|
15 | #define sigismember _sigismember
|
---|
16 | #include <signal.h>
|
---|
17 |
|
---|
18 | /* Low bit of signal masks. */
|
---|
19 | #define SIGBIT_0 ((sigset_t) 1)
|
---|
20 |
|
---|
21 | /* Mask of valid signals (0 - _NSIG). */
|
---|
22 | #define SIGMASK (((SIGBIT_0 << _NSIG) << 1) - 1)
|
---|
23 |
|
---|
24 | #define sigisvalid(signo) ((unsigned) (signo) <= _NSIG)
|
---|
25 |
|
---|
26 | PUBLIC int sigaddset(set, signo)
|
---|
27 | sigset_t *set;
|
---|
28 | int signo;
|
---|
29 | {
|
---|
30 | if (!sigisvalid(signo)) {
|
---|
31 | errno = EINVAL;
|
---|
32 | return -1;
|
---|
33 | }
|
---|
34 | *set |= SIGBIT_0 << signo;
|
---|
35 | return 0;
|
---|
36 | }
|
---|
37 |
|
---|
38 | PUBLIC int sigdelset(set, signo)
|
---|
39 | sigset_t *set;
|
---|
40 | int signo;
|
---|
41 | {
|
---|
42 | if (!sigisvalid(signo)) {
|
---|
43 | errno = EINVAL;
|
---|
44 | return -1;
|
---|
45 | }
|
---|
46 | *set &= ~(SIGBIT_0 << signo);
|
---|
47 | return 0;
|
---|
48 | }
|
---|
49 |
|
---|
50 | PUBLIC int sigemptyset(set)
|
---|
51 | sigset_t *set;
|
---|
52 | {
|
---|
53 | *set = 0;
|
---|
54 | return 0;
|
---|
55 | }
|
---|
56 |
|
---|
57 | PUBLIC int sigfillset(set)
|
---|
58 | sigset_t *set;
|
---|
59 | {
|
---|
60 | *set = SIGMASK;
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | PUBLIC int sigismember(set, signo)
|
---|
65 | _CONST sigset_t *set;
|
---|
66 | int signo;
|
---|
67 | {
|
---|
68 | if (!sigisvalid(signo)) {
|
---|
69 | errno = EINVAL;
|
---|
70 | return -1;
|
---|
71 | }
|
---|
72 | if (*set & (SIGBIT_0 << signo))
|
---|
73 | return 1;
|
---|
74 | return 0;
|
---|
75 | }
|
---|