Zth (libzth)
Loading...
Searching...
No Matches
config.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 */
6
7#include <libzth/config.h>
8
9#include <libzth/util.h>
10
11#include <cstdlib>
12#include <cstring>
13
14namespace zth {
15
19static bool config(char const* name, bool whenUnset)
20{
21 // NOLINTNEXTLINE(concurrency-mt-unsafe)
22 char const* e = getenv(name);
23
24 if(!e || !*e)
25 return whenUnset;
26 else if(strcmp(e, "0") == 0)
27 // Explicitly set to disabled
28 return false;
29 else
30 // Any other value is true
31 return true;
32}
33
39bool config(int env, bool whenUnset)
40{
41 switch(env) {
42 case Env::EnableDebugPrint: {
43 static bool const e = Config::SupportDebugPrint
44 && config("ZTH_CONFIG_ENABLE_DEBUG_PRINT", whenUnset);
45 return e;
46 }
47 case Env::DoPerfEvent: {
48 static bool const e = config("ZTH_CONFIG_DO_PERF_EVENT", whenUnset);
49 return e;
50 }
51 case Env::PerfSyscall: {
52 static bool const e = config("ZTH_CONFIG_PERF_SYSCALL", whenUnset);
53 return e;
54 }
55 case Env::CheckTimesliceOverrun: {
56 static bool const e = config("ZTH_CONFIG_CHECK_TIMESLICE_OVERRUN", whenUnset);
57 return e;
58 }
59 default:
60 return whenUnset;
61 }
62}
63
64} // namespace zth
bool config(int env, bool whenUnset)
Checks if a given environment option is set.
Definition config.cpp:39