Chromium Code Reviews

Side by Side Diff: fusl/src/env/setenv.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include <string.h> 2 #include <string.h>
3 #include <errno.h> 3 #include <errno.h>
4 4
5 int __putenv(char *s, int a); 5 int __putenv(char* s, int a);
6 6
7 int setenv(const char *var, const char *value, int overwrite) 7 int setenv(const char* var, const char* value, int overwrite) {
8 { 8 char* s;
9 » char *s; 9 int l1, l2;
10 » int l1, l2;
11 10
12 » if (!var || !*var || strchr(var, '=')) { 11 if (!var || !*var || strchr(var, '=')) {
13 » » errno = EINVAL; 12 errno = EINVAL;
14 » » return -1; 13 return -1;
15 » } 14 }
16 » if (!overwrite && getenv(var)) return 0; 15 if (!overwrite && getenv(var))
16 return 0;
17 17
18 » l1 = strlen(var); 18 l1 = strlen(var);
19 » l2 = strlen(value); 19 l2 = strlen(value);
20 » s = malloc(l1+l2+2); 20 s = malloc(l1 + l2 + 2);
21 » if (s) { 21 if (s) {
22 » » memcpy(s, var, l1); 22 memcpy(s, var, l1);
23 » » s[l1] = '='; 23 s[l1] = '=';
24 » » memcpy(s+l1+1, value, l2); 24 memcpy(s + l1 + 1, value, l2);
25 » » s[l1+l2+1] = 0; 25 s[l1 + l2 + 1] = 0;
26 » » if (!__putenv(s, 1)) return 0; 26 if (!__putenv(s, 1))
27 » } 27 return 0;
28 » free(s); 28 }
29 » return -1; 29 free(s);
30 return -1;
30 } 31 }
OLDNEW

Powered by Google App Engine