Kea 3.1.0
env_var_wrapper.cc
Go to the documentation of this file.
1// Copyright (C) 2025 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
11namespace isc {
12namespace test {
13
14EnvVarWrapper::EnvVarWrapper(const std::string& name) : name_(name) {
15 original_value_ = getValue();
16}
17
19 setValue(original_value_);
20}
21
22std::string
24 return (original_value_);
25}
26
27std::string
29 auto value = getenv(name_.c_str());
30 return (value ? std::string(value) : std::string(""));
31}
32
33void
34EnvVarWrapper::setValue(const std::string value /* = "" */) {
35 if (value.empty()) {
36 unsetenv(name_.c_str());
37 } else {
38 setenv(name_.c_str(), value.c_str(), 1);
39 }
40}
41
42} // end of isc::test namespace
43} // 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.