---
 winsup/cygwin/common.din              |  1 +
 winsup/cygwin/environ.cc              | 20 ++++++++++++++++++++
 winsup/cygwin/include/cygwin/stdlib.h |  1 +
 3 files changed, 22 insertions(+)

diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 6e8bf9185..426cf172c 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -306,6 +306,7 @@ cimag NOSIGFE
 cimagf NOSIGFE
 cimagl NOSIGFE
 cleanup_glue NOSIGFE
+clearenv SIGFE
 clearerr SIGFE
 clearerr_unlocked SIGFE
 clock SIGFE
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 8e6bbe561..3676bd9ea 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -720,6 +720,26 @@ unsetenv (const char *name)
   return -1;
 }
 
+/* Clear the environment.  */
+extern "C" int
+clearenv ()
+{
+  __try
+    {
+      if (cur_environ () == lastenviron && lastenviron != NULL)
+       {
+         free (lastenviron);
+         lastenviron = NULL;
+       }
+      __cygwin_environ = NULL;
+      update_envptrs ();
+      return 0;
+    }
+  __except (EFAULT) {}
+  __endtry
+  return -1;
+}
+
 /* Minimal list of Windows vars which must be converted to uppercase.
    Either for POSIX compatibility of for backward compatibility with
    existing applications. */
diff --git a/winsup/cygwin/include/cygwin/stdlib.h 
b/winsup/cygwin/include/cygwin/stdlib.h
index 845d2d81b..55d75e402 100644
--- a/winsup/cygwin/include/cygwin/stdlib.h
+++ b/winsup/cygwin/include/cygwin/stdlib.h
@@ -22,6 +22,7 @@ void  setprogname (const char *);
 
 #if __GNU_VISIBLE
 char *canonicalize_file_name (const char *);
+int clearenv ();
 #endif
 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
 int unsetenv (const char *);
-- 
2.17.0

Reply via email to