File: env.c

package info (click to toggle)
wlroots 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,592 kB
  • sloc: ansic: 75,766; xml: 2,739; sh: 33; makefile: 23
file content (38 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}

size_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;
}