mailing list of musl libc
 help / color / mirror / code / Atom feed
6984237aab671f12e84cc2c37699d9e5d14524df blob 902 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
 
#include <stdlib.h>
#include <string.h>
#include <errno.h>

char *__strchrnul(const char *, int);
int __putenv(char *, size_t, char *);

void __env_change(char *p, char *r)
{
	static char **env_alloced;
	static size_t env_alloced_n;
	for (size_t i=0; i < env_alloced_n; i++)
		if (env_alloced[i] == p) {
			env_alloced[i] = r;
			free(p);
			return;
		}
	if (!r) return;
	char **new_ea = realloc(env_alloced, sizeof *new_ea * (env_alloced_n+1));
	if (!new_ea) return;
	new_ea[env_alloced_n++] = r;
	env_alloced = new_ea;
}

int setenv(const char *var, const char *value, int overwrite)
{
	char *s;
	size_t l1 = __strchrnul(var, '=') - var, l2;
	if (!l1 || var[l1]) {
		errno = EINVAL;
		return -1;
	}
	if (!overwrite && getenv(var)) return 0;

	l2 = strlen(value);
	s = malloc(l1+l2+2);
	if (!s) return -1;
	memcpy(s, var, l1);
	s[l1] = '=';
	memcpy(s+l1+1, value, l2+1);
	return __putenv(s, l1, s);
}
debug log:

solving 6984237 ...
found 6984237 in https://inbox.vuxu.org/musl/1457895230-13602-2-git-send-email-amonakov@ispras.ru/
found 76e8ee1 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 76e8ee1206e5b5a4111b8c58481932952de6084f	src/env/setenv.c

applying [1/1] https://inbox.vuxu.org/musl/1457895230-13602-2-git-send-email-amonakov@ispras.ru/
diff --git a/src/env/setenv.c b/src/env/setenv.c
index 76e8ee1..6984237 100644

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

index at:
100644 6984237aab671f12e84cc2c37699d9e5d14524df	src/env/setenv.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).