Add libbroken.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@417 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
44
lib/roken/putenv.c
Normal file
44
lib/roken/putenv.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
RCSID("$Id$");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
/*
|
||||
* putenv --
|
||||
* String points to a string of the form name=value.
|
||||
*
|
||||
* Makes the value of the environment variable name equal to
|
||||
* value by altering an existing variable or creating a new one.
|
||||
*/
|
||||
int putenv(const char *string)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
len = string - strchr(string, '=') + 1;
|
||||
|
||||
if(environ == NULL){
|
||||
environ = malloc(sizeof(char*));
|
||||
if(environ == NULL)
|
||||
return 1;
|
||||
environ[0] = NULL;
|
||||
}
|
||||
|
||||
for(i = 0; environ[i]; i++)
|
||||
if(strncmp(string, environ[i], len)){
|
||||
environ[len] = string;
|
||||
return 0;
|
||||
}
|
||||
environ = realloc(environ, sizeof(char*) * (i + 1));
|
||||
if(environ == NULL)
|
||||
return 1;
|
||||
environ[i] = string;
|
||||
environ[i+1] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user