diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-13 10:54:20 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-13 10:54:20 -0800 |
commit | 99ceefa8ec4f9993663492cfcce6bb82a94569c1 (patch) | |
tree | 507f76715b3086f34672b7c984dc09befaa57fc6 /lib | |
parent | a7b7b85567f766ff510a5eaaaf32dbbbec15efd0 (diff) | |
parent | 79108894dbcd642121466bb6af6c98c6a56e9233 (diff) | |
download | emacs-99ceefa8ec4f9993663492cfcce6bb82a94569c1.tar.gz |
Merge from origin/emacs-26
79108894db Port to IBM xlc 12.01
d14956099d Simplify by removing HAVE_STRUCT_ATTRIBUTE_ALIGNED
b1573a97e1 Use alignas to fix GCALIGN-related bugs
5d68dc9a2f Change vectorlike from struct to union
6aa0a26b46 Don't enable cursor-sensor-mode in mhtml-mode
2b8ef8dddf * lisp/files.el (abbreviate-file-name): Doc fix. (Bug#29267)
fe85ce1e16 Unbreak interactive run of a flymake test (bug#29267)
48ad00390d Fix Bug#29225
42daf83f08 CC Mode: Fix defun-open being recognized as brace-list-ope...
7775c47298 Merge from Gnulib
e470d16448 Pacify GCC when configured --with-x-toolkit=no
49450d0951 * lisp/find-dired.el (find-grep-dired): Doc fix. (Bug#29262)
e286b3381f Fix more flymake-diag-region eob corner cases and add test...
# Conflicts:
# src/lisp.h
Diffstat (limited to 'lib')
-rw-r--r-- | lib/faccessat.c | 60 | ||||
-rw-r--r-- | lib/fstatat.c | 2 | ||||
-rw-r--r-- | lib/gnulib.mk.in | 2 | ||||
-rw-r--r-- | lib/unistd.in.h | 16 |
4 files changed, 70 insertions, 10 deletions
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 <unistd.h>, let it include only + the system's <unistd.h> here, so that orig_faccessat doesn't recurse to + rpl_faccessat. */ +#define _GL_INCLUDING_UNISTD_H #include <config.h> #include <unistd.h> +#include <errno.h> #include <fcntl.h> +#include <string.h> +#include <sys/stat.h> +#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 <unistd.h>, otherwise OSF/1 5.1 DTK cc + eliminates this include because of the preliminary #include <unistd.h> + 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 diff --git a/lib/fstatat.c b/lib/fstatat.c index 67e48d95d71..294861f51b1 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -28,7 +28,7 @@ #include <sys/stat.h> #undef __need_system_sys_stat_h -#if HAVE_FSTATAT +#if HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG static int orig_fstatat (int fd, char const *filename, struct stat *buf, int flags) { diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index e9358a6855d..a7b33ba34e8 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -689,6 +689,7 @@ REPLACE_DIRFD = @REPLACE_DIRFD@ REPLACE_DPRINTF = @REPLACE_DPRINTF@ REPLACE_DUP = @REPLACE_DUP@ REPLACE_DUP2 = @REPLACE_DUP2@ +REPLACE_FACCESSAT = @REPLACE_FACCESSAT@ REPLACE_FCHOWNAT = @REPLACE_FCHOWNAT@ REPLACE_FCLOSE = @REPLACE_FCLOSE@ REPLACE_FCNTL = @REPLACE_FCNTL@ @@ -2997,6 +2998,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ + -e 's|@''REPLACE_FACCESSAT''@|$(REPLACE_FACCESSAT)|g' \ -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index ca8090a3526..91447835811 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -461,13 +461,25 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - " #if @GNULIB_FACCESSAT@ -# if !@HAVE_FACCESSAT@ +# if @REPLACE_FACCESSAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef faccessat +# define faccessat rpl_faccessat +# endif +_GL_FUNCDECL_RPL (faccessat, int, + (int fd, char const *name, int mode, int flag) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (faccessat, int, + (int fd, char const *name, int mode, int flag)); +# else +# if !@HAVE_FACCESSAT@ _GL_FUNCDECL_SYS (faccessat, int, (int fd, char const *file, int mode, int flag) _GL_ARG_NONNULL ((2))); -# endif +# endif _GL_CXXALIAS_SYS (faccessat, int, (int fd, char const *file, int mode, int flag)); +# endif _GL_CXXALIASWARN (faccessat); #elif defined GNULIB_POSIXCHECK # undef faccessat |