Skip to content

Commit a513534

Browse files
committed
futils: use _dupenv_s
getenv is deprecatred on Windows Signed-off-by: Rosen Penev <[email protected]>
1 parent 68fdd17 commit a513534

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/futils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,18 @@ std::string getEnv(int env_var) {
9393
// this check is relying on undefined behavior and might not be effective
9494
if (env_var < envHTTPPOST || env_var > envTIMEOUT)
9595
throw std::out_of_range("Unexpected env variable");
96+
#ifdef _WIN32
97+
char* buf = nullptr;
98+
size_t len;
99+
if (_dupenv_s(&buf, &len, ENVARKEY[env_var]) == 0 && buf) {
100+
auto ret = std::string(buf);
101+
free(buf);
102+
return ret;
103+
}
104+
#else
96105
if (auto val = std::getenv(ENVARKEY[env_var]))
97106
return val;
107+
#endif
98108
return ENVARDEF[env_var];
99109
}
100110

0 commit comments

Comments
 (0)