Kea 3.1.7
env_var_wrapper.cc
Go to the documentation of this file.
1// Copyright (C) 2025-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
10
11#include <cstdlib>
12
13namespace isc {
14namespace test {
15
16EnvVarWrapper::EnvVarWrapper(const std::string& name) : name_(name) {
17 original_value_ = getValue();
18}
19
21 setValue(original_value_);
22}
23
24std::string
26 return (original_value_);
27}
28
29std::string
31 auto value = getenv(name_.c_str());
32 return (value ? std::string(value) : std::string(""));
33}
34
35void
36EnvVarWrapper::setValue(const std::string value /* = "" */) {
37 if (value.empty()) {
38 unsetenv(name_.c_str());
39 } else {
40 setenv(name_.c_str(), value.c_str(), 1);
41 }
42}
43
44} // end of isc::test namespace
45} // end of isc namespace
EnvVarWrapper(const std::string &name)
Constructor.
void setValue(const std::string value="")
Sets the current value of the env variable.
std::string getOriginalValue() const
Fetches the original value of the env variable.
std::string getValue() const
Fetches the current value of the env variable.
Defines the logger used by the top-level component of kea-lfc.