__mingw_access() was introduced as the msvcrt.dll access() function reportedly returned errors when passed the X_OK constant on Vista.
Users who expect to be calling access() with the X_OK constant could set the __USE_MINGW_ACCESS define to get a mingw specific reimplementation of the function. GCC has been setting this define to work around this issue (but there have been cases where the define hasn't applied on all the source where it's needed). Current versions of msvcrt.dll no longer seem to have this issue with X_OK, so the issue has somewhat been forgotten since. But UCRT's access() function shows the same behaviour of returning errors when given that constant. Always defining __USE_MINGW_ACCESS when building targeting UCRT doesn't work, as the define of access() breaks other valid cases (e.g. calls to methods named access() in C++ classes). Instead remove the access() symbol from the import libraries, and expose an UCRT specific access() that just redirects to __mingw_access(). Signed-off-by: Martin Storsjö <[email protected]> --- mingw-w64-crt/Makefile.am | 1 + .../def-include/msvcrt-common.def.in | 4 ++++ .../api-ms-win-crt-filesystem-l1-1-0.def | 3 ++- mingw-w64-crt/misc/ucrt-access.c | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/misc/ucrt-access.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 6a2835079..802657117 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -240,6 +240,7 @@ src_ucrtbase=\ crt/ucrtbase_compat.c \ math/_huge.c \ misc/__initenv.c \ + misc/ucrt-access.c \ stdio/ucrt_fprintf.c \ stdio/ucrt_fscanf.c \ stdio/ucrt_fwprintf.c \ diff --git a/mingw-w64-crt/def-include/msvcrt-common.def.in b/mingw-w64-crt/def-include/msvcrt-common.def.in index e28b09e59..c31c6b631 100644 --- a/mingw-w64-crt/def-include/msvcrt-common.def.in +++ b/mingw-w64-crt/def-include/msvcrt-common.def.in @@ -12,7 +12,11 @@ wcscmpi == _wcsicmp strcasecmp == _stricmp strncasecmp == _strnicmp +#ifdef UCRTBASE +; access is provided as an alias for __mingw_access +#else ADD_UNDERSCORE(access) +#endif ADD_UNDERSCORE(chdir) ADD_UNDERSCORE(chmod) ADD_UNDERSCORE(chsize) diff --git a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def index e5966d642..45ae728ba 100644 --- a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def +++ b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def @@ -3,7 +3,8 @@ LIBRARY api-ms-win-crt-filesystem-l1-1-0 EXPORTS _access -access == _access +; access is provided as an alias for __mingw_access +; access == _access _access_s _chdir chdir == _chdir diff --git a/mingw-w64-crt/misc/ucrt-access.c b/mingw-w64-crt/misc/ucrt-access.c new file mode 100644 index 000000000..e0c93cad0 --- /dev/null +++ b/mingw-w64-crt/misc/ucrt-access.c @@ -0,0 +1,19 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#include <io.h> + +int __cdecl __mingw_access(const char *fname, int mode); + +int __cdecl access(const char *fname, int mode) +{ + /* On UCRT, unconditionally forward access to __mingw_access. UCRT's + * access() function return an error if passed the X_OK constant, + * while msvcrt.dll's access() doesn't. (It's reported that msvcrt.dll's + * access() also returned errors on X_OK in the version shipped in Vista, + * but in recent tests it's no longer the case.) */ + return __mingw_access(fname, mode); +} -- 2.25.1 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
