Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/nolibc: move NULL and offsetof() to sys/stddef.h

This is the location regular userspace expects these definitions.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250515-nolibc-sys-v1-8-74f82eea3b59@weissschuh.net

+26 -9
+1
tools/include/nolibc/Makefile
··· 44 44 std.h \ 45 45 stdarg.h \ 46 46 stdbool.h \ 47 + stddef.h \ 47 48 stdint.h \ 48 49 stdlib.h \ 49 50 string.h \
+1 -5
tools/include/nolibc/std.h
··· 13 13 * syscall-specific stuff, as this file is expected to be included very early. 14 14 */ 15 15 16 - /* note: may already be defined */ 17 - #ifndef NULL 18 - #define NULL ((void *)0) 19 - #endif 20 - 21 16 #include "stdint.h" 17 + #include "stddef.h" 22 18 23 19 /* those are commonly provided by sys/types.h */ 24 20 typedef unsigned int dev_t;
+24
tools/include/nolibc/stddef.h
··· 1 + /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ 2 + /* 3 + * Stddef definitions for NOLIBC 4 + * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu> 5 + */ 6 + 7 + /* make sure to include all global symbols */ 8 + #include "nolibc.h" 9 + 10 + #ifndef _NOLIBC_STDDEF_H 11 + #define _NOLIBC_STDDEF_H 12 + 13 + #include "stdint.h" 14 + 15 + /* note: may already be defined */ 16 + #ifndef NULL 17 + #define NULL ((void *)0) 18 + #endif 19 + 20 + #ifndef offsetof 21 + #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) 22 + #endif 23 + 24 + #endif /* _NOLIBC_STDDEF_H */
-4
tools/include/nolibc/types.h
··· 188 188 typedef __kernel_clockid_t clockid_t; 189 189 typedef int timer_t; 190 190 191 - #ifndef offsetof 192 - #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) 193 - #endif 194 - 195 191 #ifndef container_of 196 192 #define container_of(PTR, TYPE, FIELD) ({ \ 197 193 __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \