aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_getenv__.c
diff options
context:
space:
mode:
Diffstat (limited to 'libfonts_getenv__.c')
-rw-r--r--libfonts_getenv__.c30
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);
+}