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

Side by Side Diff: fusl/src/env/putenv.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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include <string.h> 2 #include <string.h>
3 3
4 extern char **__environ; 4 extern char** __environ;
5 char **__env_map; 5 char** __env_map;
6 6
7 int __putenv(char *s, int a) 7 int __putenv(char* s, int a) {
8 { 8 int i = 0, j = 0;
9 » int i=0, j=0; 9 char* z = strchr(s, '=');
10 » char *z = strchr(s, '='); 10 char** newenv = 0;
11 » char **newenv = 0; 11 char** newmap = 0;
12 » char **newmap = 0; 12 static char** oldenv;
13 » static char **oldenv;
14 13
15 » if (!z) return unsetenv(s); 14 if (!z)
16 » if (z==s) return -1; 15 return unsetenv(s);
17 » for (; __environ[i] && memcmp(s, __environ[i], z-s+1); i++); 16 if (z == s)
18 » if (a) { 17 return -1;
19 » » if (!__env_map) { 18 for (; __environ[i] && memcmp(s, __environ[i], z - s + 1); i++)
20 » » » __env_map = calloc(2, sizeof(char *)); 19 ;
21 » » » if (__env_map) __env_map[0] = s; 20 if (a) {
22 » » } else { 21 if (!__env_map) {
23 » » » for (; __env_map[j] && __env_map[j] != __environ[i]; j++ ); 22 __env_map = calloc(2, sizeof(char*));
24 » » » if (!__env_map[j]) { 23 if (__env_map)
25 » » » » newmap = realloc(__env_map, sizeof(char *)*(j+2) ); 24 __env_map[0] = s;
26 » » » » if (newmap) { 25 } else {
27 » » » » » __env_map = newmap; 26 for (; __env_map[j] && __env_map[j] != __environ[i]; j++)
28 » » » » » __env_map[j] = s; 27 ;
29 » » » » » __env_map[j+1] = NULL; 28 if (!__env_map[j]) {
30 » » » » } 29 newmap = realloc(__env_map, sizeof(char*) * (j + 2));
31 » » » } else { 30 if (newmap) {
32 » » » » free(__env_map[j]); 31 __env_map = newmap;
33 » » » } 32 __env_map[j] = s;
34 » » } 33 __env_map[j + 1] = NULL;
35 » } 34 }
36 » if (!__environ[i]) { 35 } else {
37 » » newenv = malloc(sizeof(char *)*(i+2)); 36 free(__env_map[j]);
38 » » if (!newenv) { 37 }
39 » » » if (a && __env_map) __env_map[j] = 0; 38 }
40 » » » return -1; 39 }
41 » » } 40 if (!__environ[i]) {
42 » » memcpy(newenv, __environ, sizeof(char *)*i); 41 newenv = malloc(sizeof(char*) * (i + 2));
43 » » newenv[i] = s; 42 if (!newenv) {
44 » » newenv[i+1] = 0; 43 if (a && __env_map)
45 » » __environ = newenv; 44 __env_map[j] = 0;
46 » » free(oldenv); 45 return -1;
47 » » oldenv = __environ; 46 }
48 » } 47 memcpy(newenv, __environ, sizeof(char*) * i);
48 newenv[i] = s;
49 newenv[i + 1] = 0;
50 __environ = newenv;
51 free(oldenv);
52 oldenv = __environ;
53 }
49 54
50 » __environ[i] = s; 55 __environ[i] = s;
51 » return 0; 56 return 0;
52 } 57 }
53 58
54 int putenv(char *s) 59 int putenv(char* s) {
55 { 60 return __putenv(s, 0);
56 » return __putenv(s, 0);
57 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698