From 2dd36566de31fbc2b6bf6cda4e81ff65035a2803 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 4 May 2026 15:05:30 +0100 Subject: [PATCH] split out timeval to reduce namespace pollution --- src/header/bits_timeval/cbindgen.toml | 20 ++++++++++++++++++++ src/header/bits_timeval/mod.rs | 15 +++++++++++++++ src/header/mod.rs | 1 + src/header/sys_select/cbindgen.toml | 11 ++++++----- src/header/sys_select/mod.rs | 23 ++++++----------------- 5 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 src/header/bits_timeval/cbindgen.toml create mode 100644 src/header/bits_timeval/mod.rs diff --git a/src/header/bits_timeval/cbindgen.toml b/src/header/bits_timeval/cbindgen.toml new file mode 100644 index 0000000000..1dcb1b8aad --- /dev/null +++ b/src/header/bits_timeval/cbindgen.toml @@ -0,0 +1,20 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_select.h.html +# +# This type is split out to prevent including all of sys/select.h in other headers. +# +# POSIX headers that require timeval: +# - sys/resource.h +# - sys/select.h (where it should be defined) +# - sys/time.h +after_includes = """ +#include +#include +""" +include_guard = "_RELIBC_BITS_TIMEVAL_H" +language = "C" +style = "Tag" +no_includes = true +cpp_compat = true + +[enum] +prefix_with_name = true diff --git a/src/header/bits_timeval/mod.rs b/src/header/bits_timeval/mod.rs new file mode 100644 index 0000000000..81cd4419a9 --- /dev/null +++ b/src/header/bits_timeval/mod.rs @@ -0,0 +1,15 @@ +use crate::platform::types::{suseconds_t, time_t}; + +/// See . +/// +/// Note that the `timeval` struct was specified for +/// [`sys/time.h`](crate::header::sys_time) in the Open Group Base +/// Specifications Issue 7 and prior, see +/// . +#[repr(C)] +#[allow(non_camel_case_types)] +#[derive(Default)] +pub struct timeval { + pub tv_sec: time_t, + pub tv_usec: suseconds_t, +} diff --git a/src/header/mod.rs b/src/header/mod.rs index af78014426..7f82b7915f 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -20,6 +20,7 @@ pub mod bits_suseconds_t; #[path = "bits_time-t/mod.rs"] pub mod bits_time_t; pub mod bits_timespec; +pub mod bits_timeval; // complex.h implemented in C pub mod cpio; pub mod crypt; diff --git a/src/header/sys_select/cbindgen.toml b/src/header/sys_select/cbindgen.toml index f89d7f7c09..67a366c344 100644 --- a/src/header/sys_select/cbindgen.toml +++ b/src/header/sys_select/cbindgen.toml @@ -5,11 +5,15 @@ # - "The header shall define the sigset_t type as described in ." # - "The header shall define the timespec structure as described in ." # - "Inclusion of the header may make visible all symbols from the headers and ." -sys_includes = ["sys/types.h"] +# +# bits/timeval.h brings in time_t and suseconds_t so no need to include all of sys/types.h. +sys_includes = [] include_guard = "_RELIBC_SYS_SELECT_H" +# FD_SETSIZE and fd_set is also defined in C (below) because cbindgen is incompatible with mem::size_of after_includes = """ #include // for sigset_t from signal.h #include // for timespec from time.h +#include // for timeval // from musl license MIT { #define FD_SETSIZE 1024 @@ -38,9 +42,6 @@ cpp_compat = true [enum] prefix_with_name = true -[export] -# fd_set is also defined in C (above) because cbindgen is incompatible with mem::size_of -exclude = ["FD_SETSIZE", "fd_set"] - [export.rename] "timespec" = "struct timespec" +"timeval" = "struct timeval" diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index 45e7a2381b..d79cb21cc6 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -15,32 +15,21 @@ use crate::{ epoll_data, epoll_event, epoll_wait, }, }, - platform::{ - self, - types::{c_int, suseconds_t, time_t}, - }, + platform::{self, types::c_int}, }; -/// See . -/// -/// Note that the `timeval` struct was specified for -/// [`sys/time.h`](crate::header::sys_time) in the Open Group Base -/// Specifications Issue 7 and prior, see -/// . -#[repr(C)] -#[derive(Default)] -pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, -} +pub use crate::header::bits_timeval::timeval; -// fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo +// FD_SETSIZE and fd_set is also defined in C because cbindgen is incompatible with mem::size_of /// See . +/// cbindgen:ignore pub const FD_SETSIZE: usize = 1024; type FdBitSet = BitSet<[u64; FD_SETSIZE / (8 * mem::size_of::())]>; /// See . +/// cbindgen:ignore +#[allow(non_camel_case_types)] #[repr(C)] pub struct fd_set { pub fds_bits: FdBitSet,