11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1989, 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * Redistribution and use in source and binary forms, with or without
61573Srgrimes * modification, are permitted provided that the following conditions
71573Srgrimes * are met:
81573Srgrimes * 1. Redistributions of source code must retain the above copyright
91573Srgrimes *    notice, this list of conditions and the following disclaimer.
101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer in the
121573Srgrimes *    documentation and/or other materials provided with the distribution.
131573Srgrimes * 4. Neither the name of the University nor the names of its contributors
141573Srgrimes *    may be used to endorse or promote products derived from this software
151573Srgrimes *    without specific prior written permission.
161573Srgrimes *
171573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271573Srgrimes * SUCH DAMAGE.
281573Srgrimes *
291573Srgrimes *	@(#)sigsetops.c	8.1 (Berkeley) 6/4/93
301573Srgrimes */
311573Srgrimes
321573Srgrimes#if defined(LIBC_SCCS) && !defined(lint)
331573Srgrimesstatic char sccsid[] = "@(#)sigsetops.c	8.1 (Berkeley) 6/4/93";
341573Srgrimes#endif /* LIBC_SCCS and not lint */
3590039Sobrien#include <sys/cdefs.h>
3690039Sobrien__FBSDID("$FreeBSD: stable/11/lib/libc/gen/sigsetops.c 355898 2019-12-19 02:09:16Z kevans $");
371573Srgrimes
3851872Smarcel#include <errno.h>
391573Srgrimes#include <signal.h>
401573Srgrimes
4117141Sjkhint
42288029Srodrigcsigaddset(sigset_t *set, int signo)
431573Srgrimes{
4451794Smarcel
4551872Smarcel	if (signo <= 0 || signo > _SIG_MAXSIG) {
4651872Smarcel		errno = EINVAL;
4751872Smarcel		return (-1);
4851872Smarcel	}
4951872Smarcel	set->__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo);
501573Srgrimes	return (0);
511573Srgrimes}
521573Srgrimes
5317141Sjkhint
54288029Srodrigcsigdelset(sigset_t *set, int signo)
551573Srgrimes{
5651794Smarcel
5751872Smarcel	if (signo <= 0 || signo > _SIG_MAXSIG) {
5851872Smarcel		errno = EINVAL;
5951872Smarcel		return (-1);
6051872Smarcel	}
6151872Smarcel	set->__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo);
621573Srgrimes	return (0);
631573Srgrimes}
641573Srgrimes
6517141Sjkhint
66288029Srodrigcsigemptyset(sigset_t *set)
671573Srgrimes{
6851872Smarcel	int i;
6951794Smarcel
7051872Smarcel	for (i = 0; i < _SIG_WORDS; i++)
7151872Smarcel		set->__bits[i] = 0;
721573Srgrimes	return (0);
731573Srgrimes}
741573Srgrimes
7517141Sjkhint
76288029Srodrigcsigfillset(sigset_t *set)
771573Srgrimes{
7851872Smarcel	int i;
7951794Smarcel
8051872Smarcel	for (i = 0; i < _SIG_WORDS; i++)
8151872Smarcel		set->__bits[i] = ~0U;
821573Srgrimes	return (0);
831573Srgrimes}
841573Srgrimes
8517141Sjkhint
86355898Skevanssigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
87355898Skevans{
88355898Skevans	int i;
89355898Skevans
90355898Skevans	for (i = 0; i < _SIG_WORDS; i++)
91355898Skevans		dest->__bits[i] = left->__bits[i] | right->__bits[i];
92355898Skevans	return (0);
93355898Skevans}
94355898Skevans
95355898Skevansint
96355898Skevanssigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
97355898Skevans{
98355898Skevans	int i;
99355898Skevans
100355898Skevans	for (i = 0; i < _SIG_WORDS; i++)
101355898Skevans		dest->__bits[i] = left->__bits[i] & right->__bits[i];
102355898Skevans	return (0);
103355898Skevans}
104355898Skevans
105355898Skevansint
106355898Skevanssigisemptyset(const sigset_t *set)
107355898Skevans{
108355898Skevans	int i;
109355898Skevans
110355898Skevans	for (i = 0; i < _SIG_WORDS; i++)
111355898Skevans		if (set->__bits[i] != 0)
112355898Skevans			return (0);
113355898Skevans	return (1);
114355898Skevans}
115355898Skevans
116355898Skevansint
117288029Srodrigcsigismember(const sigset_t *set, int signo)
1181573Srgrimes{
11951794Smarcel
12051794Smarcel	if (signo <= 0 || signo > _SIG_MAXSIG) {
12151872Smarcel		errno = EINVAL;
12251794Smarcel		return (-1);
12351794Smarcel	}
12451794Smarcel	return ((set->__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) ? 1 : 0);
1251573Srgrimes}
126