1 /* putenv.c - (un) set an envariable */
3 static char ident[] = "@(#)$Id: putenv.c,v 1.6 1992/12/15 00:20:22 jromine Exp $";
10 extern char **environ;
14 int m_putenv (name, value)
23 if ((cp = malloc ((unsigned) (strlen (name) + strlen (value) + 2)))
26 (void) sprintf (cp, "%s=%s", name, value);
28 for (ep = environ, i = 0; *ep; ep++, i++)
29 if (nvmatch (name, *ep)) {
34 if ((nep = (char **) malloc ((unsigned) ((i + 2) * sizeof *nep))) == NULL)
36 for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
51 for (ep = environ; *ep; ep++)
52 if (nvmatch (name, *ep))
57 for (nep = ep + 1; *nep; nep++)
66 static nvmatch (s1, s2)
74 return (*s1 == '\0' && *--s2 == '=');