]> Savannah Git Hosting - gnulib.git/commitdiff
stat, fstat: Fix when compiling for versions older than Windows Vista.
authorBruno Haible <bruno@clisp.org>
Wed, 16 Sep 2020 21:51:52 +0000 (23:51 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 16 Sep 2020 21:51:52 +0000 (23:51 +0200)
Reported by Eli Zaretskii <eliz@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
lib/stat-w32.c
m4/fstat.m4
m4/stat.m4

index b668fbd2b7cfd181726b785fd831ba128ed05e96..57501d556650837737f3a3c028e2cddc0103c9bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-09-16  Bruno Haible  <bruno@clisp.org>
+
+       stat, fstat: Fix when compiling for versions older than Windows Vista.
+       Reported by Eli Zaretskii <eliz@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  <eggert@cs.ucla.edu>
 
        dfa: remove dfa-heap-overrun workaround
index 19bdfaa379cdd0acf5586badf3bdf234f47e7271..72442e9335b49a458e5ab5c06117c2889c651cc4 100644 (file)
 
 #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
index 53c089619372b0ef97498bc0b94a502f89acce69..bd8cb7966215737d7c6b843352aa05d21669f2b6 100644 (file)
@@ -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])
   :
 ])
index 46e9abceee7d11582f381e2ef9330b044859bcd8..db2038f63dc0bfe6ef1a689b480c52bb0fa42333 100644 (file)
@@ -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
+])