From 6f494a968d28d73a42ceaa03e6cc26d349f30f97 Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Wed, 10 Jan 2024 19:21:16 +0100
Subject: [PATCH] Move setenv compat code to porting.h

---
 src/gettext.cpp                        |  6 +-----
 src/porting.h                          | 12 ++++++++----
 src/unittest/test_servermodmanager.cpp |  8 --------
 3 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/gettext.cpp b/src/gettext.cpp
index 49eb0981a..68b6f728a 100644
--- a/src/gettext.cpp
+++ b/src/gettext.cpp
@@ -20,15 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <string>
 #include <cstring>
 #include <iostream>
-#include <cstdlib>
 #include "gettext.h"
 #include "util/string.h"
+#include "porting.h"
 #include "log.h"
 
-#ifdef _WIN32
-#define setenv(n,v,o) _putenv_s(n,v)
-#endif
-
 #if USE_GETTEXT && defined(_MSC_VER)
 #include <windows.h>
 #include <map>
diff --git a/src/porting.h b/src/porting.h
index cd710d191..ad707cebe 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -23,6 +23,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #pragma once
 
+#if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
+	#define _GNU_SOURCE
+#endif
+
 #include <string>
 #include <vector>
 #include "irrlicht.h"
@@ -43,12 +47,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 	#define sleep_ms(x) Sleep(x)
 	#define sleep_us(x) Sleep((x)/1000)
+
+	#define setenv(n,v,o) _putenv_s(n,v)
+	#define unsetenv(n) _putenv_s(n,"")
 #else
 	#include <unistd.h>
-
-	#if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
-		#define _GNU_SOURCE
-	#endif
+	#include <cstdlib> // setenv
 
 	#define sleep_ms(x) usleep((x)*1000)
 	#define sleep_us(x) usleep(x)
diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp
index e9f10b2c1..30b02f184 100644
--- a/src/unittest/test_servermodmanager.cpp
+++ b/src/unittest/test_servermodmanager.cpp
@@ -67,15 +67,7 @@ void TestServerModManager::runTests(IGameDef *gamedef)
 		ofs2 << "-- intentionally empty\n";
 	}
 
-#ifdef WIN32
-	{
-		std::string mod_path("MINETEST_MOD_PATH=");
-		mod_path.append(test_mods);
-		_putenv(mod_path.c_str());
-	}
-#else
 	setenv("MINETEST_MOD_PATH", test_mods.c_str(), 1);
-#endif
 
 	m_worlddir = getTestTempDirectory().append(DIR_DELIM "world");
 	fs::CreateDir(m_worlddir);