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 /src/libunixonacid | |
parent | 77c1c85dbf79927f48b4dc09cd4cdbadcfee84af (diff) | |
download | skalibs-483de1edb380b33c6adf56c8f47a701a0e268f07.tar.xz |
Add access_at, because MacOS
Diffstat (limited to 'src/libunixonacid')
-rw-r--r-- | src/libunixonacid/access_at.c | 53 |
1 files changed, 53 insertions, 0 deletions
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 |