From: Bruno Haible Date: Tue, 3 Oct 2023 15:59:38 +0000 (+0200) Subject: access: Make last change work also when module 'stat' is in use. X-Git-Tag: v1.0~746 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=9ea697df4ffa87bd867a982f5481bbf24f4a8c94;p=gnulib.git access: Make last change work also when module 'stat' is in use. * lib/access.c (access): When stat() returns -1 with errno != EOVERFLOW, fail. --- diff --git a/ChangeLog b/ChangeLog index 0c8d28f113..9b4317264e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2023-10-03 Bruno Haible + access: Make last change work also when module 'stat' is in use. + * lib/access.c (access): When stat() returns -1 with errno != EOVERFLOW, + fail. + access: Work around trailing slash bug on Mac OS X 10.5. * m4/access.m4 (gl_FUNC_ACCESS): Test whether access honors a trailing slash. Set REPLACE_ACCESS to 1 and define ACCESS_TRAILING_SLASH_BUG if diff --git a/lib/access.c b/lib/access.c index 75d2148453..a7acf8c49e 100644 --- a/lib/access.c +++ b/lib/access.c @@ -52,11 +52,16 @@ access (const char *file, int mode) if (file_len > 0 && file[file_len - 1] == '/') { struct stat st; - if (stat (file, &st) == 0 && ! S_ISDIR (st.st_mode)) + if (stat (file, &st) == 0) { - errno = ENOTDIR; - return -1; + if (! S_ISDIR (st.st_mode)) + { + errno = ENOTDIR; + return -1; + } } + else + return (mode == F_OK && errno == EOVERFLOW ? 0 : -1); } } # endif