The 'stat' module makes two checks: checking whether stat handles trailing slashes on directories... checking whether stat handles trailing slashes on files...
On native Windows, the results are: * for mingw and MSVC 9: checking whether stat handles trailing slashes on directories... no checking whether stat handles trailing slashes on files... yes * for mingw64: checking whether stat handles trailing slashes on directories... yes checking whether stat handles trailing slashes on files... no This behaviour comes from a definition of stat() in libmingwex.a. These bright guys (the mingw64 developers) meant to fix one stat() bug, but 1) in the process, opened another bug, 2) did not apply their fix to the other variants (_stat, _stat64, etc.) Witness: =============================== foo.c =============================== #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> int main () { { struct stat st; int ret1 = stat (".", &st); int ret2 = stat ("./", &st); int ret3 = stat ("conftest.tmp/", &st); printf ("%d %d %d\n", ret1, ret2, ret3); } { struct _stat st; int ret1 = _stat (".", &st); int ret2 = _stat ("./", &st); int ret3 = _stat ("conftest.tmp/", &st); printf ("%d %d %d\n", ret1, ret2, ret3); } { struct _stati64 st; int ret1 = _stati64 (".", &st); int ret2 = _stati64 ("./", &st); int ret3 = _stati64 ("conftest.tmp/", &st); printf ("%d %d %d\n", ret1, ret2, ret3); } { struct _stat64 st; int ret1 = _stat64 (".", &st); int ret2 = _stat64 ("./", &st); int ret3 = _stat64 ("conftest.tmp/", &st); printf ("%d %d %d\n", ret1, ret2, ret3); } return 0; } ===================================================================== $ touch conftest.tmp $ i686-w64-mingw32-gcc foo.c $ ./a.exe 0 0 0 0 -1 -1 0 -1 -1 0 -1 -1 gnulib's override currently works OK, but can optimized: There is no need for gnulib to work around a bug introduced by mingw64's override. Just use the underlying function from MSVCRT.DLL. 2012-04-14 Bruno Haible <br...@clisp.org> stat: Bypass buggy override in mingw64. * m4/stat.m4 (gl_FUNC_STAT): Update comments. * lib/stat.c (stat) [mingw64]: Define to _stat. * doc/posix-functions/stat.texi: Mention mingw64 bug. --- doc/posix-functions/stat.texi.orig Sat Apr 14 22:08:42 2012 +++ doc/posix-functions/stat.texi Sat Apr 14 22:07:30 2012 @@ -15,7 +15,7 @@ @item On some platforms, @code{stat("link-to-file/",buf)} succeeds instead of failing with @code{ENOTDIR}. -FreeBSD 7.2, AIX 7.1, Solaris 9. +FreeBSD 7.2, AIX 7.1, Solaris 9, mingw64. @item On some platforms, @code{stat(".",buf)} and @code{stat("./",buf)} give different results: --- lib/stat.c.orig Sat Apr 14 22:08:42 2012 +++ lib/stat.c Sat Apr 14 22:07:30 2012 @@ -27,6 +27,15 @@ #include <sys/stat.h> #undef __need_system_sys_stat_h +#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \ + && REPLACE_FUNC_STAT_FILE +/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a. + Bypass it. */ +# define stat _stat +# define REPLACE_FUNC_STAT_DIR 1 +# undef REPLACE_FUNC_STAT_FILE +#endif + static inline int orig_stat (const char *filename, struct stat *buf) { --- m4/stat.m4.orig Sat Apr 14 22:08:42 2012 +++ m4/stat.m4 Sat Apr 14 22:07:30 2012 @@ -1,4 +1,4 @@ -# serial 8 +# serial 9 # Copyright (C) 2009-2012 Free Software Foundation, Inc. # @@ -23,8 +23,9 @@ mingw*) gl_cv_func_stat_dir_slash="guessing no";; *) gl_cv_func_stat_dir_slash="guessing yes";; esac])]) - dnl AIX 7.1, Solaris 9 mistakenly succeed on stat("file/") - dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/") + dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/"). + dnl (For mingw, this is due to a broken stat() override in libmingwex.a.) + dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/"). AC_CACHE_CHECK([whether stat handles trailing slashes on files], [gl_cv_func_stat_file_slash], [touch conftest.tmp