xref: /onnv-gate/usr/src/lib/libc/port/gen/sigsetops.c (revision 6515:10dab2b883e0)
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
5*6515Sraf  * Common Development and Distribution License (the "License").
6*6515Sraf  * 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  */
21*6515Sraf 
220Sstevel@tonic-gate /*
23*6515Sraf  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
300Sstevel@tonic-gate /*	  All Rights Reserved  	*/
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * POSIX signal manipulation functions.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate #pragma weak sigfillset = _sigfillset
360Sstevel@tonic-gate #pragma weak sigemptyset = _sigemptyset
370Sstevel@tonic-gate #pragma weak sigaddset = _sigaddset
380Sstevel@tonic-gate #pragma weak sigdelset = _sigdelset
390Sstevel@tonic-gate #pragma weak sigismember = _sigismember
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include "synonyms.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/errno.h>
460Sstevel@tonic-gate #include <sys/signal.h>
470Sstevel@tonic-gate #include <errno.h>
480Sstevel@tonic-gate #include "libc.h"
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #define	SIGSETSIZE	4
510Sstevel@tonic-gate #define	MAXBITNO (NBPW*8)
520Sstevel@tonic-gate 
530Sstevel@tonic-gate static sigset_t sigs;
540Sstevel@tonic-gate static int sigsinit;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #define	sigword(n) ((n-1)/MAXBITNO)
570Sstevel@tonic-gate #define	bitmask(n) (1L<<((n-1)%MAXBITNO))
580Sstevel@tonic-gate 
590Sstevel@tonic-gate static int
600Sstevel@tonic-gate sigvalid(int sig)
610Sstevel@tonic-gate {
620Sstevel@tonic-gate 	if (sig <= 0 || sig > (MAXBITNO * SIGSETSIZE))
630Sstevel@tonic-gate 		return (0);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	if (!sigsinit) {
660Sstevel@tonic-gate 		(void) __sigfillset(&sigs);
670Sstevel@tonic-gate 		sigsinit++;
680Sstevel@tonic-gate 	}
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	return ((sigs.__sigbits[sigword(sig)] & bitmask(sig)) != 0);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate 
730Sstevel@tonic-gate int
740Sstevel@tonic-gate sigfillset(sigset_t *set)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	if (!sigsinit) {
770Sstevel@tonic-gate 		(void) __sigfillset(&sigs);
780Sstevel@tonic-gate 		sigsinit++;
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	*set = sigs;
820Sstevel@tonic-gate 	return (0);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate int
860Sstevel@tonic-gate sigemptyset(sigset_t *set)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	set->__sigbits[0] = 0;
890Sstevel@tonic-gate 	set->__sigbits[1] = 0;
900Sstevel@tonic-gate 	set->__sigbits[2] = 0;
910Sstevel@tonic-gate 	set->__sigbits[3] = 0;
920Sstevel@tonic-gate 	return (0);
930Sstevel@tonic-gate }
940Sstevel@tonic-gate 
950Sstevel@tonic-gate int
960Sstevel@tonic-gate sigaddset(sigset_t *set, int sig)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate 	if (!sigvalid(sig)) {
990Sstevel@tonic-gate 		errno = EINVAL;
1000Sstevel@tonic-gate 		return (-1);
1010Sstevel@tonic-gate 	}
1020Sstevel@tonic-gate 	set->__sigbits[sigword(sig)] |= bitmask(sig);
1030Sstevel@tonic-gate 	return (0);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate int
1070Sstevel@tonic-gate sigdelset(sigset_t *set, int sig)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	if (!sigvalid(sig)) {
1100Sstevel@tonic-gate 		errno = EINVAL;
1110Sstevel@tonic-gate 		return (-1);
1120Sstevel@tonic-gate 	}
1130Sstevel@tonic-gate 	set->__sigbits[sigword(sig)] &= ~bitmask(sig);
1140Sstevel@tonic-gate 	return (0);
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate int
1180Sstevel@tonic-gate sigismember(const sigset_t *set, int sig)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	if (!sigvalid(sig)) {
1210Sstevel@tonic-gate 		errno = EINVAL;
1220Sstevel@tonic-gate 		return (-1);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 	return ((set->__sigbits[sigword(sig)] & bitmask(sig)) != 0);
1250Sstevel@tonic-gate }
126