* [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates
@ 2025-11-02 10:46 Willy Tarreau
2025-11-02 10:46 ` [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Willy Tarreau @ 2025-11-02 10:46 UTC (permalink / raw)
To: linux; +Cc: shuah, linux-kernel, Willy Tarreau
Trying to port a program to nolibc triggered a few trivial errors that
are worth being addressed:
- inttypes.h is missing, while being generally recommended over stdint.h
for being more portable. Here we add it, which simply includes stdint.h.
- sys/select.h is supposed to be where struct fd_set and FD_CLR() etc
are defined. Till now it was still in types.h. Let's create the file
and move these definitions there.
- memchr() was still missing, thus a trivial one was added.
Finally the help message from "make help" reported an inaccurate
installation path, omitting the dependency on $OUTPUT. This was
fixed as well.
---
v2:
- rebase this old changeset onto latest updates from Thomas
- moved select() definition do sys/select.h as well and include
nolibc.h to avoid having just a dummy file like in v1
Willy Tarreau (4):
tools/nolibc: fix misleading help message regarding installation path
tools/nolibc: add the more portable inttypes.h
tools/nolibc: add missing memchr() to string.h
tools/nolibc: provide the portable sys/select.h
tools/include/nolibc/Makefile | 4 +-
tools/include/nolibc/inttypes.h | 8 ++
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/string.h | 15 +++
tools/include/nolibc/sys.h | 45 --------
tools/include/nolibc/sys/select.h | 103 +++++++++++++++++++
tools/include/nolibc/types.h | 47 ---------
tools/testing/selftests/nolibc/nolibc-test.c | 2 +
8 files changed, 132 insertions(+), 93 deletions(-)
create mode 100644 tools/include/nolibc/inttypes.h
create mode 100644 tools/include/nolibc/sys/select.h
--
2.17.5
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path 2025-11-02 10:46 [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau @ 2025-11-02 10:46 ` Willy Tarreau 2025-11-02 11:03 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h Willy Tarreau ` (2 subsequent siblings) 3 siblings, 1 reply; 11+ messages in thread From: Willy Tarreau @ 2025-11-02 10:46 UTC (permalink / raw) To: linux; +Cc: shuah, linux-kernel, Willy Tarreau The help message says the headers are going to be installed into tools/include/nolibc but this is only the default if $OUTPUT is not set, so better clarify this (the current value of $OUTPUT is already shown). Signed-off-by: Willy Tarreau <w@1wt.eu> --- tools/include/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 143c2d2c2ba6..4f617d91a5ff 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -79,7 +79,7 @@ help: @echo "Supported targets under nolibc:" @echo " all call \"headers\"" @echo " clean clean the sysroot" - @echo " headers prepare a sysroot in tools/include/nolibc/sysroot" + @echo " headers prepare a sysroot in \$${OUTPUT}sysroot" @echo " headers_standalone like \"headers\", and also install kernel headers" @echo " help this help" @echo "" -- 2.17.5 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path 2025-11-02 10:46 ` [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau @ 2025-11-02 11:03 ` Thomas Weißschuh 0 siblings, 0 replies; 11+ messages in thread From: Thomas Weißschuh @ 2025-11-02 11:03 UTC (permalink / raw) To: Willy Tarreau; +Cc: shuah, linux-kernel On 2025-11-02 11:46:08+0100, Willy Tarreau wrote: > The help message says the headers are going to be installed into > tools/include/nolibc but this is only the default if $OUTPUT is not set, > so better clarify this (the current value of $OUTPUT is already shown). > > Signed-off-by: Willy Tarreau <w@1wt.eu> Applied. ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h 2025-11-02 10:46 [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau 2025-11-02 10:46 ` [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau @ 2025-11-02 10:46 ` Willy Tarreau 2025-11-02 11:04 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h Willy Tarreau 2025-11-02 10:46 ` [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h Willy Tarreau 3 siblings, 1 reply; 11+ messages in thread From: Willy Tarreau @ 2025-11-02 10:46 UTC (permalink / raw) To: linux; +Cc: shuah, linux-kernel, Willy Tarreau It's often recommended to only use inttypes.h instead of stdint.h for portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when including inttypes.h. Let's add one that simply includes stdint.h to better support these programs. Signed-off-by: Willy Tarreau <w@1wt.eu> --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 4f617d91a5ff..0d312f1159ec 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -33,6 +33,7 @@ all_files := \ errno.h \ fcntl.h \ getopt.h \ + inttypes.h \ limits.h \ math.h \ nolibc.h \ diff --git a/tools/include/nolibc/inttypes.h b/tools/include/nolibc/inttypes.h new file mode 100644 index 000000000000..1088034ef7cc --- /dev/null +++ b/tools/include/nolibc/inttypes.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#ifndef _NOLIBC_INTTYPES_H +#define _NOLIBC_INTTYPES_H + +#include "stdint.h" + +#endif /* _NOLIBC_INTTYPES_H */ -- 2.17.5 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h 2025-11-02 10:46 ` [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h Willy Tarreau @ 2025-11-02 11:04 ` Thomas Weißschuh 2025-11-02 11:18 ` Willy Tarreau 0 siblings, 1 reply; 11+ messages in thread From: Thomas Weißschuh @ 2025-11-02 11:04 UTC (permalink / raw) To: Willy Tarreau; +Cc: shuah, linux-kernel On 2025-11-02 11:46:09+0100, Willy Tarreau wrote: > It's often recommended to only use inttypes.h instead of stdint.h for > portability reasons since the former is always present when the latter > is present, but not conversely, and the former includes the latter. Due > to this some simple programs fail to build when including inttypes.h. > Let's add one that simply includes stdint.h to better support these > programs. > > Signed-off-by: Willy Tarreau <w@1wt.eu> > --- > tools/include/nolibc/Makefile | 1 + > tools/include/nolibc/inttypes.h | 8 ++++++++ > 2 files changed, 9 insertions(+) > create mode 100644 tools/include/nolibc/inttypes.h I think this should also interact with the big nolibc.h. Both being included from it and including it itself, to follow the generally used pattern. Thomas ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h 2025-11-02 11:04 ` Thomas Weißschuh @ 2025-11-02 11:18 ` Willy Tarreau 2025-11-02 11:41 ` Thomas Weißschuh 0 siblings, 1 reply; 11+ messages in thread From: Willy Tarreau @ 2025-11-02 11:18 UTC (permalink / raw) To: Thomas Weißschuh; +Cc: shuah, linux-kernel On Sun, Nov 02, 2025 at 12:04:01PM +0100, Thomas Weißschuh wrote: > On 2025-11-02 11:46:09+0100, Willy Tarreau wrote: > > It's often recommended to only use inttypes.h instead of stdint.h for > > portability reasons since the former is always present when the latter > > is present, but not conversely, and the former includes the latter. Due > > to this some simple programs fail to build when including inttypes.h. > > Let's add one that simply includes stdint.h to better support these > > programs. > > > > Signed-off-by: Willy Tarreau <w@1wt.eu> > > --- > > tools/include/nolibc/Makefile | 1 + > > tools/include/nolibc/inttypes.h | 8 ++++++++ > > 2 files changed, 9 insertions(+) > > create mode 100644 tools/include/nolibc/inttypes.h > > I think this should also interact with the big nolibc.h. > Both being included from it and including it itself, to follow the > generally used pattern. > You mean you'd prefer "include nolibc.h" from inttypes and "include inttypes" from nolibc, that's it ? Willy ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h 2025-11-02 11:18 ` Willy Tarreau @ 2025-11-02 11:41 ` Thomas Weißschuh 0 siblings, 0 replies; 11+ messages in thread From: Thomas Weißschuh @ 2025-11-02 11:41 UTC (permalink / raw) To: Willy Tarreau; +Cc: shuah, linux-kernel Nov 2, 2025 12:18:57 Willy Tarreau <w@1wt.eu>: > On Sun, Nov 02, 2025 at 12:04:01PM +0100, Thomas Weißschuh wrote: >> On 2025-11-02 11:46:09+0100, Willy Tarreau wrote: >>> It's often recommended to only use inttypes.h instead of stdint.h for >>> portability reasons since the former is always present when the latter >>> is present, but not conversely, and the former includes the latter. Due >>> to this some simple programs fail to build when including inttypes.h. >>> Let's add one that simply includes stdint.h to better support these >>> programs. >>> >>> Signed-off-by: Willy Tarreau <w@1wt.eu> >>> --- >>> tools/include/nolibc/Makefile | 1 + >>> tools/include/nolibc/inttypes.h | 8 ++++++++ >>> 2 files changed, 9 insertions(+) >>> create mode 100644 tools/include/nolibc/inttypes.h >> >> I think this should also interact with the big nolibc.h. >> Both being included from it and including it itself, to follow the >> generally used pattern. >> > > You mean you'd prefer "include nolibc.h" from inttypes and > "include inttypes" from nolibc, that's it ? Yep. Thomas ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h 2025-11-02 10:46 [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau 2025-11-02 10:46 ` [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau 2025-11-02 10:46 ` [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h Willy Tarreau @ 2025-11-02 10:46 ` Willy Tarreau 2025-11-02 11:10 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h Willy Tarreau 3 siblings, 1 reply; 11+ messages in thread From: Willy Tarreau @ 2025-11-02 10:46 UTC (permalink / raw) To: linux; +Cc: shuah, linux-kernel, Willy Tarreau Surprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones. The test verifies that we don't search past the indicated length. Signed-off-by: Willy Tarreau <w@1wt.eu> --- tools/include/nolibc/string.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index 163a17e7dd38..4000926f44ac 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len) } #endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */ +#ifndef NOLIBC_ARCH_HAS_MEMCHR +static __attribute__((unused)) +void *memchr(const void *s, int c, size_t len) +{ + char *p = (char *)s; + + while (len--) { + if (*p == (char)c) + return p; + p++; + } + return NULL; +} +#endif /* #ifndef NOLIBC_ARCH_HAS_MEMCHR */ + static __attribute__((unused)) char *strchr(const char *s, int c) { diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 2b1fcfaaa60e..7fc937e9a4df 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1558,6 +1558,8 @@ int run_stdlib(int min, int max) CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break; CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break; CASE_TEST(test_timespec); EXPECT_ZR(1, test_timespec()); break; + CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o', 6), "oobar"); break; + CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b', 3)); break; case __LINE__: return ret; /* must be last */ -- 2.17.5 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h 2025-11-02 10:46 ` [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h Willy Tarreau @ 2025-11-02 11:10 ` Thomas Weißschuh 0 siblings, 0 replies; 11+ messages in thread From: Thomas Weißschuh @ 2025-11-02 11:10 UTC (permalink / raw) To: Willy Tarreau; +Cc: shuah, linux-kernel On 2025-11-02 11:46:10+0100, Willy Tarreau wrote: > Surprisingly we forgot to add this common one. It was added with a > per-arch guard allowing to later implement it in arch-specific asm > code like was done for a few other ones. > > The test verifies that we don't search past the indicated length. > > Signed-off-by: Willy Tarreau <w@1wt.eu> > --- > tools/include/nolibc/string.h | 15 +++++++++++++++ > tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ > 2 files changed, 17 insertions(+) Applied. ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h 2025-11-02 10:46 [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau ` (2 preceding siblings ...) 2025-11-02 10:46 ` [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h Willy Tarreau @ 2025-11-02 10:46 ` Willy Tarreau 2025-11-02 12:51 ` Thomas Weißschuh 3 siblings, 1 reply; 11+ messages in thread From: Willy Tarreau @ 2025-11-02 10:46 UTC (permalink / raw) To: linux; +Cc: shuah, linux-kernel, Willy Tarreau Modern programs tend to include sys/select.h to get FD_SET() and FD_CLR() definitions as well as struct fd_set, but in our case it didn't exist. The definitions were moved from types.h to sys/select.h, which is now included from nolibc.h, and the sys_select() definition moved there as well from sys.h. Signed-off-by: Willy Tarreau <w@1wt.eu> --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys.h | 45 ------------- tools/include/nolibc/sys/select.h | 103 ++++++++++++++++++++++++++++++ tools/include/nolibc/types.h | 47 -------------- 5 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 tools/include/nolibc/sys/select.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 0d312f1159ec..ff0e646acda9 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -57,6 +57,7 @@ all_files := \ sys/random.h \ sys/reboot.h \ sys/resource.h \ + sys/select.h \ sys/stat.h \ sys/syscall.h \ sys/sysmacros.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index d2f5aa085f8e..91e2795ae49c 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -104,6 +104,7 @@ #include "sys/random.h" #include "sys/reboot.h" #include "sys/resource.h" +#include "sys/select.h" #include "sys/stat.h" #include "sys/syscall.h" #include "sys/sysmacros.h" diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index aeb57bb68e92..dc8a83c716ab 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -752,51 +752,6 @@ int sched_yield(void) } -/* - * int select(int nfds, fd_set *read_fds, fd_set *write_fds, - * fd_set *except_fds, struct timeval *timeout); - */ - -static __attribute__((unused)) -int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) -{ -#if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect) - struct sel_arg_struct { - unsigned long n; - fd_set *r, *w, *e; - struct timeval *t; - } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; - return my_syscall1(__NR_select, &arg); -#elif defined(__NR__newselect) - return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout); -#elif defined(__NR_select) - return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout); -#elif defined(__NR_pselect6_time64) - struct __kernel_timespec t; - - if (timeout) { - t.tv_sec = timeout->tv_sec; - t.tv_nsec = timeout->tv_usec * 1000; - } - return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); -#else - struct timespec t; - - if (timeout) { - t.tv_sec = timeout->tv_sec; - t.tv_nsec = timeout->tv_usec * 1000; - } - return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); -#endif -} - -static __attribute__((unused)) -int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) -{ - return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); -} - - /* * int setpgid(pid_t pid, pid_t pgid); */ diff --git a/tools/include/nolibc/sys/select.h b/tools/include/nolibc/sys/select.h new file mode 100644 index 000000000000..71cdadde32b5 --- /dev/null +++ b/tools/include/nolibc/sys/select.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_SELECT_H +#define _NOLIBC_SYS_SELECT_H + +#include <linux/time.h> +#include <linux/unistd.h> + +/* commonly an fd_set represents 256 FDs */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 256 +#endif + +#define FD_SETIDXMASK (8 * sizeof(unsigned long)) +#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) + +/* for select() */ +typedef struct { + unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; +} fd_set; + +#define FD_CLR(fd, set) do { \ + fd_set *__set = (set); \ + int __fd = (fd); \ + if (__fd >= 0) \ + __set->fds[__fd / FD_SETIDXMASK] &= \ + ~(1U << (__fd & FD_SETBITMASK)); \ + } while (0) + +#define FD_SET(fd, set) do { \ + fd_set *__set = (set); \ + int __fd = (fd); \ + if (__fd >= 0) \ + __set->fds[__fd / FD_SETIDXMASK] |= \ + 1 << (__fd & FD_SETBITMASK); \ + } while (0) + +#define FD_ISSET(fd, set) ({ \ + fd_set *__set = (set); \ + int __fd = (fd); \ + int __r = 0; \ + if (__fd >= 0) \ + __r = !!(__set->fds[__fd / FD_SETIDXMASK] & \ +1U << (__fd & FD_SETBITMASK)); \ + __r; \ + }) + +#define FD_ZERO(set) do { \ + fd_set *__set = (set); \ + int __idx; \ + int __size = (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ + for (__idx = 0; __idx < __size; __idx++) \ + __set->fds[__idx] = 0; \ + } while (0) + +/* + * int select(int nfds, fd_set *read_fds, fd_set *write_fds, + * fd_set *except_fds, struct timeval *timeout); + */ + +static __attribute__((unused)) +int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) +{ +#if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect) + struct sel_arg_struct { + unsigned long n; + fd_set *r, *w, *e; + struct timeval *t; + } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; + return my_syscall1(__NR_select, &arg); +#elif defined(__NR__newselect) + return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout); +#elif defined(__NR_select) + return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout); +#elif defined(__NR_pselect6_time64) + struct __kernel_timespec t; + + if (timeout) { + t.tv_sec = timeout->tv_sec; + t.tv_nsec = timeout->tv_usec * 1000; + } + return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); +#else + struct timespec t; + + if (timeout) { + t.tv_sec = timeout->tv_sec; + t.tv_nsec = timeout->tv_usec * 1000; + } + return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); +#endif +} + +static __attribute__((unused)) +int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) +{ + return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); +} + + +#endif /* _NOLIBC_SYS_SELECT_H */ diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 3b086f68b2be..e2216d1e2c3f 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -77,11 +77,6 @@ struct timespec { #define DT_LNK 0xa #define DT_SOCK 0xc -/* commonly an fd_set represents 256 FDs */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 256 -#endif - /* PATH_MAX and MAXPATHLEN are often used and found with plenty of different * values. */ @@ -122,48 +117,6 @@ struct timespec { #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 -#define FD_SETIDXMASK (8 * sizeof(unsigned long)) -#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) - -/* for select() */ -typedef struct { - unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; -} fd_set; - -#define FD_CLR(fd, set) do { \ - fd_set *__set = (set); \ - int __fd = (fd); \ - if (__fd >= 0) \ - __set->fds[__fd / FD_SETIDXMASK] &= \ - ~(1U << (__fd & FD_SETBITMASK)); \ - } while (0) - -#define FD_SET(fd, set) do { \ - fd_set *__set = (set); \ - int __fd = (fd); \ - if (__fd >= 0) \ - __set->fds[__fd / FD_SETIDXMASK] |= \ - 1 << (__fd & FD_SETBITMASK); \ - } while (0) - -#define FD_ISSET(fd, set) ({ \ - fd_set *__set = (set); \ - int __fd = (fd); \ - int __r = 0; \ - if (__fd >= 0) \ - __r = !!(__set->fds[__fd / FD_SETIDXMASK] & \ -1U << (__fd & FD_SETBITMASK)); \ - __r; \ - }) - -#define FD_ZERO(set) do { \ - fd_set *__set = (set); \ - int __idx; \ - int __size = (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ - for (__idx = 0; __idx < __size; __idx++) \ - __set->fds[__idx] = 0; \ - } while (0) - /* for getdents64() */ struct linux_dirent64 { uint64_t d_ino; -- 2.17.5 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h 2025-11-02 10:46 ` [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h Willy Tarreau @ 2025-11-02 12:51 ` Thomas Weißschuh 0 siblings, 0 replies; 11+ messages in thread From: Thomas Weißschuh @ 2025-11-02 12:51 UTC (permalink / raw) To: Willy Tarreau; +Cc: shuah, linux-kernel On 2025-11-02 11:46:11+0100, Willy Tarreau wrote: > Modern programs tend to include sys/select.h to get FD_SET() and > FD_CLR() definitions as well as struct fd_set, but in our case it > didn't exist. > > The definitions were moved from types.h to sys/select.h, which is > now included from nolibc.h, and the sys_select() definition moved > there as well from sys.h. > > Signed-off-by: Willy Tarreau <w@1wt.eu> > --- > tools/include/nolibc/Makefile | 1 + > tools/include/nolibc/nolibc.h | 1 + > tools/include/nolibc/sys.h | 45 ------------- > tools/include/nolibc/sys/select.h | 103 ++++++++++++++++++++++++++++++ > tools/include/nolibc/types.h | 47 -------------- > 5 files changed, 105 insertions(+), 92 deletions(-) > create mode 100644 tools/include/nolibc/sys/select.h Applied. ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-11-02 12:51 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-02 10:46 [PATCH v2 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau 2025-11-02 10:46 ` [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau 2025-11-02 11:03 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h Willy Tarreau 2025-11-02 11:04 ` Thomas Weißschuh 2025-11-02 11:18 ` Willy Tarreau 2025-11-02 11:41 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h Willy Tarreau 2025-11-02 11:10 ` Thomas Weißschuh 2025-11-02 10:46 ` [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h Willy Tarreau 2025-11-02 12:51 ` Thomas Weißschuh
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.