From 04e409b376615080e1d910e302b28b144dcbff71 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Thu, 13 Oct 2022 09:23:09 +0800 Subject: add eaccess on FreeBSD, DragonFly and Linux (musl and glibc) --- src/unistd.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/unistd.rs') diff --git a/src/unistd.rs b/src/unistd.rs index 5be59b6c..dc452d2d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -2931,6 +2931,27 @@ pub fn faccessat(dirfd: Option, path: &P, mode: Acce })?; Errno::result(res).map(drop) } + +/// Checks the file named by `path` for accessibility according to the flags given +/// by `mode` using effective UID, effective GID and supplementary group lists. +/// +/// # References +/// +/// * [FreeBSD man page](https://www.freebsd.org/cgi/man.cgi?query=eaccess&sektion=2&n=1) +/// * [Linux man page](https://man7.org/linux/man-pages/man3/euidaccess.3.html) +#[cfg(any( + all(target_os = "linux", not(target_env = "uclibc")), + target_os = "freebsd", + target_os = "dragonfly" +))] +pub fn eaccess(path: &P, mode: AccessFlags) -> Result<()> { + let res = path.with_nix_path(|cstr| { + unsafe { + libc::eaccess(cstr.as_ptr(), mode.bits) + } + })?; + Errno::result(res).map(drop) +} } feature! { -- cgit v1.2.3