From 8d2bcee829e3b5c940e679f03a10aa0858cba2b4 Mon Sep 17 00:00:00 2001 From: auronandace Date: Sun, 3 May 2026 08:30:35 +0100 Subject: [PATCH] split out time_t to prepare for reducing namespace pollution --- src/header/bits_time-t/cbindgen.toml | 21 +++++++++++++++++++++ src/header/bits_time-t/mod.rs | 5 +++++ src/header/mod.rs | 2 ++ src/header/sys_types_internal/cbindgen.toml | 2 +- src/header/sys_types_internal/mod.rs | 3 +-- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/header/bits_time-t/cbindgen.toml create mode 100644 src/header/bits_time-t/mod.rs diff --git a/src/header/bits_time-t/cbindgen.toml b/src/header/bits_time-t/cbindgen.toml new file mode 100644 index 0000000000..ff20f95abe --- /dev/null +++ b/src/header/bits_time-t/cbindgen.toml @@ -0,0 +1,21 @@ +# 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 time_t: +# - sched.h +# - sys/select.h +# - sys/stat.h +# - sys/time.h +# - sys/types.h (where it should be defined) +# - time.h +sys_includes = [] +include_guard = "_RELIBC_BITS_TIME_T_H" +language = "C" +style = "type" +no_includes = true +cpp_compat = true +[export] +include = ["time_t"] +[enum] +prefix_with_name = true diff --git a/src/header/bits_time-t/mod.rs b/src/header/bits_time-t/mod.rs new file mode 100644 index 0000000000..d132055aa5 --- /dev/null +++ b/src/header/bits_time-t/mod.rs @@ -0,0 +1,5 @@ +use crate::platform::types::c_longlong; + +/// Used for time in seconds. +#[allow(non_camel_case_types)] +pub type time_t = c_longlong; diff --git a/src/header/mod.rs b/src/header/mod.rs index 1f0e6f03b6..f3aa9e72cb 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_time-t/mod.rs"] +pub mod bits_time_t; pub mod bits_timespec; // complex.h implemented in C pub mod cpio; diff --git a/src/header/sys_types_internal/cbindgen.toml b/src/header/sys_types_internal/cbindgen.toml index 9bf86018ec..b966ba298e 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 typedef void* timer_t; """ @@ -23,7 +24,6 @@ include = [ "pid_t", "id_t", "ssize_t", - "time_t", "useconds_t", "suseconds_t", "clock_t", diff --git a/src/header/sys_types_internal/mod.rs b/src/header/sys_types_internal/mod.rs index c433558716..2367b95ae0 100644 --- a/src/header/sys_types_internal/mod.rs +++ b/src/header/sys_types_internal/mod.rs @@ -10,6 +10,7 @@ use crate::platform::types::{ c_char, c_int, c_long, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, }; +pub use crate::header::bits_time_t::time_t; /// Used for block sizes. pub type blksize_t = c_long; @@ -39,8 +40,6 @@ pub type pid_t = c_int; pub type id_t = c_uint; /// Used for a count of bytes or an error indication. pub type ssize_t = c_long; -/// Used for time in seconds. -pub type time_t = c_longlong; pub type useconds_t = c_uint; #[cfg(target_os = "linux")]