Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/util/env.c (802B)
1 #include <stdlib.h>
2 #include <string.h>
3 #include <wlr/util/log.h>
4 #include "util/env.h"
5
6 bool env_parse_bool(const char *option) {
7 const char *env = getenv(option);
8 if (env) {
9 wlr_log(WLR_INFO, "Loading %s option: %s", option, env);
10 }
11
12 if (!env || strcmp(env, "0") == 0) {
13 return false;
14 } else if (strcmp(env, "1") == 0) {
15 return true;
16 }
17
18 wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env);
19 return false;
20 }
21
22 size_t env_parse_switch(const char *option, const char **switches) {
23 const char *env = getenv(option);
24 if (env) {
25 wlr_log(WLR_INFO, "Loading %s option: %s", option, env);
26 } else {
27 return 0;
28 }
29
30 for (ssize_t i = 0; switches[i]; i++) {
31 if (strcmp(env, switches[i]) == 0) {
32 return i;
33 }
34 }
35
36 wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env);
37 return 0;
38 }