aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/env.cpp
diff options
context:
space:
mode:
authormvel <mvel@yandex-team.ru>2022-02-10 16:45:41 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:41 +0300
commitbd30392c4cc92487950adc375c07adf52da1d592 (patch)
treee8d1a3f19b7fc890bcef6e4cc5de41f1d88c9ac3 /util/system/env.cpp
parent5d50718e66d9c037dc587a0211110b7d25a66185 (diff)
downloadydb-bd30392c4cc92487950adc375c07adf52da1d592.tar.gz
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 1 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 ead9b566a5..edc539a702 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);
-}
+}