Skip to content

Commit 7d76a2a

Browse files
committed
Fix MinGW compatibility in helper.cpp
1 parent 6722f0c commit 7d76a2a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

examples/desktop/utils/helper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ int promptSelection(const char* prompt, int defaultValue, int maxValue) {
9191

9292
std::string getEnvironmentValue(const char* name) {
9393
#if defined(_WIN32) || defined(_WIN64)
94+
#if defined(__MINGW32__) || defined(__MINGW64__)
95+
// MinGW doesn't支持 _dupenv_s,使用 getenv 替代
96+
const char* rawValue = std::getenv(name);
97+
return rawValue != nullptr ? std::string(rawValue) : std::string();
98+
#else
9499
char* rawValue = nullptr;
95100
size_t rawLength = 0;
96101
if (_dupenv_s(&rawValue, &rawLength, name) != 0 || rawValue == nullptr) {
@@ -100,6 +105,7 @@ std::string getEnvironmentValue(const char* name) {
100105
std::string value(rawValue);
101106
std::free(rawValue);
102107
return value;
108+
#endif
103109
#else
104110
const char* rawValue = std::getenv(name);
105111
return rawValue != nullptr ? std::string(rawValue) : std::string();

0 commit comments

Comments
 (0)