mailing list of musl libc
 help / color / mirror / code / Atom feed
86b2024cee14da3429b6862baa08ebbd3119f801 blob 1317 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
#include <stdlib.h>
#include <string.h>

extern char **__environ;
static char **__env_map;

void __env_free(char *p)
{
	if (__env_map)
		for (char **e = __env_map; *e; e++)
			if (*e == p) {
				char **ee = e;
				while (*(ee+1)) ee++;
				*e = *ee; *ee = 0;
				free(p);
				return;
			}
}

int __putenv(char *s, int a)
{
	int i=0, j=0;
	char *z = strchr(s, '=');
	char **newenv = 0;
	char **newmap = 0;
	static char **oldenv;

	if (!z) return unsetenv(s);
	if (z==s) return -1;
	for (; __environ[i] && memcmp(s, __environ[i], z-s+1); i++);
	if (a) {
		if (!__env_map) {
			__env_map = calloc(2, sizeof(char *));
			if (__env_map) __env_map[0] = s;
		} else {
			for (; __env_map[j] && __env_map[j] != __environ[i]; j++);
			if (!__env_map[j]) {
				newmap = realloc(__env_map, sizeof(char *)*(j+2));
				if (newmap) {
					__env_map = newmap;
					__env_map[j] = s;
					__env_map[j+1] = NULL;
				}
			} else {
				free(__env_map[j]);
			}
		}
	}
	if (!__environ[i]) {
		newenv = malloc(sizeof(char *)*(i+2));
		if (!newenv) {
			if (a && __env_map) __env_map[j] = 0;
			return -1;
		}
		memcpy(newenv, __environ, sizeof(char *)*i);
		newenv[i] = s;
		newenv[i+1] = 0;
		__environ = newenv;
		free(oldenv);
		oldenv = __environ;
	}

	__environ[i] = s;
	return 0;
}

int putenv(char *s)
{
	return __putenv(s, 0);
}
debug log:

solving 86b2024 ...
found 86b2024 in https://inbox.vuxu.org/musl/alpine.LNX.2.20.1602202103390.21162@monopod.intra.ispras.ru/
found 4042869 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 4042869b500f1866e111918f121ba3d08d962287	src/env/putenv.c

applying [1/1] https://inbox.vuxu.org/musl/alpine.LNX.2.20.1602202103390.21162@monopod.intra.ispras.ru/
diff --git a/src/env/putenv.c b/src/env/putenv.c
index 4042869..86b2024 100644

Checking patch src/env/putenv.c...
Applied patch src/env/putenv.c cleanly.

index at:
100644 86b2024cee14da3429b6862baa08ebbd3119f801	src/env/putenv.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).