diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-01-22 11:45:38 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-01-22 12:02:55 -0800 |
commit | a900e641fa1fd765799f12a7f699f768ebfccfe8 (patch) | |
tree | a874eba952d3e51190a2bfe26cfe6c1635e9fda1 /lib/fchmodat.c | |
parent | 9143eba0c6861f467c18bc52d66e6f5c573be56b (diff) | |
download | emacs-a900e641fa1fd765799f12a7f699f768ebfccfe8.tar.gz |
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib/fchmodat.c')
-rw-r--r-- | lib/fchmodat.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/fchmodat.c b/lib/fchmodat.c index d27c0d7734a..eb6e2242fdd 100644 --- a/lib/fchmodat.c +++ b/lib/fchmodat.c @@ -38,6 +38,7 @@ orig_fchmodat (int dir, char const *file, mode_t mode, int flags) #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #ifdef __osf__ @@ -63,6 +64,22 @@ orig_fchmodat (int dir, char const *file, mode_t mode, int flags) int fchmodat (int dir, char const *file, mode_t mode, int flags) { +# if HAVE_NEARLY_WORKING_FCHMODAT + /* Correct the trailing slash handling. */ + size_t len = strlen (file); + if (len && file[len - 1] == '/') + { + struct stat st; + if (fstatat (dir, file, &st, flags & AT_SYMLINK_NOFOLLOW) < 0) + return -1; + if (!S_ISDIR (st.st_mode)) + { + errno = ENOTDIR; + return -1; + } + } +# endif + # if NEED_FCHMODAT_NONSYMLINK_FIX if (flags == AT_SYMLINK_NOFOLLOW) { |