From 4f5d535ebcf10a713c9fa5979375d472f32249ef Mon Sep 17 00:00:00 2001 From: auronandace Date: Tue, 2 Jun 2026 16:56:12 +0100 Subject: [PATCH] split out NULL from stddef header --- include/stddef.h | 3 +-- src/header/bits_null/cbindgen.toml | 11 +++++++++++ src/header/bits_null/mod.rs | 5 +++++ src/header/locale/cbindgen.toml | 2 +- src/header/mod.rs | 1 + src/header/time/cbindgen.toml | 5 +++-- 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/header/bits_null/cbindgen.toml create mode 100644 src/header/bits_null/mod.rs diff --git a/include/stddef.h b/include/stddef.h index 76cd08412f..08d83c43a8 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -14,8 +14,7 @@ #endif // _WCHAR_T #include - -#define NULL 0 +#include #ifndef __PTRDIFF_TYPE__ #define __PTRDIFF_TYPE__ long int diff --git a/src/header/bits_null/cbindgen.toml b/src/header/bits_null/cbindgen.toml new file mode 100644 index 0000000000..2dd16668fc --- /dev/null +++ b/src/header/bits_null/cbindgen.toml @@ -0,0 +1,11 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html +# +# This type is split out to prevent importing all of stddef.h into other headers. +# +# POSIX headers that require NULL (without the rest of stddef.h): +# - locale.h +# - stddef.h (where it should be defined) +# - time.h +include_guard = "_RELIBC_BITS_NULL_T_H" +language = "C" +no_includes = true diff --git a/src/header/bits_null/mod.rs b/src/header/bits_null/mod.rs new file mode 100644 index 0000000000..11660e5aa3 --- /dev/null +++ b/src/header/bits_null/mod.rs @@ -0,0 +1,5 @@ +use crate::platform::types::c_void; + +/// Null pointer constant. +#[expect(clippy::zero_ptr)] +pub const NULL: *mut c_void = 0 as *mut c_void; diff --git a/src/header/locale/cbindgen.toml b/src/header/locale/cbindgen.toml index f8e9cb6a83..f9a68f11a4 100644 --- a/src/header/locale/cbindgen.toml +++ b/src/header/locale/cbindgen.toml @@ -2,10 +2,10 @@ # # Spec quotations relating to includes: # - "The header shall define NULL (as described in ) and at least the following as macros:" -sys_includes = ["stddef.h"] include_guard = "_RELIBC_LOCALE_H" after_includes = """ #include // for locale_t +#include // for NULL from stddef.h """ language = "C" style = "Tag" diff --git a/src/header/mod.rs b/src/header/mod.rs index 6584bf126c..2d77aa9a1f 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -26,6 +26,7 @@ pub mod bits_locale_t; pub mod bits_mode_t; #[path = "bits_nlink-t/mod.rs"] pub mod bits_nlink_t; +pub mod bits_null; #[path = "bits_off-t/mod.rs"] pub mod bits_off_t; #[path = "bits_pid-t/mod.rs"] diff --git a/src/header/time/cbindgen.toml b/src/header/time/cbindgen.toml index e120841100..29b1507705 100644 --- a/src/header/time/cbindgen.toml +++ b/src/header/time/cbindgen.toml @@ -9,16 +9,17 @@ # - "NULL As described in ." # - "Inclusion of the header may make visible all symbols from the header." # -# stddef.h brings in size_t and NULL # bits/timespec.h brings in time_t # features.h included for deprecated annotations -sys_includes = ["stddef.h", "features.h"] +sys_includes = ["features.h"] include_guard = "_RELIBC_TIME_H" language = "C" style = "Tag" no_includes = true cpp_compat = true after_includes = """ +#include // for NULL from stddef.h +#include // for size_t from sys/types.h #include // for clock_t from sys/types.h #include // for clockid_t from sys/types.h #include // for pid_t from sys/types.h