From f3dab48a9221ede9f5409662eacca4b53de34171 Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Wed, 17 Oct 2018 06:35:45 -0400 Subject: Add a fchownat(2) wrapper --- src/sys/stat.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/sys/stat.rs') 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) -> 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( }; 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( 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, -- cgit v1.2.3