From 1cd9d8769d19d9bc141a20d7c108b6016f472d68 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 4 May 2026 13:38:33 +0100 Subject: [PATCH] split out suseconds_t for namespace pollution reduction preparation --- src/header/bits_suseconds-t/cbindgen.toml | 18 ++++++++++++++++++ src/header/bits_suseconds-t/mod.rs | 14 ++++++++++++++ src/header/mod.rs | 2 ++ src/header/sys_types_internal/cbindgen.toml | 2 +- src/header/sys_types_internal/mod.rs | 9 +-------- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/header/bits_suseconds-t/cbindgen.toml create mode 100644 src/header/bits_suseconds-t/mod.rs diff --git a/src/header/bits_suseconds-t/cbindgen.toml b/src/header/bits_suseconds-t/cbindgen.toml new file mode 100644 index 0000000000..462ae61a5f --- /dev/null +++ b/src/header/bits_suseconds-t/cbindgen.toml @@ -0,0 +1,18 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html +# +# This type is split out to prevent importing all of sys/types.h into other headers. +# +# POSIX headers that require suseconds_t: +# - sys/select.h +# - sys/time.h +# - sys/types.h (where it should be defined) +sys_includes = [] +include_guard = "_RELIBC_BITS_SUSECONDS_T_H" +language = "C" +style = "type" +no_includes = true +cpp_compat = true +[export] +include = ["suseconds_t"] +[enum] +prefix_with_name = true diff --git a/src/header/bits_suseconds-t/mod.rs b/src/header/bits_suseconds-t/mod.rs new file mode 100644 index 0000000000..38964981f3 --- /dev/null +++ b/src/header/bits_suseconds-t/mod.rs @@ -0,0 +1,14 @@ +#[cfg(target_os = "linux")] +use crate::platform::types::c_long; + +#[cfg(not(target_os = "linux"))] +use crate::platform::types::c_int; + +#[cfg(target_os = "linux")] +#[allow(non_camel_case_types)] +/// Used for time in microseconds. +pub type suseconds_t = c_long; +#[cfg(not(target_os = "linux"))] +#[allow(non_camel_case_types)] +/// Used for time in microseconds. +pub type suseconds_t = c_int; diff --git a/src/header/mod.rs b/src/header/mod.rs index f3aa9e72cb..af78014426 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -15,6 +15,8 @@ pub mod bits_safamily_t; pub mod bits_sigset_t; #[path = "bits_socklen-t/mod.rs"] pub mod bits_socklen_t; +#[path = "bits_suseconds-t/mod.rs"] +pub mod bits_suseconds_t; #[path = "bits_time-t/mod.rs"] pub mod bits_time_t; pub mod bits_timespec; diff --git a/src/header/sys_types_internal/cbindgen.toml b/src/header/sys_types_internal/cbindgen.toml index b966ba298e..41b3d0a724 100644 --- a/src/header/sys_types_internal/cbindgen.toml +++ b/src/header/sys_types_internal/cbindgen.toml @@ -1,6 +1,7 @@ sys_includes = ["stddef.h"] # TODO: figure out how to export void* type after_includes = """ +#include #include typedef void* timer_t; @@ -25,7 +26,6 @@ include = [ "id_t", "ssize_t", "useconds_t", - "suseconds_t", "clock_t", "clockid_t", "blkcnt_t", diff --git a/src/header/sys_types_internal/mod.rs b/src/header/sys_types_internal/mod.rs index 967164a101..bd8ab3be9c 100644 --- a/src/header/sys_types_internal/mod.rs +++ b/src/header/sys_types_internal/mod.rs @@ -7,7 +7,7 @@ //! //! for the old specification. -pub use crate::header::bits_time_t::time_t; +pub use crate::header::{bits_suseconds_t::suseconds_t, bits_time_t::time_t}; use crate::platform::types::{ c_char, c_int, c_long, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, }; @@ -42,13 +42,6 @@ pub type id_t = c_uint; pub type ssize_t = c_long; pub type useconds_t = c_uint; -#[cfg(target_os = "linux")] -/// Used for time in microseconds. -pub type suseconds_t = c_long; -#[cfg(not(target_os = "linux"))] -/// Used for time in microseconds. -pub type suseconds_t = c_int; - /// Used for system times in clock ticks or CLOCKS_PER_SEC. pub type clock_t = c_long; /// Used for clock ID type in the clock and timer functions.