3 * putenv.c -- (un)set an envariable
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 extern char **environ;
18 int m_putenv (char *, char *);
19 int unputenv (char *);
20 static int nvmatch (char *, char *);
24 m_putenv (char *name, char *value)
27 register char **ep, **nep, *cp;
29 cp = mh_xmalloc ((size_t) (strlen (name) + strlen (value) + 2));
31 sprintf (cp, "%s=%s", name, value);
33 for (ep = environ, i = 0; *ep; ep++, i++)
34 if (nvmatch (name, *ep)) {
39 nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep)));
41 for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
55 for (ep = environ; *ep; ep++)
56 if (nvmatch (name, *ep))
61 for (nep = ep + 1; *nep; nep++)
70 nvmatch (char *s1, char *s2)
76 return (*s1 == '\0' && *--s2 == '=');