xref: /onnv-gate/usr/src/lib/libc/port/gen/sigsetops.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56515Sraf  * Common Development and Distribution License (the "License").
66515Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216515Sraf 
220Sstevel@tonic-gate /*
236515Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
30*6812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*6812Sraf 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * POSIX signal manipulation functions.
340Sstevel@tonic-gate  */
35*6812Sraf #pragma weak _sigfillset = sigfillset
36*6812Sraf #pragma weak _sigemptyset = sigemptyset
37*6812Sraf #pragma weak _sigaddset = sigaddset
38*6812Sraf #pragma weak _sigdelset = sigdelset
39*6812Sraf #pragma weak _sigismember = sigismember
400Sstevel@tonic-gate 
41*6812Sraf #include "lint.h"
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <stdio.h>
440Sstevel@tonic-gate #include <sys/param.h>
450Sstevel@tonic-gate #include <sys/signal.h>
460Sstevel@tonic-gate #include <errno.h>
470Sstevel@tonic-gate #include "libc.h"
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #define	SIGSETSIZE	4
500Sstevel@tonic-gate #define	MAXBITNO (NBPW*8)
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static sigset_t sigs;
530Sstevel@tonic-gate static int sigsinit;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	sigword(n) ((n-1)/MAXBITNO)
560Sstevel@tonic-gate #define	bitmask(n) (1L<<((n-1)%MAXBITNO))
570Sstevel@tonic-gate 
580Sstevel@tonic-gate static int
sigvalid(int sig)590Sstevel@tonic-gate sigvalid(int sig)
600Sstevel@tonic-gate {
610Sstevel@tonic-gate 	if (sig <= 0 || sig > (MAXBITNO * SIGSETSIZE))
620Sstevel@tonic-gate 		return (0);
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	if (!sigsinit) {
650Sstevel@tonic-gate 		(void) __sigfillset(&sigs);
660Sstevel@tonic-gate 		sigsinit++;
670Sstevel@tonic-gate 	}
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	return ((sigs.__sigbits[sigword(sig)] & bitmask(sig)) != 0);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate int
sigfillset(sigset_t * set)730Sstevel@tonic-gate sigfillset(sigset_t *set)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate 	if (!sigsinit) {
760Sstevel@tonic-gate 		(void) __sigfillset(&sigs);
770Sstevel@tonic-gate 		sigsinit++;
780Sstevel@tonic-gate 	}
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	*set = sigs;
810Sstevel@tonic-gate 	return (0);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate 
840Sstevel@tonic-gate int
sigemptyset(sigset_t * set)850Sstevel@tonic-gate sigemptyset(sigset_t *set)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate 	set->__sigbits[0] = 0;
880Sstevel@tonic-gate 	set->__sigbits[1] = 0;
890Sstevel@tonic-gate 	set->__sigbits[2] = 0;
900Sstevel@tonic-gate 	set->__sigbits[3] = 0;
910Sstevel@tonic-gate 	return (0);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate 
940Sstevel@tonic-gate int
sigaddset(sigset_t * set,int sig)950Sstevel@tonic-gate sigaddset(sigset_t *set, int sig)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate 	if (!sigvalid(sig)) {
980Sstevel@tonic-gate 		errno = EINVAL;
990Sstevel@tonic-gate 		return (-1);
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate 	set->__sigbits[sigword(sig)] |= bitmask(sig);
1020Sstevel@tonic-gate 	return (0);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate int
sigdelset(sigset_t * set,int sig)1060Sstevel@tonic-gate sigdelset(sigset_t *set, int sig)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate 	if (!sigvalid(sig)) {
1090Sstevel@tonic-gate 		errno = EINVAL;
1100Sstevel@tonic-gate 		return (-1);
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 	set->__sigbits[sigword(sig)] &= ~bitmask(sig);
1130Sstevel@tonic-gate 	return (0);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate int
sigismember(const sigset_t * set,int sig)1170Sstevel@tonic-gate sigismember(const sigset_t *set, int sig)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	if (!sigvalid(sig)) {
1200Sstevel@tonic-gate 		errno = EINVAL;
1210Sstevel@tonic-gate 		return (-1);
1220Sstevel@tonic-gate 	}
1230Sstevel@tonic-gate 	return ((set->__sigbits[sigword(sig)] & bitmask(sig)) != 0);
1240Sstevel@tonic-gate }
125