diff options
author | ache <ache@FreeBSD.org> | 2007-05-01 16:02:44 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2007-05-01 16:02:44 +0000 |
commit | 6ccaf050cc62bc9d81ac3acb71ce640739caa0f7 (patch) | |
tree | e3e0b3658b8df3a905b3117d8535bb15f42c9e80 /lib/libc/stdlib/putenv.c | |
parent | 61e9800ad7707590037d6868c703475f36cf7058 (diff) | |
download | FreeBSD-src-6ccaf050cc62bc9d81ac3acb71ce640739caa0f7.zip FreeBSD-src-6ccaf050cc62bc9d81ac3acb71ce640739caa0f7.tar.gz |
Back out all POSIXified *env() changes.
Not because I admit they are technically wrong and not because of bug
reports (I receive nothing). But because I surprisingly meets so
strong opposition and resistance so lost any desire to continue that.
Anyone who interested in POSIX can dig out what changes and how
through cvs diffs.
Diffstat (limited to 'lib/libc/stdlib/putenv.c')
-rw-r--r-- | lib/libc/stdlib/putenv.c | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/lib/libc/stdlib/putenv.c b/lib/libc/stdlib/putenv.c index 56b78cf..a5eea5d 100644 --- a/lib/libc/stdlib/putenv.c +++ b/lib/libc/stdlib/putenv.c @@ -33,50 +33,24 @@ static char sccsid[] = "@(#)putenv.c 8.2 (Berkeley) 3/27/94"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <errno.h> #include <stdlib.h> #include <string.h> -extern char **__alloced; /* if allocated space before */ - -char *__findenv(const char *, int *); - int putenv(str) - char *str; + const char *str; { - extern char **environ; - char *eq; - int offset; + char *p, *equal; + int rval; - if (str == NULL || (eq = strchr(str, '=')) == NULL || eq == str) { - errno = EINVAL; + if ((p = strdup(str)) == NULL) + return (-1); + if ((equal = index(p, '=')) == NULL) { + (void)free(p); return (-1); } - - /* Trimmed version of setenv(3). */ - if (__findenv(str, &offset) == NULL) { - int cnt; - char **p; - - for (p = environ, cnt = 0; *p; ++p, ++cnt); - if (__alloced == environ) { /* just increase size */ - p = (char **)realloc((char *)environ, - (size_t)(sizeof(char *) * (cnt + 2))); - if (!p) - return (-1); - } - else { /* get new space */ - /* copy old entries into it */ - p = (char **)malloc((size_t)(sizeof(char *) * (cnt + 2))); - if (!p) - return (-1); - bcopy(environ, p, cnt * sizeof(char *)); - } - __alloced = environ = p; - environ[cnt + 1] = NULL; - offset = cnt; - } - environ[offset] = str; - return (0); + *equal = '\0'; + rval = setenv(p, equal + 1, 1); + (void)free(p); + return (rval); } |