Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: fusl/src/env/setenv.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/env/putenv.c ('k') | fusl/src/env/unsetenv.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/env/setenv.c
diff --git a/fusl/src/env/setenv.c b/fusl/src/env/setenv.c
new file mode 100644
index 0000000000000000000000000000000000000000..76e8ee1206e5b5a4111b8c58481932952de6084f
--- /dev/null
+++ b/fusl/src/env/setenv.c
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int __putenv(char *s, int a);
+
+int setenv(const char *var, const char *value, int overwrite)
+{
+ char *s;
+ int l1, l2;
+
+ if (!var || !*var || strchr(var, '=')) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (!overwrite && getenv(var)) return 0;
+
+ l1 = strlen(var);
+ l2 = strlen(value);
+ s = malloc(l1+l2+2);
+ if (s) {
+ memcpy(s, var, l1);
+ s[l1] = '=';
+ memcpy(s+l1+1, value, l2);
+ s[l1+l2+1] = 0;
+ if (!__putenv(s, 1)) return 0;
+ }
+ free(s);
+ return -1;
+}
« no previous file with comments | « fusl/src/env/putenv.c ('k') | fusl/src/env/unsetenv.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698