diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
commit | 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 (patch) | |
tree | 6eaef0d8a720fa3da580de87b647fff796fe80b3 /src/env/unsetenv.c | |
download | musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.gz musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.bz2 musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.xz musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.zip |
initial check-in, version 0.5.0v0.5.0
Diffstat (limited to 'src/env/unsetenv.c')
-rw-r--r-- | src/env/unsetenv.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/env/unsetenv.c b/src/env/unsetenv.c new file mode 100644 index 00000000..7493d970 --- /dev/null +++ b/src/env/unsetenv.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +extern char **__environ; +extern char **__env_map; + +int unsetenv(const char *name) +{ + int i, j; + size_t l = strlen(name); + + if (!*name || strchr(name, '=')) { + errno = EINVAL; + return -1; + } +again: + for (i=0; __environ[i] && (memcmp(name, __environ[i], l) || __environ[i][l] != '='); i++); + if (__environ[i]) { + if (__env_map) { + for (j=0; __env_map[j] && __env_map[j] != __environ[i]; j++); + free (__env_map[j]); + for (; __env_map[j]; j++) + __env_map[j] = __env_map[j+1]; + } + for (; __environ[i]; i++) + __environ[i] = __environ[i+1]; + goto again; + } + return 0; +} |