aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/env.h
diff options
context:
space:
mode:
authorswarmer <swarmer@yandex-team.com>2024-05-16 22:29:38 +0300
committerswarmer <swarmer@yandex-team.com>2024-05-16 22:39:53 +0300
commita8049e5a7b933c56ae14a3fd55af1f85f2978b37 (patch)
tree4d26cccf4f5afada30a025eb48e3115244e83d37 /util/system/env.h
parent513eef24a8977ea56fab098fb4531f224e0890c9 (diff)
downloadydb-a8049e5a7b933c56ae14a3fd55af1f85f2978b37.tar.gz
[util] Implement TryGetEnv and UnsetEnv functions
The TryGetEnv function can be used to distinguish the case when a variable is not defined from the case when it has an empty value. 4aab7a2a39f4b9107b0b1d1ef639dc2c41c04f42
Diffstat (limited to 'util/system/env.h')
-rw-r--r--util/system/env.h34
1 files changed, 32 insertions, 2 deletions
diff --git a/util/system/env.h b/util/system/env.h
index e2ccdd1e95..55f43bd9b8 100644
--- a/util/system/env.h
+++ b/util/system/env.h
@@ -1,5 +1,6 @@
#pragma once
+#include <util/generic/fwd.h>
#include <util/generic/string.h>
/**
@@ -19,10 +20,27 @@
TString GetEnv(const TString& key, const TString& def = TString());
/**
+ * Search the environment list provided by the host environment for associated variable.
+ *
+ * @param key String identifying the name of the environmental variable to look for
+ *
+ * @return String that is associated with the matched environment
+ * variable or empty optional value if such variable is missing.
+ *
+ * @throws TSystemError If name of the variable has invalid format
+ *
+ * @note Use it only in pair with `SetEnv` as there may be inconsistency
+ * in their behaviour otherwise.
+ * @note Calls to `TryGetEnv` and `SetEnv` from different threads must be synchronized.
+ * @see SetEnv
+ */
+TMaybe<TString> TryGetEnv(const TString& key);
+
+/**
* Add or change environment variable provided by the host environment.
*
- * @key String identifying the name of the environment variable to set or change
- * @value Value to assign
+ * @param key String identifying the name of the environment variable to set or change
+ * @param value Value to assign
* @note Use it only in pair with `GetEnv` as there may be inconsistency in their behaviour
* otherwise.
@@ -30,3 +48,15 @@ TString GetEnv(const TString& key, const TString& def = TString());
* @see GetEnv
*/
void SetEnv(const TString& key, const TString& value);
+
+/**
+ * Remove environment variable from the host environment.
+ *
+ * @param key String identifying the name of the environment variable to remove
+ *
+ * @note If key does not exist in the environment, then the environment is unchanged,
+ * and the function returns normally.
+ * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized.
+ * @see GetEnv
+ */
+void UnsetEnv(const TString& key);