summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-08-06 02:11:37 +0000
committerGitHub <noreply@github.com>2022-08-06 02:11:37 +0000
commita10078f35c9564950035dfc88cb3a2cd9f3d9be3 (patch)
treee171da249e57ded5ab6ea3349b9d7fdf46493e5b /src/unistd.rs
parent67329c593f2482f5278b76fb436c7db79c921521 (diff)
parentf8c79c63e5b2779f4b1d4f5e113541cadb51b32f (diff)
downloadnix-a10078f35c9564950035dfc88cb3a2cd9f3d9be3.zip
Merge #1780
1780: Implement faccessat r=asomers a=nateavers This is a re-post of #1134, which seems to have been abandoned. Includes the changes requested in [this comment](https://github.com/nix-rust/nix/pull/1134#issuecomment-541346612). Co-authored-by: Zhang Miaolei <zmlcc@outlook.com>
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index d3915dcc..70a06b02 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -2900,6 +2900,27 @@ pub fn access<P: ?Sized + NixPath>(path: &P, amode: AccessFlags) -> Result<()> {
})?;
Errno::result(res).map(drop)
}
+
+/// Checks the file named by `path` for accessibility according to the flags given by `mode`
+///
+/// If `dirfd` has a value, then `path` is relative to directory associated with the file descriptor.
+///
+/// If `dirfd` is `None`, then `path` is relative to the current working directory.
+///
+/// # References
+///
+/// [faccessat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html)
+// illumos: faccessat(2) appears to be supported, but the libc crate does not provide a binding.
+// redox: does not appear to support the *at family of syscalls.
+#[cfg(not(any(target_os = "illumos", target_os = "redox")))]
+pub fn faccessat<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P, mode: AccessFlags, flags: AtFlags) -> Result<()> {
+ let res = path.with_nix_path(|cstr| {
+ unsafe {
+ libc::faccessat(at_rawfd(dirfd), cstr.as_ptr(), mode.bits(), flags.bits())
+ }
+ })?;
+ Errno::result(res).map(drop)
+}
}
feature! {