environ.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Many systems have putenv() but no setenv(). Other systems have setenv()
* but no putenv() (MIPS). Still other systems have neither (NeXT). This is a
* re-implementation that hopefully ends all problems.
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#ifndef lint
#endif
/* System libraries. */
extern char **environ;
extern char *strchr();
extern char *strcpy();
extern char *strncpy();
extern char *malloc();
extern char *realloc();
extern int strncmp();
extern void free();
#ifdef no_memcpy
#else
extern char *memcpy();
#endif
/* Local stuff. */
static int addenv(); /* append entry to environment */
static int allocated = 0; /* environ is, or is not, allocated */
#define DO_CLOBBER 1
/* namelength - determine length of name in "name=whatever" */
static int namelength(name)
char *name;
{
char *equal;
}
/* findenv - given name, locate name=value */
char *name;
int len;
{
char **envp;
return (envp);
return (0);
}
/* getenv - given name, locate value */
char *name;
{
}
/* putenv - update or append environment (name,value) pair */
char *nameval;
{
}
/* unsetenv - remove variable from environment */
char *name;
{
char **envp;
envp++;
}
/* setenv - update or append environment (name,value) pair */
char *name;
char *value;
int clobber;
{
char *destination;
char **envp;
int l_name; /* length of name part */
int l_nameval; /* length of name=value */
/* Permit name= and =value. */
return (0);
if (*value == '=')
value++;
/*
* Use available memory if the old value is long enough. Never free an
* old name=value entry because it may not be allocated.
*/
if (destination == 0)
return (-1);
}
/* cmalloc - malloc and copy block of memory */
char *old;
int old_len;
{
if (new != 0)
return (new);
}
/* addenv - append environment entry */
char *nameval;
{
char **envp;
int n_used; /* number of environment entries */
int l_used; /* bytes used excl. terminator */
int l_need; /* bytes needed incl. terminator */
/* void */ ;
if (envp == 0) {
return (-1);
} else {
allocated = 1;
return (0);
}
}
#ifdef TEST
/*
* Stand-alone program for test purposes.
*/
/* printenv - display environment */
static void printenv()
{
char **envp;
}
int argc;
char **argv;
{
char *cp;
int changed = 0;
if (argc < 2) {
return (1);
}
changed = 1;
} else { /* putenv() test */
perror("putenv");
return (1);
}
changed = 1;
}
}
if (changed)
printenv();
return (0);
}
#endif /* TEST */