diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-08 16:23:56 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-08 16:23:56 +0100 |
commit | 627e5b9789c663343c74dac6535724ddc63aae1c (patch) | |
tree | af78890b546b774267ff82520f0756dd159f8d86 /libfonts_getenv__.c | |
parent | Improve libfonts_get_default_font_name and draft implementation of libfonts_get_default_font (diff) | |
download | libfonts-627e5b9789c663343c74dac6535724ddc63aae1c.tar.gz libfonts-627e5b9789c663343c74dac6535724ddc63aae1c.tar.bz2 libfonts-627e5b9789c663343c74dac6535724ddc63aae1c.tar.xz |
Add environment spoofing
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libfonts_getenv__.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libfonts_getenv__.c b/libfonts_getenv__.c new file mode 100644 index 0000000..d998337 --- /dev/null +++ b/libfonts_getenv__.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +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); +} |