mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-06 07:34:03 -04:00
tools/nolibc/types: move the FD_* functions to macros in types.h
FD_SET, FD_CLR, FD_ISSET, FD_ZERO are often expected to be macros and not functions. In addition we already have a file dedicated to such macros and types used by syscalls, it's types.h, so let's move them there and turn them to macros. FD_CLR() and FD_ISSET() were missing, so they were added. FD_ZERO() now deals with its own loop so that it doesn't rely on memset() that sets one byte at a time. Cc: David Laight <David.Laight@aculab.com> Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
committed by
Paul E. McKenney
parent
50850c38b2
commit
8cb98b3fce
@@ -118,20 +118,6 @@ const char *ltoa(long in)
|
||||
|
||||
/* Here come a few helper functions */
|
||||
|
||||
static __attribute__((unused))
|
||||
void FD_ZERO(fd_set *set)
|
||||
{
|
||||
memset(set, 0, sizeof(*set));
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
void FD_SET(int fd, fd_set *set)
|
||||
{
|
||||
if (fd < 0 || fd >= FD_SETSIZE)
|
||||
return;
|
||||
set->fd32[fd / 32] |= 1 << (fd & 31);
|
||||
}
|
||||
|
||||
/* WARNING, it only deals with the 4096 first majors and 256 first minors */
|
||||
static __attribute__((unused))
|
||||
dev_t makedev(unsigned int major, unsigned int minor)
|
||||
|
||||
@@ -75,6 +75,36 @@ typedef struct {
|
||||
uint32_t fd32[FD_SETSIZE / 32];
|
||||
} fd_set;
|
||||
|
||||
#define FD_CLR(fd, set) do { \
|
||||
fd_set *__set = (set); \
|
||||
int __fd = (fd); \
|
||||
if (__fd >= 0) \
|
||||
__set->fd32[__fd / 32] &= ~(1U << (__fd & 31)); \
|
||||
} while (0)
|
||||
|
||||
#define FD_SET(fd, set) do { \
|
||||
fd_set *__set = (set); \
|
||||
int __fd = (fd); \
|
||||
if (__fd >= 0) \
|
||||
__set->fd32[__fd / 32] |= 1U << (__fd & 31); \
|
||||
} while (0)
|
||||
|
||||
#define FD_ISSET(fd, set) ({ \
|
||||
fd_set *__set = (set); \
|
||||
int __fd = (fd); \
|
||||
int __r = 0; \
|
||||
if (__fd >= 0) \
|
||||
__r = !!(__set->fd32[__fd / 32] & 1U << (__fd & 31)); \
|
||||
__r; \
|
||||
})
|
||||
|
||||
#define FD_ZERO(set) do { \
|
||||
fd_set *__set = (set); \
|
||||
int __idx; \
|
||||
for (__idx = 0; __idx < FD_SETSIZE / 32; __idx ++) \
|
||||
__set->fd32[__idx] = 0; \
|
||||
} while (0)
|
||||
|
||||
/* for poll() */
|
||||
struct pollfd {
|
||||
int fd;
|
||||
|
||||
Reference in New Issue
Block a user