From d85104099ad40c33148426adb779741c366c2f19 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 30 Apr 2007 16:56:18 +0000 Subject: Make putenv() fully conforms to Open Group specs Issue 6 (also IEEE Std 1003.1-2001) The specs explicitly says that altering passed string should change the environment, i.e. putenv() directly puts its arg into environment (unlike setenv() which just copies it there). It means that putenv() can't be implemented via setenv() (like we have before) at all. Putenv() value lives (allows modifying) up to the next putenv() or setenv() call. --- lib/libc/stdlib/getenv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdlib/getenv.c') diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index 73ac407..9ff18d8 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -43,7 +43,8 @@ inline char *__findenv(const char *, int *); * __findenv -- * Returns pointer to value associated with name, if any, else NULL. * Sets offset to be the offset of the name/value combination in the - * environmental array, for use by setenv(3) and unsetenv(3). + * environmental array, for use by putenv(3), setenv(3) and unsetenv(3). + * Explicitly removes '=' in argument name. * * This routine *should* be a static; don't use it. */ @@ -59,7 +60,9 @@ __findenv(name, offset) if (environ == NULL) return (NULL); - len = strlen(name); + for (np = name; *np && *np != '='; ++np) + continue; + len = np - name; for (p = environ; (cp = *p) != NULL; ++p) { for (np = name, i = len; i && *cp; i--) if (*cp++ != *np++) -- cgit v1.1