aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/getenv.c
diff options
context:
space:
mode:
authorMariusz Zaborski <oshogbo@FreeBSD.org>2021-11-07 15:15:28 +0000
committerMariusz Zaborski <oshogbo@FreeBSD.org>2021-11-07 15:20:15 +0000
commit597b02675751e48dd04777f1e91fee382bf3a966 (patch)
tree2dc6bd312cfe5c1fcf869c9668664747a9768648 /lib/libc/stdlib/getenv.c
parente9c7c6f5a021a02c5af2fa446d31cf3756b58d62 (diff)
Diffstat (limited to 'lib/libc/stdlib/getenv.c')
-rw-r--r--lib/libc/stdlib/getenv.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index 5d445e18d93b..bf79cb6b0d79 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -691,3 +691,28 @@ unsetenv(const char *name)
return (0);
}
+
+/*
+ * Unset all variable by flagging them as inactive. No variable is
+ * ever freed.
+ */
+int
+clearenv(void)
+{
+ int ndx;
+
+ /* Initialize environment. */
+ if (__merge_environ() == -1 || (envVars == NULL && __build_env() == -1))
+ return (-1);
+
+ /* Remove from the end to not shuffle memory too much. */
+ for (ndx = envVarsTotal - 1; ndx >= 0; ndx--) {
+ envVars[ndx].active = false;
+ if (envVars[ndx].putenv)
+ __remove_putenv(ndx);
+ }
+
+ __rebuild_environ(0);
+
+ return (0);
+}