diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-11-27 13:42:43 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-11-27 13:42:43 +0000 |
commit | 483de1edb380b33c6adf56c8f47a701a0e268f07 (patch) | |
tree | 1bad67d2f0647803018ca5e2a6923f5f4a7597b8 | |
parent | 77c1c85dbf79927f48b4dc09cd4cdbadcfee84af (diff) | |
download | skalibs-483de1edb380b33c6adf56c8f47a701a0e268f07.tar.xz |
Add access_at, because MacOS
-rw-r--r-- | package/deps.mak | 1 | ||||
-rw-r--r-- | src/include/skalibs/unix-transactional.h | 1 | ||||
-rw-r--r-- | src/libunixonacid/access_at.c | 53 |
3 files changed, 55 insertions, 0 deletions
diff --git a/package/deps.mak b/package/deps.mak index acce8a0..f5aa076 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -687,6 +687,7 @@ src/libstddjb/xpathexec_fromenv.o src/libstddjb/xpathexec_fromenv.lo: src/libstd src/libstddjb/xpathexec_r.o src/libstddjb/xpathexec_r.lo: src/libstddjb/xpathexec_r.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_r_name.o src/libstddjb/xpathexec_r_name.lo: src/libstddjb/xpathexec_r_name.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_run.o src/libstddjb/xpathexec_run.lo: src/libstddjb/xpathexec_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h +src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_rm_rf.o src/libunixonacid/atomic_rm_rf.lo: src/libunixonacid/atomic_rm_rf.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_rm_rf_tmp.o src/libunixonacid/atomic_rm_rf_tmp.lo: src/libunixonacid/atomic_rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/bufalloc_timed_flush.o src/libunixonacid/bufalloc_timed_flush.lo: src/libunixonacid/bufalloc_timed_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h index 5f1dd90..d548f78 100644 --- a/src/include/skalibs/unix-transactional.h +++ b/src/include/skalibs/unix-transactional.h @@ -13,6 +13,7 @@ extern int open2_at (int, char const *, int) ; extern int open3_at (int, char const *, int, unsigned int) ; +extern int access_at (int, char const *, int, unsigned int) ; extern int opengetlnclose (char const *, stralloc *, int) ; diff --git a/src/libunixonacid/access_at.c b/src/libunixonacid/access_at.c new file mode 100644 index 0000000..c66f5d4 --- /dev/null +++ b/src/libunixonacid/access_at.c @@ -0,0 +1,53 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifdef SKALIBS_HASOPENAT + +#ifndef _ATFILE_SOURCE +#define _ATFILE_SOURCE +#endif + +#include <skalibs/nonposix.h> +#include <fcntl.h> +#include <unistd.h> +#include <skalibs/unix-transactional.h> + +int access_at (int dirfd, char const *file, int amode, unsigned int flag) +{ + return faccessat(dirfd, file, amode, flag ? AT_EACCESS : 0) ; +} + +#else + +#include <errno.h> +#include <unistd.h> +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> + +int access_at (int dirfd, char const *file, int amode, unsigned int flag) +{ + int fdhere ; + if (getuid() != geteuid() || getgid() != getegid()) + return (errno = ENOSYS, -1) ; + (void)flag ; + fdhere = open_read(".") ; + if (fdhere < 0) return -1 ; + if (fd_chdir(dirfd) < 0) + { + fd_close(fdhere) ; + return -1 ; + } + if (access(file, amode) < 0) + { + int e = errno ; + fd_chdir(fdhere) ; + fd_close(fdhere) ; + return (errno = e, -1) ; + } + fd_chdir(fdhere) ; + fd_close(fdhere) ; + return 0 ; +} + +#endif |