From 675702d95421a7f367d0c14e45063575eb97ff0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Barto=C5=88?= <radek.barton@microsoft.com>
Date: Mon, 9 Jun 2025 18:14:14 +0200
Subject: [PATCH 64/N] Cygwin: Fix compatibility with w32api headers v13

(cherry picked from commit 2029784e05d9805aa074dcadb99c31311790b7ac)
---
 winsup/cygwin/fhandler/socket_inet.cc  | 5 +++++
 winsup/cygwin/fhandler/socket_local.cc | 5 +++++
 winsup/cygwin/local_includes/ntdll.h   | 4 ++++
 winsup/cygwin/net.cc                   | 5 +++++
 4 files changed, 19 insertions(+)

diff --git a/winsup/cygwin/fhandler/socket_inet.cc b/winsup/cygwin/fhandler/socket_inet.cc
index 63cc498..24db244 100644
--- a/winsup/cygwin/fhandler/socket_inet.cc
+++ b/winsup/cygwin/fhandler/socket_inet.cc
@@ -20,7 +20,12 @@
 #undef u_long
 #define u_long __ms_u_long
 #include <w32api/ws2tcpip.h>
+/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
+   our socket.h. Arrange not to see it here. */
+#undef cmsghdr
+#define cmsghdr __ms_cmsghdr
 #include <w32api/mswsock.h>
+#undef cmsghdr
 #include <w32api/mstcpip.h>
 #include <netinet/tcp.h>
 #include <netinet/udp.h>
diff --git a/winsup/cygwin/fhandler/socket_local.cc b/winsup/cygwin/fhandler/socket_local.cc
index e4a8816..72b0720 100644
--- a/winsup/cygwin/fhandler/socket_local.cc
+++ b/winsup/cygwin/fhandler/socket_local.cc
@@ -21,7 +21,12 @@
 #define u_long __ms_u_long
 #include "ntsecapi.h"
 #include <w32api/ws2tcpip.h>
+/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
+   our socket.h. Arrange not to see it here. */
+#undef cmsghdr
+#define cmsghdr __ms_cmsghdr
 #include <w32api/mswsock.h>
+#undef cmsghdr
 #include <unistd.h>
 #include <asm/byteorder.h>
 #include <sys/socket.h>
diff --git a/winsup/cygwin/local_includes/ntdll.h b/winsup/cygwin/local_includes/ntdll.h
index aa1f3b9..f90a53b 100644
--- a/winsup/cygwin/local_includes/ntdll.h
+++ b/winsup/cygwin/local_includes/ntdll.h
@@ -474,6 +474,8 @@ typedef struct _FILE_DISPOSITION_INFORMATION_EX	// 64
   ULONG Flags;
 } FILE_DISPOSITION_INFORMATION_EX, *PFILE_DISPOSITION_INFORMATION_EX;
 
+#if __MINGW64_VERSION_MAJOR < 13
+
 typedef struct _FILE_STAT_INFORMATION		// 68
 {
   LARGE_INTEGER FileId;
@@ -494,6 +496,8 @@ typedef struct _FILE_CASE_SENSITIVE_INFORMATION	// 71
   ULONG Flags;
 } FILE_CASE_SENSITIVE_INFORMATION, *PFILE_CASE_SENSITIVE_INFORMATION;
 
+#endif
+
 enum {
   FILE_LINK_REPLACE_IF_EXISTS				= 0x01,
   FILE_LINK_POSIX_SEMANTICS				= 0x02,
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 8840d5e..c8f63be 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -18,7 +18,12 @@ details. */
 #undef u_long
 #define u_long __ms_u_long
 #include <w32api/ws2tcpip.h>
+/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
+   our socket.h. Arrange not to see it here. */
+#undef cmsghdr
+#define cmsghdr __ms_cmsghdr
 #include <w32api/mswsock.h>
+#undef cmsghdr
 #include <w32api/iphlpapi.h>
 #define gethostname cygwin_gethostname
 #include <unistd.h>
