1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) Michael Haardt 2015 */
6 /* Copyright (c) Jeremy Harris 2015 - 2016 */
7 /* See the file NOTICE for conditions of use and distribution. */
9 /* This module provides (un)setenv routines for those environments
10 lacking them in libraries. It is #include'd by OS/os.c-foo files. */
14 setenv(const char * name, const char * val, int overwrite)
17 if (Ustrchr(name, '=')) return -1;
18 if (overwrite || !getenv(name))
19 putenv(CS string_copy_malloc(string_sprintf("%s=%s", name, val)));
24 unsetenv(const char *name)
29 extern char ** environ;
40 for (end = name; *end != '=' && *end; ) end++;
43 /* Find name in environment and move remaining variables down.
44 Do not early-out in case there are duplicate names. */
46 for (e = environ; *e; e++)
47 if (strncmp(*e, name, len) == 0 && (*e)[len] == '=')
50 do *sp = sp[1]; while (*++sp);