head 1.6; access; symbols; locks; strict; comment @ * @; 1.6 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.5; 1.5 date 92.11.04.00.37.05; author jromine; state Exp; branches; next 1.4; 1.4 date 90.04.05.15.32.08; author sources; state Exp; branches; next 1.3; 1.3 date 90.04.05.14.49.34; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.06.13.08.41; author sources; state Exp; branches; next 1.1; 1.1 date 90.02.06.13.06.05; author sources; state Exp; branches; next ; desc @ @ 1.6 log @endif sugar @ text @/* putenv.c - (un) set an envariable */ #ifndef lint static char ident[] = "@@(#)$Id: putenv.c,v 1.5 1992/11/04 00:37:05 jromine Exp jromine $"; #endif /* lint */ #include "../h/mh.h" #include extern char **environ; static nvmatch(); int m_putenv (name, value) register char *name, *value; { register int i; register char **ep, **nep, *cp; if ((cp = malloc ((unsigned) (strlen (name) + strlen (value) + 2))) == NULL) return 1; (void) sprintf (cp, "%s=%s", name, value); for (ep = environ, i = 0; *ep; ep++, i++) if (nvmatch (name, *ep)) { *ep = cp; return 0; } if ((nep = (char **) malloc ((unsigned) ((i + 2) * sizeof *nep))) == NULL) return 1; for (ep = environ, i = 0; *ep; nep[i++] = *ep++) continue; nep[i++] = cp; nep[i] = NULL; environ = nep; return 0; } int unputenv (name) char *name; { char **ep, **nep; for (ep = environ; *ep; ep++) if (nvmatch (name, *ep)) break; if (*ep == NULL) return 1; for (nep = ep + 1; *nep; nep++) continue; *ep = *--nep; *nep = NULL; return 0; } /* */ static nvmatch (s1, s2) register char *s1, *s2; { while (*s1 == *s2++) if (*s1++ == '=') return 1; return (*s1 == '\0' && *--s2 == '='); } @ 1.5 log @putenv -> m_putenv @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: putenv.c,v 1.4 1990/04/05 15:32:08 sources Exp jromine $"; #endif lint @ 1.4 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d14 1 a14 1 int putenv (name, value) @ 1.3 log @add ID @ text @d3 1 a3 1 static char ident[] = "$Id:"; @ 1.2 log @ANSI Compilance @ text @d2 3 @ 1.1 log @Initial revision @ text @d9 1 @