diff options
author | Alexander Orzechowski <orzechowski.alexander@gmail.com> | 2022-08-19 09:59:30 -0400 |
---|---|---|
committer | Alexander Orzechowski <orzechowski.alexander@gmail.com> | 2022-08-22 10:18:00 -0400 |
commit | 31a9fc1fb60f8001f43186d36e3fbb5fce584d91 (patch) | |
tree | cebed6db21a55f5d1c0f6598e32ea52724235a5e /util/env.c | |
parent | e7477c71147617572c98a7daaf5934d4ad848d2a (diff) |
util: Introduce env helpers
Diffstat (limited to 'util/env.c')
-rw-r--r-- | util/env.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/util/env.c b/util/env.c new file mode 100644 index 00000000..b0a9efda --- /dev/null +++ b/util/env.c @@ -0,0 +1,38 @@ +#include <stdlib.h> +#include <string.h> +#include <wlr/util/log.h> +#include "util/env.h" + +bool env_parse_bool(const char *option) { + const char *env = getenv(option); + if (env) { + wlr_log(WLR_INFO, "Loading %s option: %s", option, env); + } + + if (!env || strcmp(env, "0") == 0) { + return false; + } else if (strcmp(env, "1") == 0) { + return true; + } + + wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env); + return false; +} + +ssize_t env_parse_switch(const char *option, const char **switches) { + const char *env = getenv(option); + if (env) { + wlr_log(WLR_INFO, "Loading %s option: %s", option, env); + } else { + return 0; + } + + for (ssize_t i = 0; switches[i]; i++) { + if (strcmp(env, switches[i]) == 0) { + return i; + } + } + + wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env); + return 0; +} |