* Factor out fd_set and related definitions from <sys/types.h> to
<sys/fd_set.h>. Still include it from <sys/types.h> for _NETBSD_SOURCE, and amke <sys/select.h> use it instead of <sys/types.h>. * Instead of including <string.h> for memset()/memcpy() (or adding their declarations locally), make FD_ZERO()/FD_COPY() use GCC builtins if available, or define them inline otherwise. Approved by Christos.
This commit is contained in:
parent
10e3f817a6
commit
3a2b4d4dd7
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.785 2005/05/15 21:12:53 christos Exp $
|
||||
# $NetBSD: mi,v 1.786 2005/05/22 12:44:24 kleink Exp $
|
||||
./etc/mtree/set.comp comp-sys-root
|
||||
./usr/bin/addr2line comp-debug-bin bfd
|
||||
./usr/bin/ar comp-util-bin bfd
|
||||
@ -1330,6 +1330,7 @@
|
||||
./usr/include/sys/extattr.h comp-c-include
|
||||
./usr/include/sys/extent.h comp-c-include
|
||||
./usr/include/sys/fcntl.h comp-c-include
|
||||
./usr/include/sys/fd_set.h comp-c-include
|
||||
./usr/include/sys/fdio.h comp-c-include
|
||||
./usr/include/sys/featuretest.h comp-c-include
|
||||
./usr/include/sys/file.h comp-c-include
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.72 2005/03/17 20:39:17 kleink Exp $
|
||||
# $NetBSD: Makefile,v 1.73 2005/05/22 12:44:24 kleink Exp $
|
||||
|
||||
INCSDIR= /usr/include/sys
|
||||
|
||||
@ -10,7 +10,7 @@ INCS= acct.h agpio.h ansi.h ataio.h audioio.h \
|
||||
dkbad.h dkio.h dkstat.h domain.h drvctlio.h dvdio.h \
|
||||
endian.h envsys.h errno.h event.h exec.h exec_aout.h \
|
||||
exec_coff.h exec_ecoff.h exec_elf.h exec_script.h extattr.h extent.h \
|
||||
fcntl.h fdio.h featuretest.h file.h filedesc.h filio.h \
|
||||
fcntl.h fd_set.h fdio.h featuretest.h file.h filedesc.h filio.h \
|
||||
float_ieee754.h fstypes.h gmon.h hash.h \
|
||||
ieee754.h inttypes.h ioccom.h ioctl.h ioctl_compat.h ipc.h \
|
||||
joystick.h \
|
||||
|
108
sys/sys/fd_set.h
Normal file
108
sys/sys/fd_set.h
Normal file
@ -0,0 +1,108 @@
|
||||
/* $NetBSD: fd_set.h,v 1.1 2005/05/22 12:44:24 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)types.h 8.4 (Berkeley) 1/21/94
|
||||
*/
|
||||
|
||||
#ifndef _SYS_FD_SET_H_
|
||||
#define _SYS_FD_SET_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/featuretest.h>
|
||||
#include <machine/int_types.h>
|
||||
|
||||
/*
|
||||
* Implementation dependent defines, hidden from user space. X/Open does not
|
||||
* specify them.
|
||||
*/
|
||||
#define __NBBY 8 /* number of bits in a byte */
|
||||
typedef __int32_t __fd_mask;
|
||||
|
||||
/* bits per mask */
|
||||
#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)
|
||||
|
||||
#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
|
||||
|
||||
/*
|
||||
* Select uses bit masks of file descriptors in longs. These macros
|
||||
* manipulate such bit fields (the filesystem macros use chars).
|
||||
* FD_SETSIZE may be defined by the user, but the default here should
|
||||
* be enough for most uses.
|
||||
*/
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 256
|
||||
#endif
|
||||
|
||||
typedef struct fd_set {
|
||||
__fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
|
||||
} fd_set;
|
||||
|
||||
#define FD_SET(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))
|
||||
#define FD_CLR(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))
|
||||
#define FD_ISSET(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))
|
||||
#if __GNUC_PREREQ__(2, 95)
|
||||
#define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p)))
|
||||
#else
|
||||
#define FD_ZERO(p) do { \
|
||||
fd_set *__fds = (p); \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
|
||||
__fds->fds_bits[__i] = 0; \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#endif /* GCC 2.95 */
|
||||
|
||||
/*
|
||||
* Expose our internals if we are not required to hide them.
|
||||
*/
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
|
||||
#define fd_mask __fd_mask
|
||||
#define NFDBITS __NFDBITS
|
||||
#ifndef howmany
|
||||
#define howmany(a, b) __howmany(a, b)
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ__(2, 95)
|
||||
#define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f)))
|
||||
#else
|
||||
#define FD_COPY(f, t) do { \
|
||||
fd_set *__f = (f), *__t = (t); \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
|
||||
__t->fds_bits[__i] = __f->fds_bits[__i]; \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#endif /* GCC 2.95 */
|
||||
|
||||
#endif /* _NETBSD_SOURCE */
|
||||
|
||||
#endif /* _SYS_FD_SET_H_ */
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: select.h,v 1.23 2005/03/18 16:11:14 kleink Exp $ */
|
||||
/* $NetBSD: select.h,v 1.24 2005/05/22 12:44:24 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/featuretest.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fd_set.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/selinfo.h> /* for struct selinfo */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: types.h,v 1.66 2005/03/05 19:48:39 kleink Exp $ */
|
||||
/* $NetBSD: types.h,v 1.67 2005/05/22 12:44:24 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1991, 1993, 1994
|
||||
@ -289,62 +289,9 @@ typedef _BSD_USECONDS_T_ useconds_t;
|
||||
#undef _BSD_USECONDS_T_
|
||||
#endif
|
||||
|
||||
#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
|
||||
(_POSIX_C_SOURCE - 0) >= 200112L || \
|
||||
(_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
|
||||
|
||||
/*
|
||||
* Implementation dependent defines, hidden from user space. X/Open does not
|
||||
* specify them.
|
||||
*/
|
||||
#define __NBBY 8 /* number of bits in a byte */
|
||||
typedef int32_t __fd_mask;
|
||||
|
||||
/* bits per mask */
|
||||
#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)
|
||||
|
||||
#ifndef howmany
|
||||
#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
|
||||
#else
|
||||
#define __howmany(x, y) howmany(x, y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Select uses bit masks of file descriptors in longs. These macros
|
||||
* manipulate such bit fields (the filesystem macros use chars).
|
||||
* FD_SETSIZE may be defined by the user, but the default here should
|
||||
* be enough for most uses.
|
||||
*/
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 256
|
||||
#endif
|
||||
|
||||
typedef struct fd_set {
|
||||
__fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
|
||||
} fd_set;
|
||||
|
||||
#define FD_SET(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))
|
||||
#define FD_CLR(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))
|
||||
#define FD_ISSET(n, p) \
|
||||
((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))
|
||||
#define FD_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
|
||||
|
||||
/*
|
||||
* Expose our internals if we are not required to hide them.
|
||||
*/
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
|
||||
#define NBBY __NBBY
|
||||
#define fd_mask __fd_mask
|
||||
#define NFDBITS __NFDBITS
|
||||
#ifndef howmany
|
||||
#define howmany(a, b) __howmany(a, b)
|
||||
#endif
|
||||
|
||||
#define FD_COPY(f, t) (void)memcpy((t), (f), sizeof(*(f)))
|
||||
|
||||
#ifdef _NETBSD_SOURCE
|
||||
#include <sys/fd_set.h>
|
||||
#define NBBY __NBBY
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) && defined(_KERNEL)
|
||||
@ -366,8 +313,6 @@ struct tty;
|
||||
struct uio;
|
||||
#endif
|
||||
|
||||
#endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
|
||||
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||
#if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
|
||||
defined(_NETBSD_SOURCE)
|
||||
|
Loading…
Reference in New Issue
Block a user