summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorjr <semi1@posteo.de>2019-04-19 23:52:59 +0200
committerjr <semi1@posteo.de>2019-04-20 12:28:54 +0200
commit78d7aea35ef838a88d85a79a0acf36c5506d76ed (patch)
treee552cd853765b1455c521d895211593f9f7b5f5d /src/unistd.rs
parentaf59a15c5e03457db7ebd1743e9ecc14bc2de2f1 (diff)
downloadnix-78d7aea35ef838a88d85a79a0acf36c5506d76ed.zip
Add a access(2) wrapper
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)
+}