summaryrefslogtreecommitdiffstats
path: root/util/system/env.cpp
diff options
context:
space:
mode:
authormvel <[email protected]>2022-02-10 16:45:41 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:41 +0300
commit43f5a35593ebc9f6bcea619bb170394ea7ae468e (patch)
treee98df59de24d2ef7c77baed9f41e4875a2fef972 /util/system/env.cpp
parentbd30392c4cc92487950adc375c07adf52da1d592 (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'util/system/env.cpp')
-rw-r--r--util/system/env.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/util/system/env.cpp b/util/system/env.cpp
index edc539a7023..ead9b566a5f 100644
--- a/util/system/env.cpp
+++ b/util/system/env.cpp
@@ -1,8 +1,8 @@
-#include "env.h"
-
+#include "env.h"
+
#include <util/generic/string.h>
#include <util/generic/yexception.h>
-
+
#ifdef _win_
#include <util/generic/vector.h>
#include "winint.h"
@@ -10,7 +10,7 @@
#include <cerrno>
#include <cstdlib>
#endif
-
+
/**
* On Windows there may be many copies of enviroment variables, there at least two known, one is
* manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of
@@ -22,7 +22,7 @@
*/
TString GetEnv(const TString& key, const TString& def) {
-#ifdef _win_
+#ifdef _win_
size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0);
if (len == 0) {
@@ -43,25 +43,25 @@ TString GetEnv(const TString& key, const TString& def) {
} while (len > bufferSize);
return TString(buffer.data(), len);
-#else
+#else
const char* env = getenv(key.data());
return env ? TString(env) : def;
-#endif
-}
-
+#endif
+}
+
void SetEnv(const TString& key, const TString& value) {
bool isOk = false;
int errorCode = 0;
-#ifdef _win_
+#ifdef _win_
isOk = SetEnvironmentVariable(key.data(), value.data());
if (!isOk) {
errorCode = GetLastError();
}
-#else
+#else
isOk = (0 == setenv(key.data(), value.data(), true /*replace*/));
if (!isOk) {
errorCode = errno;
}
-#endif
+#endif
Y_ENSURE_EX(isOk, TSystemError() << "failed to SetEnv with error-code " << errorCode);
-}
+}