Browse Source

Move setenv compat code to porting.h

sfan5 3 months ago
parent
commit
6f494a968d
3 changed files with 9 additions and 17 deletions
  1. 1 5
      src/gettext.cpp
  2. 8 4
      src/porting.h
  3. 0 8
      src/unittest/test_servermodmanager.cpp

+ 1 - 5
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>

+ 8 - 4
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)

+ 0 - 8
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);