From d14ae1c148c3cf40068239f6e9ac264d1fd46065 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sat, 16 Aug 2025 23:52:03 -0400 Subject: [PATCH] Switch resource.h enum to c_int instead of u64 Most platforms use a c_int though glibc uses a u32. GNU defines a type, __rlimit_resource_t, for the RLIMIT enum that is a u32. Using a c_int is nicer for a few reasons. The first is that our (unimplemented) functions receive a c_int for the enum - using a u32 is technically wrong but doesn't affect anything since the constants are turned into macros by cbindgen. The second reason is that a c_int is nicer for libc and nix (the crate) too since we don't need to pollute the crates with guards for Redox. --- src/header/sys_resource/mod.rs | 32 ++++++++++++++++---------------- tests/sys_resource/constants.c | 14 +++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 4e54febacb..bc1cc1167b 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -17,22 +17,22 @@ pub const RLIM_INFINITY: u64 = 0xFFFF_FFFF_FFFF_FFFF; pub const RLIM_SAVED_CUR: u64 = RLIM_INFINITY; pub const RLIM_SAVED_MAX: u64 = RLIM_INFINITY; -pub const RLIMIT_CPU: u64 = 0; -pub const RLIMIT_FSIZE: u64 = 1; -pub const RLIMIT_DATA: u64 = 2; -pub const RLIMIT_STACK: u64 = 3; -pub const RLIMIT_CORE: u64 = 4; -pub const RLIMIT_RSS: u64 = 5; -pub const RLIMIT_NPROC: u64 = 6; -pub const RLIMIT_NOFILE: u64 = 7; -pub const RLIMIT_MEMLOCK: u64 = 8; -pub const RLIMIT_AS: u64 = 9; -pub const RLIMIT_LOCKS: u64 = 10; -pub const RLIMIT_SIGPENDING: u64 = 11; -pub const RLIMIT_MSGQUEUE: u64 = 12; -pub const RLIMIT_NICE: u64 = 13; -pub const RLIMIT_RTPRIO: u64 = 14; -pub const RLIMIT_NLIMITS: u64 = 15; +pub const RLIMIT_CPU: c_int = 0; +pub const RLIMIT_FSIZE: c_int = 1; +pub const RLIMIT_DATA: c_int = 2; +pub const RLIMIT_STACK: c_int = 3; +pub const RLIMIT_CORE: c_int = 4; +pub const RLIMIT_RSS: c_int = 5; +pub const RLIMIT_NPROC: c_int = 6; +pub const RLIMIT_NOFILE: c_int = 7; +pub const RLIMIT_MEMLOCK: c_int = 8; +pub const RLIMIT_AS: c_int = 9; +pub const RLIMIT_LOCKS: c_int = 10; +pub const RLIMIT_SIGPENDING: c_int = 11; +pub const RLIMIT_MSGQUEUE: c_int = 12; +pub const RLIMIT_NICE: c_int = 13; +pub const RLIMIT_RTPRIO: c_int = 14; +pub const RLIMIT_NLIMITS: c_int = 15; pub type rlim_t = u64; diff --git a/tests/sys_resource/constants.c b/tests/sys_resource/constants.c index 3513ac8008..7a93b7f4d5 100644 --- a/tests/sys_resource/constants.c +++ b/tests/sys_resource/constants.c @@ -15,13 +15,13 @@ int main(void) { printf("RUSAGE_SELF: %lld\n", RUSAGE_SELF); printf("RUSAGE_CHILDREN: %lld\n", RUSAGE_CHILDREN); - printf("RLIMIT_CORE: %lld\n", RLIMIT_CORE); - printf("RLIMIT_CPU: %lld\n", RLIMIT_CPU); - printf("RLIMIT_DATA: %lld\n", RLIMIT_DATA); - printf("RLIMIT_FSIZE: %lld\n", RLIMIT_FSIZE); - printf("RLIMIT_NOFILE: %lld\n", RLIMIT_NOFILE); - printf("RLIMIT_STACK: %lld\n", RLIMIT_STACK); - printf("RLIMIT_AS: %lld\n", RLIMIT_AS); + printf("RLIMIT_CORE: %d\n", RLIMIT_CORE); + printf("RLIMIT_CPU: %d\n", RLIMIT_CPU); + printf("RLIMIT_DATA: %d\n", RLIMIT_DATA); + printf("RLIMIT_FSIZE: %d\n", RLIMIT_FSIZE); + printf("RLIMIT_NOFILE: %d\n", RLIMIT_NOFILE); + printf("RLIMIT_STACK: %d\n", RLIMIT_STACK); + printf("RLIMIT_AS: %d\n", RLIMIT_AS); return 0; }