X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/30ef6099db9a7e26e55e9c58d8e1c0f79a95b06f..06cf6fdcb4b33f3751ec8d121c98e00553c8b069:/src/src/setenv.c diff --git a/src/src/setenv.c b/src/src/setenv.c new file mode 100644 index 000000000..6da56d58d --- /dev/null +++ b/src/src/setenv.c @@ -0,0 +1,55 @@ +/************************************************* +* Exim - an Internet mail transport agent * +*************************************************/ + +/* Copyright (c) Michael Haardt 2015 */ +/* Copyright (c) Jeremy Harris 2015 */ +/* See the file NOTICE for conditions of use and distribution. */ + +/* This module provides (un)setenv routines for those environments +lacking them in libraries. */ + + +static int +setenv(const char * name, const char * val, int overwrite) +{ +uschar * s; +if (Ustrchr(name, '=')) return -1; +if (overwrite || !getenv(name)) + putenv(CS string_copy_malloc(string_sprintf("%s=%s", name, val))); +return 0; +} + +static int +unsetenv(const char *name) +{ +size_t len; +const char * end; +char ** e; +extern char ** environ; + +if (!name) + { + errno = EINVAL; + return -1; + } + +for (end = name; *end != '=' && *end; ) end++; +len = end - name; + +/* Find name in environment and move remaining variables down. +Do not early-out in case there are duplicate names. */ + +for (e = environ; *e; e++) + if (strncmp(*e, name, len) == 0 && (*e)[len] == '=') + { + char ** sp = e; + do *sp = sp[1]; while (*++sp); + } + +return 0; +} + +/* vi: aw ai sw=2 +*/ +/* End of setenv.c */