]>
diplodocus.org Git - nmh/blob - sbr/putenv.c
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 *);
22 /* FIXME: These functions leak memory. No easy fix since they might not
23 * be malloc'd. Switch to setenv(3) and unsetenv(3). */
26 m_putenv (char *name
, char *value
)
29 char **ep
, **nep
, *cp
;
31 cp
= concat(name
, "=", value
, NULL
);
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
== '=');