From 8c448c490638c236f2c1b98f57a12611e98f5c09 Mon Sep 17 00:00:00 2001 From: Xing Xue Date: Fri, 17 Oct 2025 14:20:22 -0400 Subject: [PATCH] Declare field 'tv_nsec' of structure 'timespec' as 'i32' in both 32-bit and 64-bit modes for AIX. --- libc-test/build.rs | 6 ++++++ src/unix/aix/mod.rs | 9 +++++++++ src/unix/mod.rs | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 640c9dd31664f..b1ed4bebbbce3 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -5587,6 +5587,12 @@ fn test_aix(target: &str) { // The field 'data' is actually a unnamed union in the AIX header. "pollfd_ext" if field.ident() == "data" => true, + // On AIX, declares 'tv_nsec' as 'long', but the + // underlying system calls return a 32-bit value in both 32-bit + // and 64-bit modes. In the 'libc' crate it is declared as 'i32' + // to match the system call. Skip this field. + "timespec" if field.ident() == "tv_nsec" => true, + _ => false, } }); diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 7e3c8289c475a..b886e555c4e6c 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -264,6 +264,15 @@ s! { pub tv_nsec: c_int, } + // On AIX, declares 'tv_nsec' as 'long', but the underlying + // system calls return a 4-byte value in both 32-bit and 64-bit modes. + // It is declared as 'c_int' here to avoid using the other undefined 4 + // bytes in the 64-bit mode. + pub struct timespec { + pub tv_sec: time_t, + pub tv_nsec: c_int, + } + pub struct statfs64 { pub f_version: c_int, pub f_type: c_int, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 2a0fd17a163d3..7b66aa46baf3e 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -68,7 +68,7 @@ s! { // linux x32 compatibility // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437 - #[cfg(not(target_env = "gnu"))] + #[cfg(all(not(target_env = "gnu"), not(target_os = "aix")))] pub struct timespec { pub tv_sec: time_t, #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]