sys/select.h: Cleanup.
* Always declare FD_SET rather than conditionally. This matches the behavior of the glibc, musl, FreeBSD headers. * Simplify comments. * Leave the custom FD_SETSIZE possibility in place for now. Neither glibc nor musl permit this, but FreeBSD still does.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
|
* Copyright 2002-2024, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _SYS_SELECT_H
|
#ifndef _SYS_SELECT_H
|
||||||
@@ -10,23 +10,18 @@
|
|||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
/* If FD_SET is already defined, only the select() prototype is
|
/* Custom FD_SETSIZEs can be defined if more bits are needed, but the default
|
||||||
* exported in this header.
|
* should suffice for most uses. */
|
||||||
*/
|
|
||||||
#ifndef FD_SET
|
|
||||||
|
|
||||||
/* You can define your own FDSETSIZE if you need more bits - but
|
|
||||||
* it should be enough for most uses.
|
|
||||||
*/
|
|
||||||
#ifndef FD_SETSIZE
|
#ifndef FD_SETSIZE
|
||||||
# define FD_SETSIZE 1024
|
# define FD_SETSIZE 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef __haiku_uint32 fd_mask;
|
typedef __haiku_uint32 fd_mask;
|
||||||
|
|
||||||
#define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */
|
#define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */
|
||||||
|
|
||||||
typedef struct fd_set {
|
typedef struct fd_set {
|
||||||
fd_mask bits[((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS)];
|
fd_mask bits[((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS)];
|
||||||
@@ -35,17 +30,12 @@ typedef struct fd_set {
|
|||||||
#define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
|
#define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
|
||||||
#define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
|
#define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
|
||||||
|
|
||||||
/* FD_ZERO uses memset */
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
|
#define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
|
||||||
#define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
|
#define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
|
||||||
#define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
|
#define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
|
||||||
#define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
|
#define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
|
||||||
#define FD_COPY(source, target) (*(target) = *(source))
|
#define FD_COPY(source, target) (*(target) = *(source))
|
||||||
|
|
||||||
#endif /* FD_SET */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -60,4 +50,5 @@ extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* _SYS_SELECT_H */
|
#endif /* _SYS_SELECT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user