Skip to content

Commit 2217abe

Browse files
committed
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 <[email protected]> Acked-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0f97135 commit 2217abe

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

tools/include/nolibc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ all_files := \
4444
std.h \
4545
stdarg.h \
4646
stdbool.h \
47+
stddef.h \
4748
stdint.h \
4849
stdlib.h \
4950
string.h \

tools/include/nolibc/std.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
* syscall-specific stuff, as this file is expected to be included very early.
1414
*/
1515

16-
/* note: may already be defined */
17-
#ifndef NULL
18-
#define NULL ((void *)0)
19-
#endif
20-
2116
#include "stdint.h"
17+
#include "stddef.h"
2218

2319
/* those are commonly provided by sys/types.h */
2420
typedef unsigned int dev_t;

tools/include/nolibc/stddef.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2+
/*
3+
* Stddef definitions for NOLIBC
4+
* Copyright (C) 2017-2021 Willy Tarreau <[email protected]>
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 */

tools/include/nolibc/types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ struct stat {
188188
typedef __kernel_clockid_t clockid_t;
189189
typedef int timer_t;
190190

191-
#ifndef offsetof
192-
#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
193-
#endif
194-
195191
#ifndef container_of
196192
#define container_of(PTR, TYPE, FIELD) ({ \
197193
__typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \

0 commit comments

Comments
 (0)