split out timeval to reduce namespace pollution

This commit is contained in:
auronandace
2026-05-04 15:05:30 +01:00
parent 4bff41fe78
commit 2dd36566de
5 changed files with 48 additions and 22 deletions
+20
View File
@@ -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 <bits/time-t.h>
#include <bits/suseconds-t.h>
"""
include_guard = "_RELIBC_BITS_TIMEVAL_H"
language = "C"
style = "Tag"
no_includes = true
cpp_compat = true
[enum]
prefix_with_name = true
+15
View File
@@ -0,0 +1,15 @@
use crate::platform::types::{suseconds_t, time_t};
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_select.h.html>.
///
/// 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
/// <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_time.h.html>.
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Default)]
pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: suseconds_t,
}
+1
View File
@@ -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;
+6 -5
View File
@@ -5,11 +5,15 @@
# - "The <sys/select.h> header shall define the sigset_t type as described in <signal.h>."
# - "The <sys/select.h> header shall define the timespec structure as described in <time.h>."
# - "Inclusion of the <sys/select.h> header may make visible all symbols from the headers <signal.h> and <time.h>."
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 <bits/sigset-t.h> // for sigset_t from signal.h
#include <bits/timespec.h> // for timespec from time.h
#include <bits/timeval.h> // 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"
+6 -17
View File
@@ -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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_select.h.html>.
///
/// 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
/// <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_time.h.html>.
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_select.h.html>.
/// cbindgen:ignore
pub const FD_SETSIZE: usize = 1024;
type FdBitSet = BitSet<[u64; FD_SETSIZE / (8 * mem::size_of::<u64>())]>;
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_select.h.html>.
/// cbindgen:ignore
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct fd_set {
pub fds_bits: FdBitSet,