Bruno Haible <bruno <at> clisp.org> writes: > > [about setenv and unsetenv] > > given the Austin Group feedback, I'll go ahead and relax our > > setenv implementation to no longer reject BSD solely on the basis of failure to > > handle null, and our testsuite to no longer call setenv(NULL,,). > > Yes, that makes sense to me.
I'm testing the following; although I don't want to push it until we also have the __nonnull__ attributes in place. From: Eric Blake <[email protected]> Date: Thu, 10 Dec 2009 12:18:31 -0700 Subject: [PATCH] setenv: relax requirement in light of POSIX ruling Requiring that {un,}setenv gracefully reject NULL is just a waste of processing power; POSIX agreed to this argument in http://austingroupbugs.net/view.php?id=185 so we no longer worry about native implementation handling of NULL. * m4/setenv.m4 (gl_FUNC_SETENV_SEPARATE): Test handling of "" but not NULL. * tests/test-setenv.c (main): Relax test. * tests/test-unsetenv.c (main): Likewise. * doc/posix-functions/setenv.texi (setenv): Document this. * doc/posix-functions/unsetenv.texi (unsetenv): Likewise. Signed-off-by: Eric Blake <[email protected]> --- ChangeLog | 10 ++++++++++ doc/posix-functions/setenv.texi | 6 +++++- doc/posix-functions/unsetenv.texi | 6 +++++- m4/setenv.m4 | 4 ++-- tests/test-setenv.c | 4 ++++ tests/test-unsetenv.c | 4 ++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9af19bc..fd558c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-12-10 Eric Blake <[email protected]> + + setenv: relax requirement in light of POSIX ruling + * m4/setenv.m4 (gl_FUNC_SETENV_SEPARATE): Test handling of "" but + not NULL. + * tests/test-setenv.c (main): Relax test. + * tests/test-unsetenv.c (main): Likewise. + * doc/posix-functions/setenv.texi (setenv): Document this. + * doc/posix-functions/unsetenv.texi (unsetenv): Likewise. + 2009-12-09 Eric Blake <[email protected]> fcntl: port portions of fcntl to mingw diff --git a/doc/posix-functions/setenv.texi b/doc/posix-functions/setenv.texi index 87c9e2d..279ae14 100644 --- a/doc/posix-functions/setenv.texi +++ b/doc/posix-functions/setenv.texi @@ -13,7 +13,7 @@ setenv AIX 4.3.2, HP-UX 11, IRIX 6.5, Solaris 9, mingw, BeOS. @item On some platforms, this function does not fail with @samp{EINVAL} when -passed a null pointer, an empty string, or a string containing @samp{=}: +passed an empty string or a string containing @samp{=}: FreeBSD 6.0, NetBSD 1.6, OpenBSD 3.8, Cygwin 1.5.x. @item On some platforms, this function removes a leading @samp{=} from the @@ -23,4 +23,8 @@ setenv Portability problems not fixed by Gnulib: @itemize +...@item +Older versions of POSIX required that @code{setenv(NULL,"",0)} gracefully +fail with @code{EINVAL}, but not all implementations guarantee this, +and the requirement was removed. @end itemize diff --git a/doc/posix-functions/unsetenv.texi b/doc/posix- functions/unsetenv.texi index 99a5e69..80b1704 100644 --- a/doc/posix-functions/unsetenv.texi +++ b/doc/posix-functions/unsetenv.texi @@ -17,7 +17,7 @@ unsetenv MacOS X 10.3, FreeBSD 6.0, NetBSD 1.6, OpenBSD 3.8, OSF/1 5.1. @item On some platforms, this function does not fail with @samp{EINVAL} when -passed a null pointer, an empty string, or a string containing @samp{=}: +passed an empty string or a string containing @samp{=}: FreeBSD 6.0, NetBSD 1.6, OpenBSD 3.8. @item This function removes only the first value association for the given @@ -27,4 +27,8 @@ unsetenv Portability problems not fixed by Gnulib: @itemize +...@item +Older versions of POSIX required that @code{unsetenv(NULL)} gracefully +fail with @code{EINVAL}, but not all implementations guarantee this, +and the requirement was removed. @end itemize diff --git a/m4/setenv.m4 b/m4/setenv.m4 index a5df034..29e6866 100644 --- a/m4/setenv.m4 +++ b/m4/setenv.m4 @@ -1,4 +1,4 @@ -# setenv.m4 serial 13 +# setenv.m4 serial 14 dnl Copyright (C) 2001-2004, 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -26,7 +26,7 @@ AC_DEFUN([gl_FUNC_SETENV_SEPARATE], #include <stdlib.h> #include <errno.h> ]], [[ - if (setenv (NULL, "", 0) != -1) return 1; + if (setenv ("", "", 0) != -1) return 1; if (errno != EINVAL) return 2; if (setenv ("a", "=", 1) != 0) return 3; if (strcmp (getenv ("a"), "=") != 0) return 4; diff --git a/tests/test-setenv.c b/tests/test-setenv.c index 61be838..eb1fe33 100644 --- a/tests/test-setenv.c +++ b/tests/test-setenv.c @@ -52,9 +52,13 @@ main (void) errno = 0; ASSERT (setenv ("a=b", "", 0) == -1); ASSERT (errno == EINVAL); +#if 0 + /* glibc and gnulib's implementation guarantee this, but POSIX no + longer requires it: http://austingroupbugs.net/view.php?id=185 */ errno = 0; ASSERT (setenv (NULL, "", 0) == -1); ASSERT (errno == EINVAL); +#endif return 0; } diff --git a/tests/test-unsetenv.c b/tests/test-unsetenv.c index 11af82c..2815cf3 100644 --- a/tests/test-unsetenv.c +++ b/tests/test-unsetenv.c @@ -57,9 +57,13 @@ main (void) errno = 0; ASSERT (unsetenv ("a=b") == -1); ASSERT (errno == EINVAL); +#if 0 + /* glibc and gnulib's implementation guarantee this, but POSIX no + longer requires it: http://austingroupbugs.net/view.php?id=185 */ errno = 0; ASSERT (unsetenv (NULL) == -1); ASSERT (errno == EINVAL); +#endif return 0; } -- 1.6.4.2
