summaryrefslogtreecommitdiffstats
path: root/usr/klibc/putenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/putenv.c')
-rw-r--r--usr/klibc/putenv.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/usr/klibc/putenv.c b/usr/klibc/putenv.c
new file mode 100644
index 0000000..5059ecb
--- /dev/null
+++ b/usr/klibc/putenv.c
@@ -0,0 +1,37 @@
+/*
+ * putenv.c
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "env.h"
+
+int putenv(const char *str)
+{
+ char *s;
+ const char *e, *z;
+
+ if (!str) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ e = NULL;
+ for (z = str; *z; z++) {
+ if (*z == '=')
+ e = z;
+ }
+
+ if (!e) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ s = strdup(str);
+ if (!s)
+ return -1;
+
+ return __put_env(s, e - str, 1);
+}