Skip to content

Commit

Permalink
extend LinkatFlags to allow passing AT_EMPTY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
xaverdh committed Nov 30, 2022
1 parent ed8319c commit d24c4af
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,20 @@ pub fn isatty(fd: RawFd) -> Result<bool> {
}
}

/// Flags for `linkat` function.
#[derive(Clone, Copy, Debug)]
pub enum LinkatFlags {
SymlinkFollow,
NoSymlinkFollow,
libc_bitflags! {
pub struct LinkatFlags: c_int {
AT_SYMLINK_FOLLOW;
#[cfg(any(target_os = "android", target_os = "linux"))]
AT_EMPTY_PATH;
}
}

/// Flags for `linkat` function.
#[allow(non_upper_case_globals)]
pub const SymlinkFollow : LinkatFlags = LinkatFlags::AT_SYMLINK_FOLLOW;
#[allow(non_upper_case_globals)]
pub const NoSymlinkFollow : LinkatFlags = LinkatFlags::empty();

/// Link one file to another file
///
/// Creates a new link (directory entry) at `newpath` for the existing file at `oldpath`. In the
Expand All @@ -1254,15 +1261,9 @@ pub fn linkat<P: ?Sized + NixPath>(
oldpath: &P,
newdirfd: Option<RawFd>,
newpath: &P,
flag: LinkatFlags,
flags: LinkatFlags,
) -> Result<()> {

let atflag =
match flag {
LinkatFlags::SymlinkFollow => AtFlags::AT_SYMLINK_FOLLOW,
LinkatFlags::NoSymlinkFollow => AtFlags::empty(),
};

let res =
oldpath.with_nix_path(|oldcstr| {
newpath.with_nix_path(|newcstr| {
Expand All @@ -1272,7 +1273,7 @@ pub fn linkat<P: ?Sized + NixPath>(
oldcstr.as_ptr(),
at_rawfd(newdirfd),
newcstr.as_ptr(),
atflag.bits() as libc::c_int
flags.bits() as libc::c_int
)
}
})
Expand Down

0 comments on commit d24c4af

Please sign in to comment.