Fixed error case + minor cleanup.

This commit is contained in:
shivers 1995-10-26 13:36:23 +00:00
parent 4b080b5a28
commit ef473e636e
1 changed files with 12 additions and 9 deletions

View File

@ -17,8 +17,12 @@
#include <string.h>
/* Don't want to include stdlib.h because it declares putenv to take
** a const string -- bogus. So we'll just declare malloc directly.
*/
extern void *malloc(size_t size);
#define Malloc(type,n) ((type *) malloc(sizeof(type)*(n)))
#define Free(p) (free((void *)(p)))
extern char **environ;
/*****************************************************************************/
@ -66,15 +70,14 @@ static int append_envvar(char *str, int old_envsize)
int putenv(char *str)
{
char **envp = environ;
char **envp;
char *equalsign = strchr(str, '=');
int namelen;
char **newenv, **nenvp;
if( ! equalsign ) return 0; /* No equals sign in str! */
namelen = 1 + equalsign - str; /* Count the terminating =. */
for(; *envp; envp++)
for(envp = environ; *envp; envp++)
if( ! memcmp(*envp, str, namelen) ) {
*envp = str;
return 0;
@ -83,7 +86,6 @@ int putenv(char *str)
/* The env var wasn't defined. Copy the entire env to a new
** block, and add the new definition.
*/
return append_envvar(str, envp-environ+1);
}
@ -95,18 +97,20 @@ int putenv(char *str)
** beginning with "<var>=" are deleted from environ. unsetenv
** returns the number of occurrences it found and deleted; if
** it returns 0, then the variable wasn't in environ to begin with.
** If name is the null pointer, unsetenv returns immediately.
** If name is the null pointer, unsetenv returns -1 immediately.
*/
int unsetenv(const char *name)
{
char **envp, **target;
int hits = 0;
int hits;
int slen;
if( !name ) return;
if( !name ) return -1;
slen = strlen(name);
hits = 0;
target = environ;
for( envp=environ; *envp; envp++ )
if( !strncmp(*envp, name, slen) && (*envp)[slen] == '=' )
hits++;
@ -152,7 +156,6 @@ int setenv(const char *name, const char *val)
for( envp=environ; *envp; envp++ )
if( !strncmp(*envp, name, name_len) && (*envp)[name_len] == '=' ) {
char *newval;
char *equal = name_len + *envp;
if( strlen(equal+1) >= val_len )