On 2023-10-03 I did: > * tests/test-access.c (main): Test for result if the argument has a > trailing slash.
The new test cases fail on native Windows: ../../gltests/test-access.h:54: assertion 'errno == ENOTDIR' failed FAIL test-access.exe (exit status: 3) This patch fixes it. 2023-10-13 Bruno Haible <br...@clisp.org> access: Fix test failure on native Windows. * lib/access.c (access): Do the trailing slash workaround also on native Windows. * modules/access (Depends-on): Add stat. diff --git a/lib/access.c b/lib/access.c index a7acf8c49e..0551d0f75d 100644 --- a/lib/access.c +++ b/lib/access.c @@ -19,34 +19,36 @@ /* Specification. */ #include <unistd.h> +#include <errno.h> #include <fcntl.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> -#if defined _WIN32 && ! defined __CYGWIN__ - +#if defined _WIN32 && !defined __CYGWIN__ # include <io.h> +#endif int access (const char *file, int mode) +#undef access { + int ret; + +#if defined _WIN32 && !defined __CYGWIN__ if ((mode & X_OK) != 0) mode = (mode & ~X_OK) | R_OK; - return _access (file, mode); -} - + ret = _access (file, mode); #else + ret = access (file, mode); +#endif -# include <errno.h> -# include <string.h> -# include <sys/types.h> -# include <sys/stat.h> - -int -access (const char *file, int mode) -# undef access -{ - int ret = access (file, mode); -# if ACCESS_TRAILING_SLASH_BUG +#if (defined _WIN32 && !defined __CYGWIN__) || ACCESS_TRAILING_SLASH_BUG +# if defined _WIN32 && !defined __CYGWIN__ + if (ret == 0 || errno == EINVAL) +# else if (ret == 0) +# endif { size_t file_len = strlen (file); if (file_len > 0 && file[file_len - 1] == '/') @@ -64,8 +66,6 @@ access (const char *file, int mode) return (mode == F_OK && errno == EOVERFLOW ? 0 : -1); } } -# endif +#endif return ret; } - -#endif diff --git a/modules/access b/modules/access index cc23d81cae..543857a1fa 100644 --- a/modules/access +++ b/modules/access @@ -8,6 +8,7 @@ m4/access.m4 Depends-on: unistd fcntl +stat configure.ac: gl_FUNC_ACCESS