mike121 pushed a commit to branch main
in repository guile.

commit df225a87b91db1785a24fb5bed599286054dcf70
Author: Michael Gran <spk...@yahoo.com>
AuthorDate: Mon Jul 17 16:07:37 2023 -0700

    Test for clearenv function
    
    clearenv() may not be provided by non-glibc systems.  As a fallback,
    just set environ to NULL.
    
    * libguile/posix.c (scm_environ)[!HAVE_CLEARENV]: add fallback logic
        for clearenv()
---
 configure.ac     | 4 +++-
 libguile/posix.c | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index f644dd2c5..d0a2dc79b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -516,6 +516,7 @@ AC_CHECK_HEADERS([crt_externs.h])
 #   sendfile - non-POSIX, found in glibc
 #   pipe2 - non-POSIX, found in glibc (GNU/Linux and GNU/Hurd)
 #   posix_spawn_file_actions_addclosefrom_np - glibc >= 2.34
+#...clearenv - non-POSIX, found in glibc
 #
 AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid         \
   fesetround ftime ftruncate fchown fchownat fchmod fchdir readlinkat  \
@@ -530,7 +531,8 @@ AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 
ctermid         \
   strcoll_l strtod_l strtol_l newlocale uselocale utimensat     \
   fstatat futimens openat                                              \
   sched_getaffinity sched_setaffinity sendfile pipe2                   \
-  posix_spawn_file_actions_addclosefrom_np])
+  posix_spawn_file_actions_addclosefrom_np                              \
+  clearenv])
 
 # The newlib C library uses _NL_ prefixed locale langinfo constants.
 AC_CHECK_DECLS([_NL_NUMERIC_GROUPING], [], [], [[#include <langinfo.h>]])
diff --git a/libguile/posix.c b/libguile/posix.c
index 4ca8d5ff7..6ce78ee18 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1773,7 +1773,11 @@ SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
     {
       /* Arrange to not use GC-allocated storage for what goes into
          'environ' as libc might reallocate it behind our back.  */
+#if HAVE_CLEARENV
       clearenv ();
+#else
+      environ = NULL;
+#endif
       while (!scm_is_null (env))
         {
           scm_putenv (scm_car (env));

Reply via email to