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

Side by Side Diff: fusl/src/env/putenv.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/getenv.c ('k') | fusl/src/env/setenv.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
4 extern char **__environ;
5 char **__env_map;
6
7 int __putenv(char *s, int a)
8 {
9 int i=0, j=0;
10 char *z = strchr(s, '=');
11 char **newenv = 0;
12 char **newmap = 0;
13 static char **oldenv;
14
15 if (!z) return unsetenv(s);
16 if (z==s) return -1;
17 for (; __environ[i] && memcmp(s, __environ[i], z-s+1); i++);
18 if (a) {
19 if (!__env_map) {
20 __env_map = calloc(2, sizeof(char *));
21 if (__env_map) __env_map[0] = s;
22 } else {
23 for (; __env_map[j] && __env_map[j] != __environ[i]; j++ );
24 if (!__env_map[j]) {
25 newmap = realloc(__env_map, sizeof(char *)*(j+2) );
26 if (newmap) {
27 __env_map = newmap;
28 __env_map[j] = s;
29 __env_map[j+1] = NULL;
30 }
31 } else {
32 free(__env_map[j]);
33 }
34 }
35 }
36 if (!__environ[i]) {
37 newenv = malloc(sizeof(char *)*(i+2));
38 if (!newenv) {
39 if (a && __env_map) __env_map[j] = 0;
40 return -1;
41 }
42 memcpy(newenv, __environ, sizeof(char *)*i);
43 newenv[i] = s;
44 newenv[i+1] = 0;
45 __environ = newenv;
46 free(oldenv);
47 oldenv = __environ;
48 }
49
50 __environ[i] = s;
51 return 0;
52 }
53
54 int putenv(char *s)
55 {
56 return __putenv(s, 0);
57 }
OLDNEW
« no previous file with comments | « fusl/src/env/getenv.c ('k') | fusl/src/env/setenv.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698