Skip to content

Commit dc37fea

Browse files
committed
gnulib: fix stat/fstat build errors on old Windows version or using old MinGW
This commit imports two commits from gnulib's master branch fixing a build error when building on a version of Windows that's older than Vista, or when using an mingw's MinGW. gnulib/ChangeLog: GDB PR build/26607 * patches/0002-stat-fstat-windows-older-vista: New patch. * patches/0003-stat-fstat-windows-old-mingw: New patch. * update-gnulib.sh: Update to use the two new patches above. * import/m4/fstat.m4: Update after applying patches above. * import/m4/stat.m4: Ditto. * import/stat-w32.c: Ditto. * config.in: Regenerate. * configure: Regenerate.
1 parent 114f9fd commit dc37fea

9 files changed

Lines changed: 229 additions & 8 deletions

File tree

gnulib/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-10-09 Joel Brobecker <brobecker@adacore.com>
2+
3+
GDB PR build/26607
4+
* patches/0002-stat-fstat-windows-older-vista: New patch.
5+
* patches/0003-stat-fstat-windows-old-mingw: New patch.
6+
* update-gnulib.sh: Update to use the two new patches above.
7+
* import/m4/fstat.m4: Update after applying patches above.
8+
* import/m4/stat.m4: Ditto.
9+
* import/stat-w32.c: Ditto.
10+
* config.in: Regenerate.
11+
* configure: Regenerate.
12+
113
2020-09-08 Tom Tromey <tromey@adacore.com>
214

315
PR win32/25302:

gnulib/config.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@
693693
/* Define to 1 if the system has the type `sa_family_t'. */
694694
#undef HAVE_SA_FAMILY_T
695695

696+
/* Define to 1 if you have the <sdkddkver.h> header file. */
697+
#undef HAVE_SDKDDKVER_H
698+
696699
/* Define to 1 if you have the <search.h> header file. */
697700
#undef HAVE_SEARCH_H
698701

gnulib/configure

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10107,6 +10107,25 @@ fi
1010710107

1010810108

1010910109

10110+
10111+
case "$host_os" in
10112+
mingw*)
10113+
for ac_header in sdkddkver.h
10114+
do :
10115+
ac_fn_c_check_header_mongrel "$LINENO" "sdkddkver.h" "ac_cv_header_sdkddkver_h" "$ac_includes_default"
10116+
if test "x$ac_cv_header_sdkddkver_h" = xyes; then :
10117+
cat >>confdefs.h <<_ACEOF
10118+
#define HAVE_SDKDDKVER_H 1
10119+
_ACEOF
10120+
10121+
fi
10122+
10123+
done
10124+
10125+
;;
10126+
esac
10127+
10128+
1011010129
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5
1011110130
$as_echo_n "checking whether lstat correctly handles trailing slash... " >&6; }
1011210131
if ${gl_cv_func_lstat_dereferences_slashed_symlink+:} false; then :
@@ -19576,6 +19595,7 @@ $as_echo "#define GNULIB_TEST_FREXPL 1" >>confdefs.h
1957619595
esac
1957719596

1957819597

19598+
1957919599
:
1958019600

1958119601
fi
@@ -27005,6 +27025,7 @@ $as_echo "#define REPLACE_FUNC_STAT_FILE 1" >>confdefs.h
2700527025
esac
2700627026

2700727027

27028+
2700827029
:
2700927030

2701027031
fi

