17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
58cd4554raf * Common Development and Distribution License (the "License").
68cd4554raf * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
218cd4554raf
227c478bdstevel@tonic-gate/*
238cd4554raf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*	Copyright (c) 1988 AT&T	*/
287c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
297c478bdstevel@tonic-gate
307257d1braf#pragma ident	"%Z%%M%	%I%	%E% SMI"
317257d1braf
327c478bdstevel@tonic-gate/*
337c478bdstevel@tonic-gate * POSIX signal manipulation functions.
347c478bdstevel@tonic-gate */
357257d1braf#pragma weak _sigfillset = sigfillset
367257d1braf#pragma weak _sigemptyset = sigemptyset
377257d1braf#pragma weak _sigaddset = sigaddset
387257d1braf#pragma weak _sigdelset = sigdelset
397257d1braf#pragma weak _sigismember = sigismember
407c478bdstevel@tonic-gate
417257d1braf#include "lint.h"
427c478bdstevel@tonic-gate#include <sys/types.h>
437c478bdstevel@tonic-gate#include <stdio.h>
447c478bdstevel@tonic-gate#include <sys/param.h>
457c478bdstevel@tonic-gate#include <sys/signal.h>
467c478bdstevel@tonic-gate#include <errno.h>
477c478bdstevel@tonic-gate#include "libc.h"
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate#define	SIGSETSIZE	4
507c478bdstevel@tonic-gate#define	MAXBITNO (NBPW*8)
517c478bdstevel@tonic-gate
527c478bdstevel@tonic-gatestatic sigset_t sigs;
537c478bdstevel@tonic-gatestatic int sigsinit;
547c478bdstevel@tonic-gate
557c478bdstevel@tonic-gate#define	sigword(n) ((n-1)/MAXBITNO)
567c478bdstevel@tonic-gate#define	bitmask(n) (1L<<((n-1)%MAXBITNO))
577c478bdstevel@tonic-gate
587c478bdstevel@tonic-gatestatic int
597c478bdstevel@tonic-gatesigvalid(int sig)
607c478bdstevel@tonic-gate{
617c478bdstevel@tonic-gate	if (sig <= 0 || sig > (MAXBITNO * SIGSETSIZE))
627c478bdstevel@tonic-gate		return (0);
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate	if (!sigsinit) {
657c478bdstevel@tonic-gate		(void) __sigfillset(&sigs);
667c478bdstevel@tonic-gate		sigsinit++;
677c478bdstevel@tonic-gate	}
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate	return ((sigs.__sigbits[sigword(sig)] & bitmask(sig)) != 0);
707c478bdstevel@tonic-gate}
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gateint
737c478bdstevel@tonic-gatesigfillset(sigset_t *set)
747c478bdstevel@tonic-gate{
757c478bdstevel@tonic-gate	if (!sigsinit) {
767c478bdstevel@tonic-gate		(void) __sigfillset(&sigs);
777c478bdstevel@tonic-gate		sigsinit++;
787c478bdstevel@tonic-gate	}
797c478bdstevel@tonic-gate
807c478bdstevel@tonic-gate	*set = sigs;
817c478bdstevel@tonic-gate	return (0);
827c478bdstevel@tonic-gate}
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gateint
857c478bdstevel@tonic-gatesigemptyset(sigset_t *set)
867c478bdstevel@tonic-gate{
877c478bdstevel@tonic-gate	set->__sigbits[0] = 0;
887c478bdstevel@tonic-gate	set->__sigbits[1] = 0;
897c478bdstevel@tonic-gate	set->__sigbits[2] = 0;
907c478bdstevel@tonic-gate	set->__sigbits[3] = 0;
917c478bdstevel@tonic-gate	return (0);
927c478bdstevel@tonic-gate}
937c478bdstevel@tonic-gate
947c478bdstevel@tonic-gateint
957c478bdstevel@tonic-gatesigaddset(sigset_t *set, int sig)
967c478bdstevel@tonic-gate{
977c478bdstevel@tonic-gate	if (!sigvalid(sig)) {
987c478bdstevel@tonic-gate		errno = EINVAL;
997c478bdstevel@tonic-gate		return (-1);
1007c478bdstevel@tonic-gate	}
1017c478bdstevel@tonic-gate	set->__sigbits[sigword(sig)] |= bitmask(sig);
1027c478bdstevel@tonic-gate	return (0);
1037c478bdstevel@tonic-gate}
1047c478bdstevel@tonic-gate
1057c478bdstevel@tonic-gateint
1067c478bdstevel@tonic-gatesigdelset(sigset_t *set, int sig)
1077c478bdstevel@tonic-gate{
1087c478bdstevel@tonic-gate	if (!sigvalid(sig)) {
1097c478bdstevel@tonic-gate		errno = EINVAL;
1107c478bdstevel@tonic-gate		return (-1);
1117c478bdstevel@tonic-gate	}
1127c478bdstevel@tonic-gate	set->__sigbits[sigword(sig)] &= ~bitmask(sig);
1137c478bdstevel@tonic-gate	return (0);
1147c478bdstevel@tonic-gate}
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gateint
1177c478bdstevel@tonic-gatesigismember(const sigset_t *set, int sig)
1187c478bdstevel@tonic-gate{
1197c478bdstevel@tonic-gate	if (!sigvalid(sig)) {
1207c478bdstevel@tonic-gate		errno = EINVAL;
1217c478bdstevel@tonic-gate		return (-1);
1227c478bdstevel@tonic-gate	}
1237c478bdstevel@tonic-gate	return ((set->__sigbits[sigword(sig)] & bitmask(sig)) != 0);
1247c478bdstevel@tonic-gate}
125