aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_getenv__.c
blob: fd5b1d35c9aac7685c8ebfdcdb45e60d21f5a928 (plain) (blame)
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
39
40
41
42
43
44
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


const char *
libfonts_getenv__(const char *name, struct libfonts_context *ctx)
{
	char **envp;
	size_t len = strlen(name);

#ifdef VALIDATE
	size_t i;
	if (!name) {
		fprintf(stderr, "`name` parameter in libfonts_getenv__ is NULL\n");
		abort();
	}
	for (i = 0; libfonts_used_environs[i]; i++)
		if (!strcmp(name, libfonts_used_environs[i]))
			goto ok;
	fprintf(stderr, "Value of `name` parameter (\"%s\") in libfonts_getenv__ is not in libfonts_used_environs\n", name);
	abort();
ok:
#endif

	if (ctx && ctx->environ)
		for (envp = ctx->environ; *envp; envp++)
			if (strncmp(*envp, name, len) && (*envp)[len] == '=')
				return *envp;
	return ctx->ignore_process_environ ? NULL : getenv(name);
}


#else


int
main(void)
{
	return 0; /* XXX add test */
}


#endif