diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-24 11:38:48 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-24 12:06:48 -0800 |
commit | 6c98a29696b591c9a357183fac657f5547b6118a (patch) | |
tree | 2ea11b739489d0d9a8968c927867fb0648006bad /lib | |
parent | 340dcbd879d050aebcd7081ec5f2208f0e2418b6 (diff) | |
download | gnulib-6c98a29696b591c9a357183fac657f5547b6118a.tar.gz |
faccessat: work around F_OK EOVERFLOW bug
Also, tune when LSTAT_FOLLOWS_SLASHED_SYMLINK.
* doc/posix-functions/faccessat.texi: Mention the problem.
* lib/faccessat.c (FACCESSAT_NEVER_EOVERFLOWS)
(LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0.
(rpl_faccessat): If !FACCESSAT_NEVER_EOVERFLOWS, check
for F_OK and EOVERFLOW, which means we can return 0.
If LSTAT_FOLLOWS_SLASHED_SYMLINK, don't worry about
file names ending in slashes, as faccessat should already
do the right thing for them.
* m4/faccessat.m4 (gl_FUNC_FACCESSAT_EOVERFLOW): New macro.
(gl_FUNC_FACCESSAT): Use it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/faccessat.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/faccessat.c b/lib/faccessat.c index 9f6a11bf6e..330c54a0be 100644 --- a/lib/faccessat.c +++ b/lib/faccessat.c @@ -32,6 +32,13 @@ #include <sys/stat.h> #undef _GL_INCLUDING_UNISTD_H +#ifndef FACCESSAT_NEVER_EOVERFLOWS +# define FACCESSAT_NEVER_EOVERFLOWS 0 +#endif +#ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK +# define LSTAT_FOLLOWS_SLASHED_SYMLINK 0 +#endif + #if HAVE_FACCESSAT static int orig_faccessat (int fd, char const *name, int mode, int flag) @@ -59,7 +66,12 @@ 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] == '/') + if (result != 0) + { + if (!FACCESSAT_NEVER_EOVERFLOWS && mode == F_OK && errno == EOVERFLOW) + return 0; + } + else if (!LSTAT_FOLLOWS_SLASHED_SYMLINK && file[strlen (file) - 1] == '/') { struct stat st; result = fstatat (fd, file, &st, 0); |