- 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]);
+ size_t i=0;
+ if (__environ) {
+ for (char **e = __environ; *e; e++, i++)
+ if (!strncmp(s, *e, l+1)) {
+ char *tmp = *e;
+ *e = s;
+ __env_rm_add(tmp, r);
+ return 0;