projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Build the release tarball from git, not manually
[mmh]
/
sbr
/
putenv.c
diff --git
a/sbr/putenv.c
b/sbr/putenv.c
index
2c6af0d
..
a2ec7d3
100644
(file)
--- a/
sbr/putenv.c
+++ b/
sbr/putenv.c
@@
-1,76
+1,76
@@
-
/*
/*
- * putenv.c -- (un)set an envariable
- *
- * $Id$
- */
+** putenv.c -- (un)set an envariable
+**
+** 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/mh.h>
+#include <h/utils.h>
extern char **environ;
/*
extern char **environ;
/*
- * prototypes
- */
-int m_putenv (char *, char *);
-int unputenv (char *);
-static int nvmatch (char *, char *);
+** prototypes
+*/
+int m_putenv(char *, char *);
+int unputenv(char *);
+static int nvmatch(char *, char *);
int
int
-m_putenv (char *name, char *value)
+m_putenv(char *name, char *value)
{
{
- register int i;
- register char **ep, **nep, *cp;
+ int i;
+ char **ep, **nep, *cp;
- if (!(cp = malloc ((size_t) (strlen (name) + strlen (value) + 2))))
- return 1;
+ cp = mh_xmalloc((size_t) (strlen(name) + strlen(value) + 2));
- sprintf (cp, "%s=%s", name, value);
+ sprintf(cp, "%s=%s", name, value);
- for (ep = environ, i = 0; *ep; ep++, i++)
- if (nvmatch (name, *ep)) {
- *ep = cp;
- return 0;
- }
+ for (ep = environ, i = 0; *ep; ep++, i++)
+ if (nvmatch(name, *ep)) {
+ *ep = cp;
+ 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;
- nep[i++] = cp;
- nep[i] = NULL;
- environ = nep;
- return 0;
+ for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
+ continue;
+ nep[i++] = cp;
+ nep[i] = NULL;
+ environ = nep;
+ return 0;
}
int
}
int
-unputenv (char *name)
+unputenv(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;
+ 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 int
}
static int
-nvmatch (char *s1, char *s2)
+nvmatch(char *s1, char *s2)
{
{
- while (*s1 == *s2++)
- if (*s1++ == '=')
- return 1;
+ while (*s1 == *s2++)
+ if (*s1++ == '=')
+ return 1;
- return (*s1 == '\0' && *--s2 == '=');
+ return (*s1 == '\0' && *--s2 == '=');
}
}