bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] unsetenv: work around Haiku issues


From: Eric Blake
Subject: [PATCH] unsetenv: work around Haiku issues
Date: Sat, 5 Feb 2011 15:15:44 -0700

On Haiku alpha 2, test-unsetenv.c passed in isolation with just
system headers, but failed when libgnu and replacement headers
were in use.  Why?  Because putenv("a") fails to remove "a=..."
from the environment, and the gnulib rpl_putenv works by
assigning to environ.  Apparently, Haiku is doing some funky
caching issues, and correctly removes all vestiges of environment
duplicates when Haiku is in charge, but not after assigning to
environ forces Haiku to rebuild its cache.

The m4 change is sufficient to detect Haiku's oddities, and the
existing replacement then passes just fine.

* m4/setenv.m4 (gl_FUNC_UNSETENV): Also detect Haiku issue.
* doc/posix-functions/unsetenv.texi (unsetenv): Document it.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                         |    4 ++++
 doc/posix-functions/unsetenv.texi |    2 +-
 m4/setenv.m4                      |   18 ++++++++++++++----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c962097..eb17b6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-02-05  Eric Blake  <address@hidden>

+       unsetenv: work around Haiku issues
+       * m4/setenv.m4 (gl_FUNC_UNSETENV): Also detect Haiku issue.
+       * doc/posix-functions/unsetenv.texi (unsetenv): Document it.
+
        strerror_r-posix: port to cygwin
        * lib/strerror_r.c (strerror_r) [__CYGWIN__]: Add cygwin
        implementation.
diff --git a/doc/posix-functions/unsetenv.texi 
b/doc/posix-functions/unsetenv.texi
index 160ef83..2c43b1e 100644
--- a/doc/posix-functions/unsetenv.texi
+++ b/doc/posix-functions/unsetenv.texi
@@ -25,7 +25,7 @@ unsetenv
 @item
 This function removes only the first value association for the given
 environment variable, not all of them, on some platforms:
-Solaris 11 2010-11.
+Solaris 11 2010-11, Haiku.
 @end itemize

 Portability problems not fixed by Gnulib:
diff --git a/m4/setenv.m4 b/m4/setenv.m4
index c5c8061..ba619b0 100644
--- a/m4/setenv.m4
+++ b/m4/setenv.m4
@@ -1,4 +1,4 @@
-# setenv.m4 serial 20
+# setenv.m4 serial 21
 dnl Copyright (C) 2001-2004, 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -97,20 +97,30 @@ int unsetenv();
     fi

     dnl Solaris 10 unsetenv does not remove all copies of a name.
+    dnl Haiku alpha 2 unsetenv gets confused by assignment to environ.
     dnl OpenBSD 4.7 unsetenv("") does not fail.
     AC_CACHE_CHECK([whether unsetenv obeys POSIX],
       [gl_cv_func_unsetenv_works],
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
        #include <stdlib.h>
        #include <errno.h>
+       extern char **environ;
       ]], [[
-       char entry[] = "b=2";
+       char entry1[] = "a=1";
+       char entry2[] = "b=2";
+       char *env[] = { entry1, entry2, NULL };
        if (putenv ((char *) "a=1")) return 1;
-       if (putenv (entry)) return 2;
-       entry[0] = 'a';
+       if (putenv (entry2)) return 2;
+       entry2[0] = 'a';
        unsetenv ("a");
        if (getenv ("a")) return 3;
        if (!unsetenv ("") || errno != EINVAL) return 4;
+       entry2[0] = 'b';
+       environ = env;
+       if (!getenv ("a")) return 5;
+       entry2[0] = 'a';
+       unsetenv ("a");
+       if (getenv ("a")) return 6;
       ]])],
       [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no],
       [gl_cv_func_unsetenv_works="guessing no"])])
-- 
1.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]