espidf: fix stat

* corect type usage with new type definitions in libc
This commit is contained in:
Scott Mabin 2022-04-07 12:07:46 +01:00
parent f565016edd
commit 3569d43b50
3 changed files with 30 additions and 15 deletions

View file

@ -24,8 +24,8 @@ pub trait CommandExt: Sealed {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn uid( fn uid(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] id: u32, #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(target_os = "vxworks")] id: u16, #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
) -> &mut process::Command; ) -> &mut process::Command;
/// Similar to `uid`, but sets the group ID of the child process. This has /// Similar to `uid`, but sets the group ID of the child process. This has
@ -33,8 +33,8 @@ pub trait CommandExt: Sealed {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn gid( fn gid(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] id: u32, #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(target_os = "vxworks")] id: u16, #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
) -> &mut process::Command; ) -> &mut process::Command;
/// Sets the supplementary group IDs for the calling process. Translates to /// Sets the supplementary group IDs for the calling process. Translates to
@ -42,8 +42,8 @@ pub trait CommandExt: Sealed {
#[unstable(feature = "setgroups", issue = "90747")] #[unstable(feature = "setgroups", issue = "90747")]
fn groups( fn groups(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] groups: &[u32], #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32],
#[cfg(target_os = "vxworks")] groups: &[u16], #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16],
) -> &mut process::Command; ) -> &mut process::Command;
/// Schedules a closure to be run just before the `exec` function is /// Schedules a closure to be run just before the `exec` function is
@ -160,8 +160,8 @@ pub trait CommandExt: Sealed {
impl CommandExt for process::Command { impl CommandExt for process::Command {
fn uid( fn uid(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] id: u32, #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(target_os = "vxworks")] id: u16, #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
) -> &mut process::Command { ) -> &mut process::Command {
self.as_inner_mut().uid(id); self.as_inner_mut().uid(id);
self self
@ -169,8 +169,8 @@ impl CommandExt for process::Command {
fn gid( fn gid(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] id: u32, #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(target_os = "vxworks")] id: u16, #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
) -> &mut process::Command { ) -> &mut process::Command {
self.as_inner_mut().gid(id); self.as_inner_mut().gid(id);
self self
@ -178,8 +178,8 @@ impl CommandExt for process::Command {
fn groups( fn groups(
&mut self, &mut self,
#[cfg(not(target_os = "vxworks"))] groups: &[u32], #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32],
#[cfg(target_os = "vxworks")] groups: &[u16], #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16],
) -> &mut process::Command { ) -> &mut process::Command {
self.as_inner_mut().groups(groups); self.as_inner_mut().groups(groups);
self self

View file

@ -11,6 +11,21 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
use libc::{c_int, c_void}; 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)] #[derive(Debug)]
pub struct FileDesc(OwnedFd); pub struct FileDesc(OwnedFd);
@ -109,7 +124,7 @@ impl FileDesc {
self.as_raw_fd(), self.as_raw_fd(),
buf.as_mut_ptr() as *mut c_void, buf.as_mut_ptr() as *mut c_void,
cmp::min(buf.len(), READ_LIMIT), cmp::min(buf.len(), READ_LIMIT),
offset as i64, offset as off64_t,
)) ))
.map(|n| n as usize) .map(|n| n as usize)
} }
@ -176,7 +191,7 @@ impl FileDesc {
self.as_raw_fd(), self.as_raw_fd(),
buf.as_ptr() as *const c_void, buf.as_ptr() as *const c_void,
cmp::min(buf.len(), READ_LIMIT), cmp::min(buf.len(), READ_LIMIT),
offset as i64, offset as off64_t,
)) ))
.map(|n| n as usize) .map(|n| n as usize)
} }

View file

@ -966,7 +966,7 @@ impl File {
SeekFrom::End(off) => (libc::SEEK_END, off), SeekFrom::End(off) => (libc::SEEK_END, off),
SeekFrom::Current(off) => (libc::SEEK_CUR, 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) Ok(n as u64)
} }