diff options
author | Julio Merino <julio@meroh.net> | 2018-10-17 06:35:45 -0400 |
---|---|---|
committer | Julio Merino <julio@meroh.net> | 2018-10-19 22:09:13 -0400 |
commit | f3dab48a9221ede9f5409662eacca4b53de34171 (patch) | |
tree | 06607538e84ea1a65828c87cd9960ad4f72a9596 /src/sys/stat.rs | |
parent | dc6b2992f5e794cdc67a49a23b239241b0ebafd5 (diff) | |
download | nix-f3dab48a9221ede9f5409662eacca4b53de34171.zip |
Add a fchownat(2) wrapper
Diffstat (limited to 'src/sys/stat.rs')
-rw-r--r-- | src/sys/stat.rs | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs index d0f0f8d9..a0b3aafc 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -3,10 +3,9 @@ pub use libc::stat as FileStat; use {Result, NixPath}; use errno::Errno; -use fcntl::AtFlags; +use fcntl::{AtFlags, at_rawfd}; use libc; use std::mem; -use std::os::raw; use std::os::unix::io::RawFd; use sys::time::{TimeSpec, TimeVal}; @@ -135,15 +134,6 @@ pub fn fchmod(fd: RawFd, mode: Mode) -> Result<()> { Errno::result(res).map(|_| ()) } -/// Computes the raw fd consumed by a function of the form `*at`. -#[inline] -fn actual_atfd(fd: Option<RawFd>) -> raw::c_int { - match fd { - None => libc::AT_FDCWD, - Some(fd) => fd, - } -} - /// Flags for `fchmodat` function. #[derive(Clone, Copy, Debug)] pub enum FchmodatFlags { @@ -180,7 +170,7 @@ pub fn fchmodat<P: ?Sized + NixPath>( }; let res = path.with_nix_path(|cstr| unsafe { libc::fchmodat( - actual_atfd(dirfd), + at_rawfd(dirfd), cstr.as_ptr(), mode.bits() as mode_t, atflag.bits() as libc::c_int, @@ -260,7 +250,7 @@ pub fn utimensat<P: ?Sized + NixPath>( let times: [libc::timespec; 2] = [*atime.as_ref(), *mtime.as_ref()]; let res = path.with_nix_path(|cstr| unsafe { libc::utimensat( - actual_atfd(dirfd), + at_rawfd(dirfd), cstr.as_ptr(), ×[0], atflag.bits() as libc::c_int, |