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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « fusl/src/env/putenv.c ('k') | fusl/src/env/unsetenv.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4
5 int __putenv(char *s, int a);
6
7 int setenv(const char *var, const char *value, int overwrite)
8 {
9 char *s;
10 int l1, l2;
11
12 if (!var || !*var || strchr(var, '=')) {
13 errno = EINVAL;
14 return -1;
15 }
16 if (!overwrite && getenv(var)) return 0;
17
18 l1 = strlen(var);
19 l2 = strlen(value);
20 s = malloc(l1+l2+2);
21 if (s) {
22 memcpy(s, var, l1);
23 s[l1] = '=';
24 memcpy(s+l1+1, value, l2);
25 s[l1+l2+1] = 0;
26 if (!__putenv(s, 1)) return 0;
27 }
28 free(s);
29 return -1;
30 }
OLDNEW
« 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