From 3569d43b501f73862d2fb18fa5e6d023aa5fa750 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Thu, 7 Apr 2022 12:07:46 +0100 Subject: [PATCH] espidf: fix stat * corect type usage with new type definitions in libc --- library/std/src/os/unix/process.rs | 24 ++++++++++++------------ library/std/src/sys/unix/fd.rs | 19 +++++++++++++++++-- library/std/src/sys/unix/fs.rs | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index d95bc9b15c9..9a6778c0e86 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -24,8 +24,8 @@ pub trait CommandExt: Sealed { #[stable(feature = "rust1", since = "1.0.0")] fn uid( &mut self, - #[cfg(not(target_os = "vxworks"))] id: u32, - #[cfg(target_os = "vxworks")] id: u16, + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, ) -> &mut process::Command; /// Similar to `uid`, but sets the group ID of the child process. This has @@ -33,8 +33,8 @@ fn uid( #[stable(feature = "rust1", since = "1.0.0")] fn gid( &mut self, - #[cfg(not(target_os = "vxworks"))] id: u32, - #[cfg(target_os = "vxworks")] id: u16, + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, ) -> &mut process::Command; /// Sets the supplementary group IDs for the calling process. Translates to @@ -42,8 +42,8 @@ fn gid( #[unstable(feature = "setgroups", issue = "90747")] fn groups( &mut self, - #[cfg(not(target_os = "vxworks"))] groups: &[u32], - #[cfg(target_os = "vxworks")] groups: &[u16], + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32], + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16], ) -> &mut process::Command; /// Schedules a closure to be run just before the `exec` function is @@ -160,8 +160,8 @@ fn arg0(&mut self, arg: S) -> &mut process::Command impl CommandExt for process::Command { fn uid( &mut self, - #[cfg(not(target_os = "vxworks"))] id: u32, - #[cfg(target_os = "vxworks")] id: u16, + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, ) -> &mut process::Command { self.as_inner_mut().uid(id); self @@ -169,8 +169,8 @@ fn uid( fn gid( &mut self, - #[cfg(not(target_os = "vxworks"))] id: u32, - #[cfg(target_os = "vxworks")] id: u16, + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, ) -> &mut process::Command { self.as_inner_mut().gid(id); self @@ -178,8 +178,8 @@ fn gid( fn groups( &mut self, - #[cfg(not(target_os = "vxworks"))] groups: &[u32], - #[cfg(target_os = "vxworks")] groups: &[u16], + #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32], + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16], ) -> &mut process::Command { self.as_inner_mut().groups(groups); self diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 3de7c68a686..40a64585802 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -11,6 +11,21 @@ use libc::{c_int, c_void}; +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "emscripten", + target_os = "l4re" +))] +use libc::off64_t; +#[cfg(not(any( + target_os = "linux", + target_os = "emscripten", + target_os = "l4re", + target_os = "android" +)))] +use libc::off_t as off64_t; + #[derive(Debug)] pub struct FileDesc(OwnedFd); @@ -109,7 +124,7 @@ pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.as_raw_fd(), buf.as_mut_ptr() as *mut c_void, cmp::min(buf.len(), READ_LIMIT), - offset as i64, + offset as off64_t, )) .map(|n| n as usize) } @@ -176,7 +191,7 @@ pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { self.as_raw_fd(), buf.as_ptr() as *const c_void, cmp::min(buf.len(), READ_LIMIT), - offset as i64, + offset as off64_t, )) .map(|n| n as usize) } diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 7181451de57..a5732f3e946 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -966,7 +966,7 @@ pub fn seek(&self, pos: SeekFrom) -> io::Result { SeekFrom::End(off) => (libc::SEEK_END, off), SeekFrom::Current(off) => (libc::SEEK_CUR, off), }; - let n = cvt(unsafe { lseek64(self.as_raw_fd(), pos, whence) })?; + let n = cvt(unsafe { lseek64(self.as_raw_fd(), pos as off64_t, whence) })?; Ok(n as u64) }