]> git.saurik.com Git - apple/libc.git/blame - sys/select.c
Libc-498.tar.gz
[apple/libc.git] / sys / select.c
CommitLineData
224c7076
A
1/*
2 * Copyright (c) 2005, 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#if defined(__LP64__) && (defined(VARIANT_CANCELABLE) || defined(VARIANT_PRE1050))
24#undef __DARWIN_NON_CANCELABLE
25#define __DARWIN_NON_CANCELABLE 0
26#endif /* __LP64__ && (VARIANT_CANCELABLE || VARIANT_PRE1050) */
27#include <sys/select.h>
28#include <errno.h>
29
30#if defined(VARIANT_CANCELABLE) || defined(VARIANT_PRE1050)
31extern int __select(int, fd_set * __restrict, fd_set * __restrict,
32 fd_set * __restrict, struct timeval * __restrict);
33#else /* !VARIANT_CANCELABLE && !VARIANT_PRE1050 */
34int __select_nocancel(int, fd_set * __restrict, fd_set * __restrict,
35 fd_set * __restrict, struct timeval * __restrict);
36#endif /* VARIANT_CANCELABLE || VARIANT_PRE1050 */
37
38/*
39 * select stub, return error if nfds > FD_SETSIZE
40 * add pthread cancelability
41 * mandated for conformance.
42 *
43 * This is only for (non DARWINEXTSN) UNIX03 (both cancelable and
44 * non-cancelable) and for legacy
45 */
46int
47select(int nfds, fd_set * __restrict readfds, fd_set * __restrict writefds,
48 fd_set * __restrict exceptfds, struct timeval * __restrict
49#if defined(VARIANT_LEGACY) || defined(VARIANT_PRE1050)
50 intimeout
51#else /* !VARIANT_LEGACY && !VARIANT_PRE1050 */
52 timeout
53#endif /* VARIANT_LEGACY || VARIANT_PRE1050 */
54 )
55{
56
57#if defined(VARIANT_LEGACY) || defined(VARIANT_PRE1050)
58 struct timeval tb, *timeout;
59
60 /*
61 * Legacy select behavior is minimum 10 msec when tv_usec is non-zero
62 */
63 if (intimeout && intimeout->tv_sec == 0 && intimeout->tv_usec > 0 && intimeout->tv_usec < 10000) {
64 tb.tv_sec = 0;
65 tb.tv_usec = 10000;
66 timeout = &tb;
67 } else
68 timeout = intimeout;
69#else /* !VARIANT_LEGACY && !VARIANT_PRE1050 */
70 if (nfds > FD_SETSIZE) {
71 errno = EINVAL;
72 return -1;
73 }
74#endif /* VARIANT_LEGACY || VARIANT_PRE1050 */
75#if defined(VARIANT_CANCELABLE) || defined(VARIANT_PRE1050)
76 return __select(nfds, readfds, writefds, exceptfds, timeout);
77#else /* !VARIANT_CANCELABLE && !VARIANT_PRE1050 */
78 return __select_nocancel(nfds, readfds, writefds, exceptfds, timeout);
79#endif /* VARIANT_CANCELABLE || VARIANT_PRE1050 */
80}