]>
diplodocus.org Git - nmh/blob - sbr/putenv.c
1 /* putenv.c -- (un)set an envariable
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
11 extern char **environ
;
16 int m_putenv (char *, char *);
17 int unputenv (char *);
18 static int nvmatch (char *, char *);
20 /* FIXME: These functions leak memory. No easy fix since they might not
21 * be malloc'd. Switch to setenv(3) and unsetenv(3). */
24 m_putenv (char *name
, char *value
)
27 char **ep
, **nep
, *cp
;
29 cp
= concat(name
, "=", value
, NULL
);
31 for (ep
= environ
, i
= 0; *ep
; ep
++, i
++)
32 if (nvmatch (name
, *ep
)) {
37 nep
= (char **) mh_xmalloc ((size_t) ((i
+ 2) * sizeof(*nep
)));
39 for (ep
= environ
, i
= 0; *ep
; nep
[i
++] = *ep
++)
53 for (ep
= environ
; *ep
; ep
++)
54 if (nvmatch (name
, *ep
))
59 for (nep
= ep
+ 1; *nep
; nep
++)
68 nvmatch (char *s1
, char *s2
)
74 return (*s1
== '\0' && *--s2
== '=');