]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tools/nolibc: move NULL and offsetof() to sys/stddef.h
authorThomas Weißschuh <linux@weissschuh.net>
Thu, 15 May 2025 19:57:54 +0000 (21:57 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Wed, 21 May 2025 13:32:25 +0000 (15:32 +0200)
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
tools/include/nolibc/Makefile
tools/include/nolibc/std.h
tools/include/nolibc/stddef.h [new file with mode: 0644]
tools/include/nolibc/types.h

index 7546c359e282afcde9706524ba292f2d83ed1876..c335ce0bd195c1ec63b9b23c0143307acfd3d3c8 100644 (file)
@@ -44,6 +44,7 @@ all_files := \
                std.h \
                stdarg.h \
                stdbool.h \
+               stddef.h \
                stdint.h \
                stdlib.h \
                string.h \
index 933bc0be7e1c6be3b7909efc127f1d3b9c611135..adda7333d12e7d2c336938ede1aaf215b4b93165 100644 (file)
  * syscall-specific stuff, as this file is expected to be included very early.
  */
 
-/* note: may already be defined */
-#ifndef NULL
-#define NULL ((void *)0)
-#endif
-
 #include "stdint.h"
+#include "stddef.h"
 
 /* those are commonly provided by sys/types.h */
 typedef unsigned int          dev_t;
diff --git a/tools/include/nolibc/stddef.h b/tools/include/nolibc/stddef.h
new file mode 100644 (file)
index 0000000..ecbd13e
--- /dev/null
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * Stddef definitions for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+/* make sure to include all global symbols */
+#include "nolibc.h"
+
+#ifndef _NOLIBC_STDDEF_H
+#define _NOLIBC_STDDEF_H
+
+#include "stdint.h"
+
+/* note: may already be defined */
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#ifndef offsetof
+#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
+#endif
+
+#endif /* _NOLIBC_STDDEF_H */
index 0071bfbc23154cf9b47b0bd747101fea4955018d..30904be544ed01b212042ebc0f4dab610f64b216 100644 (file)
@@ -188,10 +188,6 @@ struct stat {
 typedef __kernel_clockid_t clockid_t;
 typedef int timer_t;
 
-#ifndef offsetof
-#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
-#endif
-
 #ifndef container_of
 #define container_of(PTR, TYPE, FIELD) ({                      \
        __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR);    \