UCRT's access() function errors out if the X_OK flag is passed.
(The __mingw_access() function was added because the access() function
also used to error out on this flag in msvcrt.dll in Vista, but the
issue there seems to have been reverted at some point, because the
issue can't be reproduced on Vista any longer. But it can be reproduced
with UCRT.)

Change the use of the __USE_MINGW_ACCESS define, to allow defining
__USE_MINGW_ACCESS=0 to use the default version of the function
from the CRT.

Signed-off-by: Martin Storsjö <mar...@martin.st>
---
 mingw-w64-headers/crt/_mingw.h.in | 13 +++++++++++++
 mingw-w64-headers/crt/io.h        |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-headers/crt/_mingw.h.in 
b/mingw-w64-headers/crt/_mingw.h.in
index 83fa2da80..06e88a507 100644
--- a/mingw-w64-headers/crt/_mingw.h.in
+++ b/mingw-w64-headers/crt/_mingw.h.in
@@ -443,6 +443,19 @@ typedef int __int128 __attribute__ ((__mode__ (TI)));
 #define __USE_MINGW_ANSI_STDIO 0      /* was defined as (int)zero and 
non-empty so it should be 0 */
 #endif
 
+#if defined(_UCRT) && !defined(__USE_MINGW_ACCESS)
+/* UCRT's access() errors out on X_OK. */
+#  define __USE_MINGW_ACCESS 1
+#endif
+
+#if !defined(__USE_MINGW_ACCESS)
+#define __USE_MINGW_ACCESS 0          /* was not defined so it should be 0 */
+#elif (__USE_MINGW_ACCESS + 0) != 0 || (1 - __USE_MINGW_ACCESS - 1) == 2
+#define __USE_MINGW_ACCESS 1          /* was defined as nonzero or empty so it 
should be 1 */
+#else
+#define __USE_MINGW_ACCESS 0          /* was defined as (int)zero and 
non-empty so it should be 0 */
+#endif
+
 /* _dowildcard is an int that controls the globbing of the command line.
  * The MinGW32 (mingw.org) runtime calls it _CRT_glob, so we are adding
  * a compatibility definition here:  you can use either of _CRT_glob or
diff --git a/mingw-w64-headers/crt/io.h b/mingw-w64-headers/crt/io.h
index 8986931a5..c90cdf7f7 100644
--- a/mingw-w64-headers/crt/io.h
+++ b/mingw-w64-headers/crt/io.h
@@ -363,7 +363,7 @@ unsigned int alarm(unsigned int seconds);
 
 #endif
 
-#ifdef __USE_MINGW_ACCESS
+#if __USE_MINGW_ACCESS
 /*  Old versions of MSVCRT access() just ignored X_OK, while the version
     shipped with Vista, returns an error code.  This will restore the
     old behaviour  */
-- 
2.25.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to