From 7775c4729814431608c943643a490ad5f1f68a99 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 11 Nov 2017 23:11:03 -0800 Subject: Merge from Gnulib This incorporates: 2017-11-11 faccessat: port to macOS (Bug#29231) 2017-11-05 fstatat: pacify GCC on unusual platform * build-aux/config.guess, build-aux/config.sub: * doc/misc/texinfo.tex, lib/faccessat.c, lib/fstatat.c: * lib/unistd.in.h, m4/faccessat.m4, m4/unistd_h.m4: Copy from Gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. --- lib/faccessat.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'lib/faccessat.c') diff --git a/lib/faccessat.c b/lib/faccessat.c index 6cf9c99df20..fa9235820dc 100644 --- a/lib/faccessat.c +++ b/lib/faccessat.c @@ -16,10 +16,31 @@ /* written by Eric Blake */ +/* If the user's config.h happens to include , let it include only + the system's here, so that orig_faccessat doesn't recurse to + rpl_faccessat. */ +#define _GL_INCLUDING_UNISTD_H #include #include +#include #include +#include +#include +#undef _GL_INCLUDING_UNISTD_H + +#if HAVE_FACCESSAT +static int +orig_faccessat (int fd, char const *name, int mode, int flag) +{ + return faccessat (fd, name, mode, flag); +} +#endif + +/* Write "unistd.h" here, not , otherwise OSF/1 5.1 DTK cc + eliminates this include because of the preliminary #include + above. */ +#include "unistd.h" #ifndef HAVE_ACCESS /* Mingw lacks access, but it also lacks real vs. effective ids, so @@ -28,6 +49,29 @@ # define access euidaccess #endif +#if HAVE_FACCESSAT + +int +rpl_faccessat (int fd, char const *file, int mode, int flag) +{ + int result = orig_faccessat (fd, file, mode, flag); + + if (result == 0 && file[strlen (file) - 1] == '/') + { + struct stat st; + result = fstatat (fd, file, &st, 0); + if (result == 0 && !S_ISDIR (st.st_mode)) + { + errno = ENOTDIR; + return -1; + } + } + + return result; +} + +#else /* !HAVE_FACCESSAT */ + /* Invoke access or euidaccess on file, FILE, using mode MODE, in the directory open on descriptor FD. If possible, do it without changing the working directory. Otherwise, resort to using save_cwd/fchdir, then @@ -36,10 +80,12 @@ Note that this implementation only supports AT_EACCESS, although some native versions also support AT_SYMLINK_NOFOLLOW. */ -#define AT_FUNC_NAME faccessat -#define AT_FUNC_F1 euidaccess -#define AT_FUNC_F2 access -#define AT_FUNC_USE_F1_COND AT_EACCESS -#define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag -#define AT_FUNC_POST_FILE_ARGS , mode -#include "at-func.c" +# define AT_FUNC_NAME faccessat +# define AT_FUNC_F1 euidaccess +# define AT_FUNC_F2 access +# define AT_FUNC_USE_F1_COND AT_EACCESS +# define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag +# define AT_FUNC_POST_FILE_ARGS , mode +# include "at-func.c" + +#endif -- cgit v1.2.3