]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/sys/fd_set.h
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / Include / sys / fd_set.h
CommitLineData
2aa62f2b 1/* $NetBSD: fd_set.h,v 1.2 2005/12/11 12:25:20 christos Exp $ */\r
2\r
3/*-\r
4 * Copyright (c) 1992, 1993\r
5 * The Regents of the University of California. All rights reserved.\r
6 *\r
7 * Redistribution and use in source and binary forms, with or without\r
8 * modification, are permitted provided that the following conditions\r
9 * are met:\r
10 * 1. Redistributions of source code must retain the above copyright\r
11 * notice, this list of conditions and the following disclaimer.\r
12 * 2. Redistributions in binary form must reproduce the above copyright\r
13 * notice, this list of conditions and the following disclaimer in the\r
14 * documentation and/or other materials provided with the distribution.\r
15 * 3. Neither the name of the University nor the names of its contributors\r
16 * may be used to endorse or promote products derived from this software\r
17 * without specific prior written permission.\r
18 *\r
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
29 * SUCH DAMAGE.\r
30 *\r
31 * from: @(#)types.h 8.4 (Berkeley) 1/21/94\r
32 */\r
33\r
34#ifndef _SYS_FD_SET_H_\r
35#define _SYS_FD_SET_H_\r
36\r
37#include <sys/EfiCdefs.h>\r
38#include <machine/int_types.h>\r
39\r
40/*\r
41 * Implementation dependent defines, hidden from user space. X/Open does not\r
42 * specify them.\r
43 */\r
44#define __NBBY 8 /* number of bits in a byte */\r
45typedef __int32_t __fd_mask;\r
46\r
47/* bits per mask */\r
48#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)\r
49\r
50#define __howmany(x, y) (((x) + ((y) - 1)) / (y))\r
51\r
52/*\r
53 * Select uses bit masks of file descriptors in longs. These macros\r
54 * manipulate such bit fields (the filesystem macros use chars).\r
55 * FD_SETSIZE may be defined by the user, but the default here should\r
56 * be enough for most uses.\r
57 */\r
58#ifndef FD_SETSIZE\r
59#define FD_SETSIZE 256\r
60#endif\r
61\r
62typedef struct fd_set {\r
63 __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];\r
64} fd_set;\r
65\r
66#define FD_SET(n, p) \\r
67 ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))\r
68#define FD_CLR(n, p) \\r
69 ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))\r
70#define FD_ISSET(n, p) \\r
71 ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))\r
72#if __GNUC_PREREQ__(2, 95)\r
73#define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p)))\r
74#else\r
75#define FD_ZERO(p) do { \\r
76 fd_set *__fds = (p); \\r
77 unsigned int __i; \\r
78 for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \\r
79 __fds->fds_bits[__i] = 0; \\r
80 } while (/* CONSTCOND */ 0)\r
81#endif /* GCC 2.95 */\r
82\r
83/*\r
84 * Expose our internals if we are not required to hide them.\r
85 */\r
86#if defined(_NETBSD_SOURCE)\r
87\r
88#define fd_mask __fd_mask\r
89#define NFDBITS __NFDBITS\r
90#ifndef howmany\r
91#define howmany(a, b) __howmany(a, b)\r
92#endif\r
93\r
94#if __GNUC_PREREQ__(2, 95)\r
95#define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f)))\r
96#else\r
97#define FD_COPY(f, t) do { \\r
98 fd_set *__f = (f), *__t = (t); \\r
99 unsigned int __i; \\r
100 for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \\r
101 __t->fds_bits[__i] = __f->fds_bits[__i]; \\r
102 } while (/* CONSTCOND */ 0)\r
103#endif /* GCC 2.95 */\r
104\r
105#endif /* _NETBSD_SOURCE */\r
106\r
107#endif /* _SYS_FD_SET_H_ */\r