blob: b14c4c929b1f18033e68a480d4500856f33bdaa5 [file] [log] [blame]
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
static void dummy(char *old, char *new) {}
weak_alias(dummy, __env_rm_add);
int unsetenv(const char *name)
{
size_t l = __strchrnul(name, '=') - name;
if (!l || name[l]) {
errno = EINVAL;
return -1;
}
if (__environ) {
char **e = __environ, **eo = e;
for (; *e; e++)
if (!strncmp(name, *e, l) && l[*e] == '=')
__env_rm_add(*e, 0);
else if (eo != e)
*eo++ = *e;
else
eo++;
if (eo != e) *eo = 0;
}
return 0;
}