]> diplodocus.org Git - nmh/blobdiff - sbr/putenv.c
Editing of man/mh-tailor.man.
[nmh] / sbr / putenv.c
index 649b0152debdaa9132b0373fd705ca13d9037cb0..5266d63ee65395a7acba2e1c448a825a3dc2c0ff 100644 (file)
@@ -2,14 +2,13 @@
 /*
  * putenv.c -- (un)set an envariable
  *
 /*
  * putenv.c -- (un)set an envariable
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
 #include <h/mh.h>
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 
 extern char **environ;
 
 
 extern char **environ;
 
@@ -20,17 +19,16 @@ int m_putenv (char *, char *);
 int unputenv (char *);
 static int nvmatch (char *, char *);
 
 int unputenv (char *);
 static int nvmatch (char *, char *);
 
+/* FIXME: These functions leak memory.  No easy fix since they might not
+ * be malloc'd.  Switch to setenv(3) and unsetenv(3). */
 
 int
 m_putenv (char *name, char *value)
 {
 
 int
 m_putenv (char *name, char *value)
 {
-    register int i;
-    register char **ep, **nep, *cp;
-
-    if (!(cp = malloc ((size_t) (strlen (name) + strlen (value) + 2))))
-       return 1;
+    int i;
+    char **ep, **nep, *cp;
 
 
-    sprintf (cp, "%s=%s", name, value);
+    cp = concat(name, "=", value, NULL);
 
     for (ep = environ, i = 0; *ep; ep++, i++)
        if (nvmatch (name, *ep)) {
 
     for (ep = environ, i = 0; *ep; ep++, i++)
        if (nvmatch (name, *ep)) {
@@ -38,8 +36,7 @@ m_putenv (char *name, char *value)
            return 0;
        }
 
            return 0;
        }
 
-    if (!(nep = (char **) malloc ((size_t) ((i + 2) * sizeof(*nep)))))
-       return 1;
+    nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep)));
 
     for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
        continue;
 
     for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
        continue;