import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / sigsetops.c
blobb9862220fb8a695578ff0e0512fb61f9994a0011
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * POSIX signal manipulation functions.
35 #pragma weak _sigfillset = sigfillset
36 #pragma weak _sigemptyset = sigemptyset
37 #pragma weak _sigaddset = sigaddset
38 #pragma weak _sigdelset = sigdelset
39 #pragma weak _sigismember = sigismember
41 #include "lint.h"
42 #include <sys/types.h>
43 #include <stdio.h>
44 #include <sys/param.h>
45 #include <sys/signal.h>
46 #include <errno.h>
47 #include "libc.h"
49 #define SIGSETSIZE 4
50 #define MAXBITNO (NBPW*8)
52 static sigset_t sigs;
53 static int sigsinit;
55 #define sigword(n) ((n-1)/MAXBITNO)
56 #define bitmask(n) (1L<<((n-1)%MAXBITNO))
58 static int
59 sigvalid(int sig)
61 if (sig <= 0 || sig > (MAXBITNO * SIGSETSIZE))
62 return (0);
64 if (!sigsinit) {
65 (void) __sigfillset(&sigs);
66 sigsinit++;
69 return ((sigs.__sigbits[sigword(sig)] & bitmask(sig)) != 0);
72 int
73 sigfillset(sigset_t *set)
75 if (!sigsinit) {
76 (void) __sigfillset(&sigs);
77 sigsinit++;
80 *set = sigs;
81 return (0);
84 int
85 sigemptyset(sigset_t *set)
87 set->__sigbits[0] = 0;
88 set->__sigbits[1] = 0;
89 set->__sigbits[2] = 0;
90 set->__sigbits[3] = 0;
91 return (0);
94 int
95 sigaddset(sigset_t *set, int sig)
97 if (!sigvalid(sig)) {
98 errno = EINVAL;
99 return (-1);
101 set->__sigbits[sigword(sig)] |= bitmask(sig);
102 return (0);
106 sigdelset(sigset_t *set, int sig)
108 if (!sigvalid(sig)) {
109 errno = EINVAL;
110 return (-1);
112 set->__sigbits[sigword(sig)] &= ~bitmask(sig);
113 return (0);
117 sigismember(const sigset_t *set, int sig)
119 if (!sigvalid(sig)) {
120 errno = EINVAL;
121 return (-1);
123 return ((set->__sigbits[sigword(sig)] & bitmask(sig)) != 0);