This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Cygwin: Implement the GNU extension clearenv


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=defaa2ca31cd3e407451d55ea8414f30d7dddf65

commit defaa2ca31cd3e407451d55ea8414f30d7dddf65
Author: Ken Brown <kbrown@cornell.edu>
Date:   Wed Jun 6 11:45:56 2018 -0400

    Cygwin: Implement the GNU extension clearenv

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

diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 6e8bf91..426cf17 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 06e1ced..bbe5398 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 (void)
+{
+  __try
+    {
+      if (cur_environ () == lastenviron)
+	{
+	  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 845d2d8..e274b8b 100644
--- a/winsup/cygwin/include/cygwin/stdlib.h
+++ b/winsup/cygwin/include/cygwin/stdlib.h
@@ -26,6 +26,9 @@ char *canonicalize_file_name (const char *);
 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
 int unsetenv (const char *);
 #endif
+#if __MISC_VISIBLE
+int clearenv (void);
+#endif
 #if __XSI_VISIBLE
 char *ptsname (int);
 int grantpt (int);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]