gnulib/import/m4/fstat.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fstat.m4 serial 6
1+
# fstat.m4 serial 7
22
dnl Copyright (C) 2011-2020 Free Software Foundation, Inc.
33
dnl This file is free software; the Free Software Foundation
44
dnl gives unlimited permission to copy and/or distribute it,
@@ -35,5 +35,6 @@ AC_DEFUN([gl_FUNC_FSTAT],
3535
# Prerequisites of lib/fstat.c and lib/stat-w32.c.
3636
AC_DEFUN([gl_PREREQ_FSTAT], [
3737
AC_REQUIRE([gl_HEADER_SYS_STAT_H])
38+
AC_REQUIRE([gl_PREREQ_STAT_W32])
3839
:
3940
])

gnulib/import/m4/stat.m4

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# serial 16
1+
# serial 17
22

33
# Copyright (C) 2009-2020 Free Software Foundation, Inc.
44
#
@@ -70,5 +70,16 @@ AC_DEFUN([gl_FUNC_STAT],
7070
# Prerequisites of lib/stat.c and lib/stat-w32.c.
7171
AC_DEFUN([gl_PREREQ_STAT], [
7272
AC_REQUIRE([gl_HEADER_SYS_STAT_H])
73+
AC_REQUIRE([gl_PREREQ_STAT_W32])
7374
:
7475
])
76+
77+
# Prerequisites of lib/stat-w32.c.
78+
AC_DEFUN([gl_PREREQ_STAT_W32], [
79+
AC_REQUIRE([AC_CANONICAL_HOST])
80+
case "$host_os" in
81+
mingw*)
82+
AC_CHECK_HEADERS([sdkddkver.h])
83+
;;
84+
esac
85+
])

gnulib/import/stat-w32.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@
2020

2121
#if defined _WIN32 && ! defined __CYGWIN__
2222

23-
/* Ensure that <windows.h> defines FILE_ID_INFO. */
24-
#if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
25-
# undef _WIN32_WINNT
26-
# define _WIN32_WINNT _WIN32_WINNT_WIN8
23+
/* Attempt to make <windows.h> define FILE_ID_INFO.
24+
But ensure that the redefinition of _WIN32_WINNT does not make us assume
25+
Windows Vista or newer when building for an older version of Windows. */
26+
#if HAVE_SDKDDKVER_H
27+
# include <sdkddkver.h>
28+
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
29+
# define WIN32_ASSUME_VISTA 1
30+
# else
31+
# define WIN32_ASSUME_VISTA 0
32+
# endif
33+
# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
34+
# undef _WIN32_WINNT
35+
# define _WIN32_WINNT _WIN32_WINNT_WIN8
36+
# endif
37+
#else
38+
# define WIN32_ASSUME_VISTA (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
2739
#endif
2840

2941
#include <sys/types.h>
@@ -46,7 +58,12 @@
4658
#undef GetFinalPathNameByHandle
4759
#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
4860

49-
#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
61+
/* Older mingw headers do not define VOLUME_NAME_NONE. */
62+
#ifndef VOLUME_NAME_NONE
63+
# define VOLUME_NAME_NONE 4
64+
#endif
65+
66+
#if !WIN32_ASSUME_VISTA
5067

5168
/* Avoid warnings from gcc -Wcast-function-type. */
5269
# define GetProcAddress \
@@ -149,7 +166,7 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
149166
DWORD type = GetFileType (h);
150167
if (type == FILE_TYPE_DISK)
151168
{
152-
#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
169+
#if !WIN32_ASSUME_VISTA
153170
if (!initialized)
154171
initialize ();
155172
#endif
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From f8c23f202d11992182e87736e73929bcc369cc75 Mon Sep 17 00:00:00 2001
2+
From: Bruno Haible <bruno@clisp.org>
3+
Date: Wed, 16 Sep 2020 23:52:44 +0200
4+
Subject: [PATCH 2/2] stat, fstat: Fix compilation error with old mingw
5+
headers.
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 (VOLUME_NAME_NONE): Define if the Windows headers don't
11+
define it.
12+
---
13+
stat-w32.c | 5 +++++
14+
2 files changed, 13 insertions(+)
15+
16+
diff --git a/gnulib/import/stat-w32.c b/gnulib/import/stat-w32.c
17+
index 72442e933..108ce199c 100644
18+
--- a/gnulib/import/stat-w32.c
19+
+++ b/gnulib/import/stat-w32.c
20+
@@ -58,6 +58,11 @@
21+
#undef GetFinalPathNameByHandle
22+
#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
23+
24+
+/* Older mingw headers do not define VOLUME_NAME_NONE. */
25+
+#ifndef VOLUME_NAME_NONE
26+
+# define VOLUME_NAME_NONE 4
27+
+#endif
28+
+
29+
#if !WIN32_ASSUME_VISTA
30+
31+
/* Avoid warnings from gcc -Wcast-function-type. */
32+
--
33+
2.17.1
34+

gnulib/update-gnulib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ apply_patches ()
174174
}
175175

176176
apply_patches "patches/0001-use-windows-stat"
177+
# The following two patches are specific imports of two commits
178+
# already in gnulib's master. We import those patches individually
179+
# because we want to avoid doing a standard gnulib update, which
180+
# would be too disruptive for a release branch.
181+
apply_patches "patches/0002-stat-fstat-windows-older-vista"
182+
apply_patches "patches/0003-stat-fstat-windows-old-mingw"
177183

178184
# Regenerate all necessary files...
179185
aclocal &&

0 commit comments

Comments
 (0)