From 9ea697df4ffa87bd867a982f5481bbf24f4a8c94 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 3 Oct 2023 17:59:38 +0200 Subject: [PATCH] access: Make last change work also when module 'stat' is in use. * lib/access.c (access): When stat() returns -1 with errno != EOVERFLOW, fail. --- ChangeLog | 4 ++++ lib/access.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) 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 -- 2.39.5