xref: /haiku/src/system/libroot/posix/sys/select.cpp (revision 46b7da1f4f40f7157d74fc7fb26ff9ec7f2416f2)
1 /*
2  * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de.
3  * All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include <sys/select.h>
9 
10 #include <errno.h>
11 #include <pthread.h>
12 
13 #include <syscall_utils.h>
14 
15 #include <errno_private.h>
16 #include <signal_private.h>
17 #include <symbol_versioning.h>
18 #include <syscalls.h>
19 #include <time_private.h>
20 
21 
22 extern "C" int __pselect_beos(int numBits, struct fd_set *readBits,
23 	struct fd_set *writeBits, struct fd_set *errorBits,
24 	const struct timespec *tv, const sigset_t *beosSignalMask);
25 extern "C" int __pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
26 	struct fd_set *errorBits, const struct timespec *tv,
27 	const sigset_t *sigMask);
28 
29 
30 int
__pselect_beos(int numBits,struct fd_set * readBits,struct fd_set * writeBits,struct fd_set * errorBits,const struct timespec * tv,const sigset_t * beosSignalMask)31 __pselect_beos(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
32 	struct fd_set *errorBits, const struct timespec *tv,
33 	const sigset_t *beosSignalMask)
34 {
35 	int status;
36 	sigset_t signalMask;
37 	bigtime_t timeout = -1LL;
38 	if (tv != NULL && !timespec_to_bigtime(*tv, timeout))
39 		RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
40 
41 	if (beosSignalMask != NULL)
42 		signalMask = from_beos_sigset(*beosSignalMask);
43 
44 	status = _kern_select(numBits, readBits, writeBits, errorBits, timeout,
45 		beosSignalMask != NULL ? &signalMask : NULL);
46 
47 	RETURN_AND_SET_ERRNO_TEST_CANCEL(status);
48 }
49 
50 
51 int
__pselect(int numBits,struct fd_set * readBits,struct fd_set * writeBits,struct fd_set * errorBits,const struct timespec * tv,const sigset_t * sigMask)52 __pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
53 	struct fd_set *errorBits, const struct timespec *tv,
54 	const sigset_t *sigMask)
55 {
56 	int status;
57 	bigtime_t timeout = -1LL;
58 	if (tv != NULL && !timespec_to_bigtime(*tv, timeout))
59 		RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
60 
61 	status = _kern_select(numBits, readBits, writeBits, errorBits, timeout,
62 		sigMask);
63 
64 	RETURN_AND_SET_ERRNO_TEST_CANCEL(status);
65 }
66 
67 
68 int
select(int numBits,struct fd_set * readBits,struct fd_set * writeBits,struct fd_set * errorBits,struct timeval * tv)69 select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
70 	struct fd_set *errorBits, struct timeval *tv)
71 {
72 	int status;
73 	bigtime_t timeout = -1LL;
74 	if (tv != NULL && !timeval_to_bigtime(*tv, timeout))
75 		RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
76 
77 	status = _kern_select(numBits, readBits, writeBits, errorBits, timeout,
78 		NULL);
79 
80 	RETURN_AND_SET_ERRNO_TEST_CANCEL(status);
81 }
82 
83 
84 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__pselect_beos", "pselect@", "BASE");
85 
86 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__pselect", "pselect@@", "1_ALPHA4");
87