1 #include <stdlib.h> 2 #include <string.h> 3 #include <errno.h> 4 #include <unistd.h> 5 dummy(char * old,char * new)6static void dummy(char *old, char *new) {} 7 weak_alias(dummy, __env_rm_add); 8 unsetenv(const char * name)9int unsetenv(const char *name) 10 { 11 size_t l = __strchrnul(name, '=') - name; 12 if (!l || name[l]) { 13 errno = EINVAL; 14 return -1; 15 } 16 if (__environ) { 17 char **e = __environ, **eo = e; 18 for (; *e; e++) 19 if (!strncmp(name, *e, l) && l[*e] == '=') 20 __env_rm_add(*e, 0); 21 else if (eo != e) 22 *eo++ = *e; 23 else 24 eo++; 25 if (eo != e) *eo = 0; 26 } 27 return 0; 28 } 29