xref: /openbsd/lib/libc/sys/w_pselect.c (revision fe38b55c)
1*fe38b55cSguenther /*	$OpenBSD: w_pselect.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
2*fe38b55cSguenther /*
3*fe38b55cSguenther  * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
4*fe38b55cSguenther  *
5*fe38b55cSguenther  * Permission to use, copy, modify, and distribute this software for any
6*fe38b55cSguenther  * purpose with or without fee is hereby granted, provided that the above
7*fe38b55cSguenther  * copyright notice and this permission notice appear in all copies.
8*fe38b55cSguenther  *
9*fe38b55cSguenther  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*fe38b55cSguenther  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*fe38b55cSguenther  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*fe38b55cSguenther  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*fe38b55cSguenther  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*fe38b55cSguenther  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*fe38b55cSguenther  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*fe38b55cSguenther  */
17*fe38b55cSguenther 
18*fe38b55cSguenther #include <sys/select.h>
19*fe38b55cSguenther #include <signal.h>
20*fe38b55cSguenther #include "cancel.h"
21*fe38b55cSguenther 
22*fe38b55cSguenther int
pselect(int nfds,fd_set * readfds,fd_set * writefds,fd_set * exceptfds,const struct timespec * timeout,const sigset_t * sigmask)23*fe38b55cSguenther pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
24*fe38b55cSguenther     const struct timespec *timeout, const sigset_t *sigmask)
25*fe38b55cSguenther {
26*fe38b55cSguenther 	sigset_t set;
27*fe38b55cSguenther 	int ret;
28*fe38b55cSguenther 
29*fe38b55cSguenther 	if (sigmask != NULL && sigismember(sigmask, SIGTHR)) {
30*fe38b55cSguenther 		set = *sigmask;
31*fe38b55cSguenther 		sigdelset(&set, SIGTHR);
32*fe38b55cSguenther 		sigmask = &set;
33*fe38b55cSguenther 	}
34*fe38b55cSguenther 
35*fe38b55cSguenther 	ENTER_CANCEL_POINT(1);
36*fe38b55cSguenther 	ret = HIDDEN(pselect)(nfds, readfds, writefds, exceptfds, timeout,
37*fe38b55cSguenther 	    sigmask);
38*fe38b55cSguenther 	LEAVE_CANCEL_POINT(ret == -1);
39*fe38b55cSguenther 
40*fe38b55cSguenther 	return (ret);
41*fe38b55cSguenther }
42*fe38b55cSguenther DEF_CANCEL(pselect);
43