summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index c3b2b61e..f855c0af 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -2334,3 +2334,28 @@ mod setres {
Errno::result(res).map(drop)
}
}
+
+libc_bitflags!{
+ /// Options for access()
+ pub struct AccessFlags : c_int {
+ /// Test for existence of file.
+ F_OK;
+ /// Test for read permission.
+ R_OK;
+ /// Test for write permission.
+ W_OK;
+ /// Test for execute (search) permission.
+ X_OK;
+ }
+}
+
+/// Checks the file named by `path` for accessibility according to the flags given by `amode`
+/// See [access(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html)
+pub fn access<P: ?Sized + NixPath>(path: &P, amode: AccessFlags) -> Result<()> {
+ let res = path.with_nix_path(|cstr| {
+ unsafe {
+ libc::access(cstr.as_ptr(), amode.bits)
+ }
+ })?;
+ Errno::result(res).map(drop)
+}