ape: putenv, add file :)
This commit is contained in:
parent
84c930a078
commit
ee251568fb
1 changed files with 24 additions and 0 deletions
24
sys/src/ape/lib/ap/gen/putenv.c
Normal file
24
sys/src/ape/lib/ap/gen/putenv.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern char **environ;
|
||||||
|
|
||||||
|
int
|
||||||
|
putenv(const char *str)
|
||||||
|
{
|
||||||
|
char *s1, *s2, **e;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
for(n = 0; s2 = environ[n]; n++)
|
||||||
|
for(s1 = str; *s1 == *s2; s1++, s2++)
|
||||||
|
if(*s1 == '\0' || *s1 == '='){
|
||||||
|
environ[n] = str;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
e = realloc(environ, (n+1) * sizeof(char*));
|
||||||
|
if(e == 0)
|
||||||
|
return -1;
|
||||||
|
environ = e;
|
||||||
|
e[n++] = str;
|
||||||
|
e[n] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue