From 669818e186bbd16bc0cfcdc444677e64332eb719 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 5 Dec 2024 23:51:57 +1300
Subject: [PATCH 2/2] Fix warnings about declaration of environ on MinGW.

POSIX says that the global variable environ shouldn't be declared in a
header, and you have to declare it yourself, as we do in three places.
Windows declares it in <stdlib.h>, and then MinGW warns that our
redeclarations lacks a dllimport attribute, as seen on CI and fairywren.
Let's just hide our declarations from Windows.
---
 src/backend/postmaster/postmaster.c | 2 ++
 src/backend/utils/misc/ps_status.c  | 3 +++
 src/test/regress/regress.c          | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index ce00f4032ee..450ef7f6e0d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -854,7 +854,9 @@ PostmasterMain(int argc, char *argv[])
 	/* For debugging: display postmaster environment */
 	if (message_level_is_interesting(DEBUG3))
 	{
+#ifndef WIN32
 		extern char **environ;
+#endif
 		char	  **p;
 		StringInfoData si;
 
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 9da63774020..f4ec7051037 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -23,7 +23,10 @@
 #include "utils/guc.h"
 #include "utils/ps_status.h"
 
+
+#ifndef WIN32
 extern char **environ;
+#endif
 
 /* GUC variable */
 bool		update_process_title = DEFAULT_UPDATE_PROCESS_TITLE;
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 8309166f5b2..f0aaa620302 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -647,7 +647,9 @@ PG_FUNCTION_INFO_V1(get_environ);
 Datum
 get_environ(PG_FUNCTION_ARGS)
 {
+#ifndef WIN32
 	extern char **environ;
+#endif
 	int			nvals = 0;
 	ArrayType  *result;
 	Datum	   *env;
-- 
2.39.5

