about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
authorOndřej Bílka <neleai@seznam.cz>2014-02-10 12:50:46 +0100
committerOndřej Bílka <neleai@seznam.cz>2014-02-10 12:54:10 +0100
commitf3d338c9f3e84dac5458d388efd785c4ef0df7ec (patch)
tree6d8bf33159aae83b06d901c9167db4f82ab352bd /stdlib
parentbdfe308a166b433a841d5c9ae256560c18bce640 (diff)
downloadglibc-f3d338c9f3e84dac5458d388efd785c4ef0df7ec.tar.gz
glibc-f3d338c9f3e84dac5458d388efd785c4ef0df7ec.tar.xz
glibc-f3d338c9f3e84dac5458d388efd785c4ef0df7ec.zip
Deduplicate setenv.
Setenv contained a code path that was redundant as it could be handled
in general case.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/setenv.c75
1 files changed, 3 insertions, 72 deletions
diff --git a/stdlib/setenv.c b/stdlib/setenv.c
index 7df5b3fd5f..3043498103 100644
--- a/stdlib/setenv.c
+++ b/stdlib/setenv.c
@@ -146,82 +146,13 @@ __add_to_environ (name, value, combined, replace)
 	  UNLOCK;
 	  return -1;
 	}
-
-      /* If the whole entry is given add it.  */
-      if (combined != NULL)
-	/* We must not add the string to the search tree since it belongs
-	   to the user.  */
-	new_environ[size] = (char *) combined;
-      else
-	{
-	  /* See whether the value is already known.  */
-#ifdef USE_TSEARCH
-	  char *new_value;
-	  int use_alloca = __libc_use_alloca (varlen);
-	  if (__builtin_expect (use_alloca, 1))
-	    new_value = (char *) alloca (varlen);
-	  else
-	    {
-	      new_value = malloc (varlen);
-	      if (new_value == NULL)
-		{
-		  UNLOCK;
-		  if (last_environ == NULL)
-		    free (new_environ);
-		  return -1;
-		}
-	    }
-# ifdef _LIBC
-	  __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
-		     value, vallen);
-# else
-	  memcpy (new_value, name, namelen);
-	  new_value[namelen] = '=';
-	  memcpy (&new_value[namelen + 1], value, vallen);
-# endif
-
-	  new_environ[size] = KNOWN_VALUE (new_value);
-	  if (__builtin_expect (new_environ[size] == NULL, 1))
-#endif
-	    {
-#ifdef USE_TSEARCH
-	      if (__builtin_expect (! use_alloca, 0))
-		new_environ[size] = new_value;
-	      else
-#endif
-		{
-		  new_environ[size] = (char *) malloc (varlen);
-		  if (__builtin_expect (new_environ[size] == NULL, 0))
-		    {
-		      UNLOCK;
-		      return -1;
-		    }
-
-#ifdef USE_TSEARCH
-		  memcpy (new_environ[size], new_value, varlen);
-#else
-		  memcpy (new_environ[size], name, namelen);
-		  new_environ[size][namelen] = '=';
-		  memcpy (&new_environ[size][namelen + 1], value, vallen);
-#endif
-		}
-
-	      /* And save the value now.  We cannot do this when we remove
-		 the string since then we cannot decide whether it is a
-		 user string or not.  */
-	      STORE_VALUE (new_environ[size]);
-	    }
-	}
-
-      if (__environ != last_environ)
-	memcpy ((char *) new_environ, (char *) __environ,
-		size * sizeof (char *));
-
+      new_environ[size] = NULL;
       new_environ[size + 1] = NULL;
+      ep = new_environ + size;
 
       last_environ = __environ = new_environ;
     }
-  else if (replace)
+  if (*ep == NULL || replace)
     {
       char *np;