ep = __environ;
__add_to_environ (name, value, combined, replace)     const char *name;     const char *value;     const char *combined;     int replace;{  register char **ep = __environ;  register size_t size;  const size_t namelen = strlen (name);  const size_t vallen = value != NULL ? strlen (value) + 1 : 0;  LOCK;  size = 0;  if (ep != NULL)    {      for (; *ep != NULL; ++ep)	if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')	  break;	else	  ++size;    }  if (ep == NULL || *ep == NULL)    {      char **new_environ;#ifdef USE_TSEARCH      char *new_value;#endif      /* We allocated this space; we can extend it.  */      new_environ = (char **) realloc (last_environ,				       (size + 2) * sizeof (char *));      if (new_environ == NULL)	{	  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	  new_value = (char *) alloca (namelen + 1 + vallen);# 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 (new_environ[size] == NULL)#endif	    {	      new_environ[size] = (char *) malloc (namelen + 1 + vallen);	      if (new_environ[size] == NULL)		{		  __set_errno (ENOMEM);		  UNLOCK;		  return -1;		}#ifdef USE_TSEARCH	      memcpy (new_environ[size], new_value, namelen + 1 + vallen);#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 + 1] = NULL;      last_environ = __environ = new_environ;    }  else if (replace)    {      char *np;      /* Use the user string if given.  */      if (combined != NULL)	np = (char *) combined;      else	{#ifdef USE_TSEARCH	  char *new_value = alloca (namelen + 1 + vallen);# 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	  np = KNOWN_VALUE (new_value);	  if (np == NULL)#endif	    {	      np = malloc (namelen + 1 + vallen);	      if (np == NULL)		{		  UNLOCK;		  return -1;		}#ifdef USE_TSEARCH	      memcpy (np, new_value, namelen + 1 + vallen);#else	      memcpy (np, name, namelen);	      np[namelen] = '=';	      memcpy (&np[namelen + 1], value, vallen);#endif	      /* And remember the value.  */	      STORE_VALUE (np);	    }	}      *ep = np;    }  UNLOCK;  return 0;}