Browse Source

as an extension, have putenv("VAR") behave as unsetenv("VAR")

the behavior of putenv is left undefined if the argument does not
contain an equal sign, but traditional implementations behave this way
and gnulib replaces putenv if it doesn't do this.
Rich Felker 12 years ago
parent
commit
31a55f233b
1 changed files with 5 additions and 5 deletions
  1. 5 5
      src/env/putenv.c

+ 5 - 5
src/env/putenv.c

@@ -9,14 +9,14 @@ char **__env_map;
 int __putenv(char *s, int a)
 int __putenv(char *s, int a)
 {
 {
 	int i=0, j=0;
 	int i=0, j=0;
-	char *end = strchr(s, '=');
-	size_t l = end-s+1;
+	char *z = strchr(s, '=');
 	char **newenv = 0;
 	char **newenv = 0;
 	char **newmap = 0;
 	char **newmap = 0;
 	static char **oldenv;
 	static char **oldenv;
-	
-	if (!end || l == 1) return -1;
-	for (; __environ[i] && memcmp(s, __environ[i], l); i++);
+
+	if (!z) return unsetenv(s);
+	if (z==s) return -1;
+	for (; __environ[i] && memcmp(s, __environ[i], z-s+1); i++);
 	if (a) {
 	if (a) {
 		if (!__env_map) {
 		if (!__env_map) {
 			__env_map = calloc(2, sizeof(char *));
 			__env_map = calloc(2, sizeof(char *));