|
| 1 | +From 1796cda9975bd459a87222676030b943869c686e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Bruno Haible <bruno@clisp.org> |
| 3 | +Date: Wed, 16 Sep 2020 23:51:52 +0200 |
| 4 | +Subject: [PATCH 1/2] stat, fstat: Fix when compiling for versions older than |
| 5 | + Windows Vista. |
| 6 | + |
| 7 | +Reported by Eli Zaretskii <eliz@gnu.org> in |
| 8 | +<https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00027.html>. |
| 9 | + |
| 10 | +* lib/stat-w32.c: Include <sdkddkver.h>. Test the value of _WIN32_WINNT |
| 11 | +that was originally set before we redefined it. |
| 12 | +* m4/stat.m4 (gl_PREREQ_STAT_W32): New macro. |
| 13 | +(gl_PREREQ_STAT): Require it. |
| 14 | +* m4/fstat.m4 (gl_PREREQ_FSTAT): Likewise. |
| 15 | +--- |
| 16 | + stat-w32.c | 24 ++++++++++++++++++------ |
| 17 | + m4/fstat.m4 | 3 ++- |
| 18 | + m4/stat.m4 | 13 ++++++++++++- |
| 19 | + 4 files changed, 43 insertions(+), 8 deletions(-) |
| 20 | + |
| 21 | +diff --git a/gnulib/import/stat-w32.c b/gnulib/import/stat-w32.c |
| 22 | +index 19bdfaa37..72442e933 100644 |
| 23 | +--- a/gnulib/import/stat-w32.c |
| 24 | ++++ b/gnulib/import/stat-w32.c |
| 25 | +@@ -20,10 +20,22 @@ |
| 26 | + |
| 27 | + #if defined _WIN32 && ! defined __CYGWIN__ |
| 28 | + |
| 29 | +-/* Ensure that <windows.h> defines FILE_ID_INFO. */ |
| 30 | +-#if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8) |
| 31 | +-# undef _WIN32_WINNT |
| 32 | +-# define _WIN32_WINNT _WIN32_WINNT_WIN8 |
| 33 | ++/* Attempt to make <windows.h> define FILE_ID_INFO. |
| 34 | ++ But ensure that the redefinition of _WIN32_WINNT does not make us assume |
| 35 | ++ Windows Vista or newer when building for an older version of Windows. */ |
| 36 | ++#if HAVE_SDKDDKVER_H |
| 37 | ++# include <sdkddkver.h> |
| 38 | ++# if _WIN32_WINNT >= _WIN32_WINNT_VISTA |
| 39 | ++# define WIN32_ASSUME_VISTA 1 |
| 40 | ++# else |
| 41 | ++# define WIN32_ASSUME_VISTA 0 |
| 42 | ++# endif |
| 43 | ++# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8) |
| 44 | ++# undef _WIN32_WINNT |
| 45 | ++# define _WIN32_WINNT _WIN32_WINNT_WIN8 |
| 46 | ++# endif |
| 47 | ++#else |
| 48 | ++# define WIN32_ASSUME_VISTA (_WIN32_WINNT >= _WIN32_WINNT_VISTA) |
| 49 | + #endif |
| 50 | + |
| 51 | + #include <sys/types.h> |
| 52 | +@@ -46,7 +58,7 @@ |
| 53 | + #undef GetFinalPathNameByHandle |
| 54 | + #define GetFinalPathNameByHandle GetFinalPathNameByHandleA |
| 55 | + |
| 56 | +-#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) |
| 57 | ++#if !WIN32_ASSUME_VISTA |
| 58 | + |
| 59 | + /* Avoid warnings from gcc -Wcast-function-type. */ |
| 60 | + # define GetProcAddress \ |
| 61 | +@@ -149,7 +161,7 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf) |
| 62 | + DWORD type = GetFileType (h); |
| 63 | + if (type == FILE_TYPE_DISK) |
| 64 | + { |
| 65 | +-#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) |
| 66 | ++#if !WIN32_ASSUME_VISTA |
| 67 | + if (!initialized) |
| 68 | + initialize (); |
| 69 | + #endif |
| 70 | +diff --git a/gnulib/import/m4/fstat.m4 b/gnulib/import/m4/fstat.m4 |
| 71 | +index 53c089619..bd8cb7966 100644 |
| 72 | +--- a/gnulib/import/m4/fstat.m4 |
| 73 | ++++ b/gnulib/import/m4/fstat.m4 |
| 74 | +@@ -1,4 +1,4 @@ |
| 75 | +-# fstat.m4 serial 6 |
| 76 | ++# fstat.m4 serial 7 |
| 77 | + dnl Copyright (C) 2011-2020 Free Software Foundation, Inc. |
| 78 | + dnl This file is free software; the Free Software Foundation |
| 79 | + dnl gives unlimited permission to copy and/or distribute it, |
| 80 | +@@ -35,5 +35,6 @@ AC_DEFUN([gl_FUNC_FSTAT], |
| 81 | + # Prerequisites of lib/fstat.c and lib/stat-w32.c. |
| 82 | + AC_DEFUN([gl_PREREQ_FSTAT], [ |
| 83 | + AC_REQUIRE([gl_HEADER_SYS_STAT_H]) |
| 84 | ++ AC_REQUIRE([gl_PREREQ_STAT_W32]) |
| 85 | + : |
| 86 | + ]) |
| 87 | +diff --git a/gnulib/import/m4/stat.m4 b/gnulib/import/m4/stat.m4 |
| 88 | +index 46e9abcee..db2038f63 100644 |
| 89 | +--- a/gnulib/import/m4/stat.m4 |
| 90 | ++++ b/gnulib/import/m4/stat.m4 |
| 91 | +@@ -1,4 +1,4 @@ |
| 92 | +-# serial 16 |
| 93 | ++# serial 17 |
| 94 | + |
| 95 | + # Copyright (C) 2009-2020 Free Software Foundation, Inc. |
| 96 | + # |
| 97 | +@@ -70,5 +70,16 @@ AC_DEFUN([gl_FUNC_STAT], |
| 98 | + # Prerequisites of lib/stat.c and lib/stat-w32.c. |
| 99 | + AC_DEFUN([gl_PREREQ_STAT], [ |
| 100 | + AC_REQUIRE([gl_HEADER_SYS_STAT_H]) |
| 101 | ++ AC_REQUIRE([gl_PREREQ_STAT_W32]) |
| 102 | + : |
| 103 | + ]) |
| 104 | ++ |
| 105 | ++# Prerequisites of lib/stat-w32.c. |
| 106 | ++AC_DEFUN([gl_PREREQ_STAT_W32], [ |
| 107 | ++ AC_REQUIRE([AC_CANONICAL_HOST]) |
| 108 | ++ case "$host_os" in |
| 109 | ++ mingw*) |
| 110 | ++ AC_CHECK_HEADERS([sdkddkver.h]) |
| 111 | ++ ;; |
| 112 | ++ esac |
| 113 | ++]) |
| 114 | +-- |
| 115 | +2.17.1 |
| 116 | + |
0 commit comments