Skip to content

Commit

Permalink
Disable dirfd for vxworks, Return unsupported error from set_times an…
Browse files Browse the repository at this point in the history
…d lchown for vxworks
  • Loading branch information
B I Mohammed Abbas committed Jul 23, 2024
1 parent 22a6797 commit 227b5af
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ impl Drop for Dir {
target_os = "espidf",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vxworks",
)))]
{
let fd = unsafe { libc::dirfd(self.0) };
Expand Down Expand Up @@ -1313,7 +1314,12 @@ impl File {
}

pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))]
#[cfg(not(any(
target_os = "redox",
target_os = "espidf",
target_os = "horizon",
target_os = "vxworks"
)))]
let to_timespec = |time: Option<SystemTime>| match time {
Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts),
Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!(
Expand All @@ -1327,10 +1333,11 @@ impl File {
None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }),
};
cfg_if::cfg_if! {
if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] {
if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "vxworks"))] {
// Redox doesn't appear to support `UTIME_OMIT`.
// ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore
// the same as for Redox.
// `futimens` and `UTIME_OMIT` are a work in progress for vxworks.
let _ = times;
Err(io::const_io_error!(
io::ErrorKind::Unsupported,
Expand Down Expand Up @@ -1962,13 +1969,20 @@ pub fn fchown(fd: c_int, uid: u32, gid: u32) -> io::Result<()> {
Ok(())
}

#[cfg(not(target_os = "vxworks"))]
pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
run_path_with_cstr(path, &|path| {
cvt(unsafe { libc::lchown(path.as_ptr(), uid as libc::uid_t, gid as libc::gid_t) })
.map(|_| ())
})
}

#[cfg(target_os = "vxworks")]
pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
let (_, _, _) = (path, uid, gid);
Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks",))
}

#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
pub fn chroot(dir: &Path) -> io::Result<()> {
run_path_with_cstr(dir, &|dir| cvt(unsafe { libc::chroot(dir.as_ptr()) }).map(|_| ()))
Expand Down

0 comments on commit 227b5af

Please sign in to comment.