]> Savannah Git Hosting - gnulib.git/commitdiff
access: Fix test failure on native Windows.
authorBruno Haible <bruno@clisp.org>
Fri, 13 Oct 2023 10:56:49 +0000 (12:56 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 13 Oct 2023 10:56:49 +0000 (12:56 +0200)
* lib/access.c (access): Do the trailing slash workaround also on
native Windows.
* modules/access (Depends-on): Add stat.

ChangeLog
lib/access.c
modules/access

index 12dee61c16a4fc5936b3e1d16c457c515b36a1aa..01875a5d4e088847438a7153b6f6ebed3ee007c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-10-13  Bruno Haible  <bruno@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.
+
 2023-10-13  Bruno Haible  <bruno@clisp.org>
 
        isnanf, isnand: Fix conflict with Solaris <ieeefp.h>.
index a7acf8c49eccae54fe4fbe04a72139d5f89f34fe..0551d0f75d5d4adc21b5ad6d09bed43b52af1dab 100644 (file)
 /* 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
index cc23d81cae24f8e6890fa03569ed8799364e822a..543857a1faec723b99cc860d5bfdb1e02a0a70b2 100644 (file)
@@ -8,6 +8,7 @@ m4/access.m4
 Depends-on:
 unistd
 fcntl
+stat
 
 configure.ac:
 gl_FUNC_ACCESS