From 483de1edb380b33c6adf56c8f47a701a0e268f07 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 27 Nov 2017 13:42:43 +0000 Subject: Add access_at, because MacOS --- src/libunixonacid/access_at.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/libunixonacid/access_at.c (limited to 'src/libunixonacid') 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 + +#ifdef SKALIBS_HASOPENAT + +#ifndef _ATFILE_SOURCE +#define _ATFILE_SOURCE +#endif + +#include +#include +#include +#include + +int access_at (int dirfd, char const *file, int amode, unsigned int flag) +{ + return faccessat(dirfd, file, amode, flag ? AT_EACCESS : 0) ; +} + +#else + +#include +#include +#include +#include + +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 -- cgit v1.2.3