]>
diplodocus.org Git - nmh/blob - sbr/putenv.c
3 * putenv.c -- (un)set an envariable
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
14 extern char **environ
;
19 int m_putenv (char *, char *);
20 int unputenv (char *);
21 static int nvmatch (char *, char *);
25 m_putenv (char *name
, char *value
)
28 register char **ep
, **nep
, *cp
;
30 if (!(cp
= malloc ((size_t) (strlen (name
) + strlen (value
) + 2))))
33 sprintf (cp
, "%s=%s", name
, value
);
35 for (ep
= environ
, i
= 0; *ep
; ep
++, i
++)
36 if (nvmatch (name
, *ep
)) {
41 if (!(nep
= (char **) malloc ((size_t) ((i
+ 2) * sizeof(*nep
)))))
44 for (ep
= environ
, i
= 0; *ep
; nep
[i
++] = *ep
++)
58 for (ep
= environ
; *ep
; ep
++)
59 if (nvmatch (name
, *ep
))
64 for (nep
= ep
+ 1; *nep
; nep
++)
73 nvmatch (char *s1
, char *s2
)
79 return (*s1
== '\0' && *--s2
== '=');