Hi Eli, You are right on both accounts. Thanks for the reports. Should be fixed by the two attached patches.
> This happens because stat-w32.c unconditionally sets _WIN32_WINNT to > the value suitable for Windows 8.0 or later: > > #if defined _WIN32 && ! defined __CYGWIN__ > > /* Ensure that <windows.h> defines FILE_ID_INFO. */ > #if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8) > # undef _WIN32_WINNT > # define _WIN32_WINNT _WIN32_WINNT_WIN8 > #endif > > which later on causes it to expect GetFinalPathNameByHandle to be in > kernel32.dll, instead of dynamically loading it: > > #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) Yes, an obvious mistake. > In addition, VOLUME_NAME_NONE is used here, but the Windows headers > define it only when _WIN32_WINNT is greater or equal to > _WIN32_WINNT_VISTA In the MSVC9, MSVC14, and mingw64 headers, I find VOLUME_NAME_NONE to be always defined. And in some old mingw headers from 2003, I find it to be never defined. Bruno 2020-09-16 Bruno Haible <br...@clisp.org> stat, fstat: Fix compilation error with old mingw headers. Reported by Eli Zaretskii <e...@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. * lib/stat-w32.c (VOLUME_NAME_NONE): Define if the Windows headers don't define it. 2020-09-16 Bruno Haible <br...@clisp.org> stat, fstat: Fix when compiling for versions older than Windows Vista. Reported by Eli Zaretskii <e...@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. * lib/stat-w32.c: Include <sdkddkver.h>. Test the value of _WIN32_WINNT that was originally set before we redefined it. * m4/stat.m4 (gl_PREREQ_STAT_W32): New macro. (gl_PREREQ_STAT): Require it. * m4/fstat.m4 (gl_PREREQ_FSTAT): Likewise.
>From 1796cda9975bd459a87222676030b943869c686e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 16 Sep 2020 23:51:52 +0200 Subject: [PATCH 1/2] stat, fstat: Fix when compiling for versions older than Windows Vista. Reported by Eli Zaretskii <e...@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. * lib/stat-w32.c: Include <sdkddkver.h>. Test the value of _WIN32_WINNT that was originally set before we redefined it. * m4/stat.m4 (gl_PREREQ_STAT_W32): New macro. (gl_PREREQ_STAT): Require it. * m4/fstat.m4 (gl_PREREQ_FSTAT): Likewise. --- ChangeLog | 11 +++++++++++ lib/stat-w32.c | 24 ++++++++++++++++++------ m4/fstat.m4 | 3 ++- m4/stat.m4 | 13 ++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b668fbd..57501d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2020-09-16 Bruno Haible <br...@clisp.org> + + stat, fstat: Fix when compiling for versions older than Windows Vista. + Reported by Eli Zaretskii <e...@gnu.org> in + <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. + * lib/stat-w32.c: Include <sdkddkver.h>. Test the value of _WIN32_WINNT + that was originally set before we redefined it. + * m4/stat.m4 (gl_PREREQ_STAT_W32): New macro. + (gl_PREREQ_STAT): Require it. + * m4/fstat.m4 (gl_PREREQ_FSTAT): Likewise. + 2020-09-15 Paul Eggert <egg...@cs.ucla.edu> dfa: remove dfa-heap-overrun workaround diff --git a/lib/stat-w32.c b/lib/stat-w32.c index 19bdfaa..72442e9 100644 --- a/lib/stat-w32.c +++ b/lib/stat-w32.c @@ -20,10 +20,22 @@ #if defined _WIN32 && ! defined __CYGWIN__ -/* Ensure that <windows.h> defines FILE_ID_INFO. */ -#if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8) -# undef _WIN32_WINNT -# define _WIN32_WINNT _WIN32_WINNT_WIN8 +/* Attempt to make <windows.h> define FILE_ID_INFO. + But ensure that the redefinition of _WIN32_WINNT does not make us assume + Windows Vista or newer when building for an older version of Windows. */ +#if HAVE_SDKDDKVER_H +# include <sdkddkver.h> +# if _WIN32_WINNT >= _WIN32_WINNT_VISTA +# define WIN32_ASSUME_VISTA 1 +# else +# define WIN32_ASSUME_VISTA 0 +# endif +# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8) +# undef _WIN32_WINNT +# define _WIN32_WINNT _WIN32_WINNT_WIN8 +# endif +#else +# define WIN32_ASSUME_VISTA (_WIN32_WINNT >= _WIN32_WINNT_VISTA) #endif #include <sys/types.h> @@ -46,7 +58,7 @@ #undef GetFinalPathNameByHandle #define GetFinalPathNameByHandle GetFinalPathNameByHandleA -#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) +#if !WIN32_ASSUME_VISTA /* Avoid warnings from gcc -Wcast-function-type. */ # define GetProcAddress \ @@ -149,7 +161,7 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf) DWORD type = GetFileType (h); if (type == FILE_TYPE_DISK) { -#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) +#if !WIN32_ASSUME_VISTA if (!initialized) initialize (); #endif diff --git a/m4/fstat.m4 b/m4/fstat.m4 index 53c0896..bd8cb79 100644 --- a/m4/fstat.m4 +++ b/m4/fstat.m4 @@ -1,4 +1,4 @@ -# fstat.m4 serial 6 +# fstat.m4 serial 7 dnl Copyright (C) 2011-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -35,5 +35,6 @@ AC_DEFUN([gl_FUNC_FSTAT], # Prerequisites of lib/fstat.c and lib/stat-w32.c. AC_DEFUN([gl_PREREQ_FSTAT], [ AC_REQUIRE([gl_HEADER_SYS_STAT_H]) + AC_REQUIRE([gl_PREREQ_STAT_W32]) : ]) diff --git a/m4/stat.m4 b/m4/stat.m4 index 46e9abc..db2038f 100644 --- a/m4/stat.m4 +++ b/m4/stat.m4 @@ -1,4 +1,4 @@ -# serial 16 +# serial 17 # Copyright (C) 2009-2020 Free Software Foundation, Inc. # @@ -70,5 +70,16 @@ AC_DEFUN([gl_FUNC_STAT], # Prerequisites of lib/stat.c and lib/stat-w32.c. AC_DEFUN([gl_PREREQ_STAT], [ AC_REQUIRE([gl_HEADER_SYS_STAT_H]) + AC_REQUIRE([gl_PREREQ_STAT_W32]) : ]) + +# Prerequisites of lib/stat-w32.c. +AC_DEFUN([gl_PREREQ_STAT_W32], [ + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + mingw*) + AC_CHECK_HEADERS([sdkddkver.h]) + ;; + esac +]) -- 2.7.4
>From f8c23f202d11992182e87736e73929bcc369cc75 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 16 Sep 2020 23:52:44 +0200 Subject: [PATCH 2/2] stat, fstat: Fix compilation error with old mingw headers. Reported by Eli Zaretskii <e...@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. * lib/stat-w32.c (VOLUME_NAME_NONE): Define if the Windows headers don't define it. --- ChangeLog | 8 ++++++++ lib/stat-w32.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 57501d5..d18ec51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-09-16 Bruno Haible <br...@clisp.org> + stat, fstat: Fix compilation error with old mingw headers. + Reported by Eli Zaretskii <e...@gnu.org> in + <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. + * lib/stat-w32.c (VOLUME_NAME_NONE): Define if the Windows headers don't + define it. + +2020-09-16 Bruno Haible <br...@clisp.org> + stat, fstat: Fix when compiling for versions older than Windows Vista. Reported by Eli Zaretskii <e...@gnu.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. diff --git a/lib/stat-w32.c b/lib/stat-w32.c index 72442e9..108ce19 100644 --- a/lib/stat-w32.c +++ b/lib/stat-w32.c @@ -58,6 +58,11 @@ #undef GetFinalPathNameByHandle #define GetFinalPathNameByHandle GetFinalPathNameByHandleA +/* Older mingw headers do not define VOLUME_NAME_NONE. */ +#ifndef VOLUME_NAME_NONE +# define VOLUME_NAME_NONE 4 +#endif + #if !WIN32_ASSUME_VISTA /* Avoid warnings from gcc -Wcast-function-type. */ -- 2.7.4