]> git.lizzy.rs Git - plan9front.git/commitdiff
ape: putenv, add file :)
authorcinap_lenrek <cinap_lenrek@gmx.de>
Mon, 3 Dec 2012 05:47:01 +0000 (06:47 +0100)
committercinap_lenrek <cinap_lenrek@gmx.de>
Mon, 3 Dec 2012 05:47:01 +0000 (06:47 +0100)
sys/src/ape/lib/ap/gen/putenv.c [new file with mode: 0644]

diff --git a/sys/src/ape/lib/ap/gen/putenv.c b/sys/src/ape/lib/ap/gen/putenv.c
new file mode 100644 (file)
index 0000000..56a1184
--- /dev/null
@@ -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;
+}