2 ** putenv.c -- (un)set an envariable
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
12 extern char **environ;
17 int m_putenv(char *, char *);
19 static int nvmatch(char *, char *);
23 m_putenv(char *name, char *value)
26 char **ep, **nep, *cp;
28 cp = mh_xmalloc((size_t) (strlen(name) + strlen(value) + 2));
30 sprintf(cp, "%s=%s", name, value);
32 for (ep = environ, i = 0; *ep; ep++, i++)
33 if (nvmatch(name, *ep)) {
38 nep = (char **) mh_xmalloc((size_t) ((i + 2) * sizeof(*nep)));
40 for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
54 for (ep = environ; *ep; ep++)
55 if (nvmatch(name, *ep))
60 for (nep = ep + 1; *nep; nep++)
69 nvmatch(char *s1, char *s2)
75 return (*s1 == '\0' && *--s2 == '=');