Define the putenv substitute in <stdlib.h> rather than in <config.h>.
authorBruno Haible <bruno@clisp.org>
Thu, 1 Nov 2007 12:23:33 +0000 (13:23 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 1 Nov 2007 12:23:33 +0000 (13:23 +0100)
ChangeLog
lib/putenv.c
lib/stdlib.in.h
m4/putenv.m4
m4/stdlib_h.m4
modules/putenv
modules/stdlib

index c534892..7866e74 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2007-11-01  Bruno Haible  <bruno@clisp.org>
+
+       * lib/putenv.c: Include <stdlib.h>. Remove rpl_putenv declaration.
+       (putenv): Renamed from rpl_putenv. Change argument type from
+       'const char *' to 'char *'.
+       * m4/putenv.m4 (gl_FUNC_PUTENV): Require gl_STDLIB_H_DEFAULTS. Instead
+       of defining putenv in config.h, just set REPLACE_PUTENV.
+       * modules/putenv (Depends-on): Add stdlib.
+       (configure.ac): Invoke gl_STDLIB_MODULE_INDICATOR.
+       (Include): Use <stdlib.h>.
+       * lib/stdlib.in.h (putenv): New declaration.
+       * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_PUTENV and
+       REPLACE_PUTENV.
+       * modules/stdlib (Makefile.am): Substitute GNULIB_PUTENV and
+       REPLACE_PUTENV.
+       Needed for MacOS X 10.5.0.
+       Reported by Peter O'Gorman <peter@pogma.com>.
+
 2007-11-01  Jim Meyering  <meyering@redhat.com>
 
        Treat an empty date string exactly like "0".
index 1d24a57..351b403 100644 (file)
 
 #include <config.h>
 
-/* undef putenv here, because some (e.g., Solaris 10) declare putenv in
-   with a non-const argument.  That would conflict with the declaration of
-   rpl_putenv below (due to the #define putenv rpl_putenv from config.h).  */
-#undef putenv
-int rpl_putenv (char const *);
+/* Specification.  */
+#include <stdlib.h>
 
 #include <stddef.h>
 
@@ -95,7 +92,7 @@ _unsetenv (const char *name)
 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
    If STRING contains no `=', then remove STRING from the environment.  */
 int
-rpl_putenv (const char *string)
+putenv (char *string)
 {
   const char *const name_end = strchr (string, '=');
   register size_t size;
@@ -131,7 +128,7 @@ rpl_putenv (const char *string)
       environ = new_environ;
     }
   else
-    *ep = (char *) string;
+    *ep = string;
 
   return 0;
 }
index a297e9e..7221ba2 100644 (file)
@@ -167,6 +167,21 @@ extern int mkstemp (char * /*template*/);
 #endif
 
 
+#if @GNULIB_PUTENV@
+# if @REPLACE_PUTENV@
+#  undef putenv
+#  define putenv rpl_putenv
+extern int putenv (char *string);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef putenv
+# define putenv(s) \
+    (GL_LINK_WARNING ("putenv is not POSIX compliant everywhere - " \
+                      "use gnulib module putenv for portability"), \
+     putenv (s))
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif
index 43a5dc5..ba7c5c7 100644 (file)
@@ -1,5 +1,5 @@
-# putenv.m4 serial 12
-dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+# putenv.m4 serial 13
+dnl Copyright (C) 2002-2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -10,8 +10,10 @@ dnl Check whether putenv ("FOO") removes FOO from the environment.
 dnl The putenv in libc on at least SunOS 4.1.4 does *not* do that.
 
 AC_DEFUN([gl_FUNC_PUTENV],
-[AC_CACHE_CHECK([for SVID conformant putenv], jm_cv_func_svid_putenv,
-  [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],[
+[
+  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+  AC_CACHE_CHECK([for SVID conformant putenv], jm_cv_func_svid_putenv,
+   [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],[
     /* Put it in env.  */
     if (putenv ("CONFTEST_putenv=val"))
       return 1;
@@ -30,10 +32,9 @@ AC_DEFUN([gl_FUNC_PUTENV],
             jm_cv_func_svid_putenv=no,
             dnl When crosscompiling, assume putenv is broken.
             jm_cv_func_svid_putenv=no)
-  ])
+   ])
   if test $jm_cv_func_svid_putenv = no; then
+    REPLACE_PUTENV=1
     AC_LIBOBJ(putenv)
-    AC_DEFINE(putenv, rpl_putenv,
-      [Define to rpl_putenv if the replacement function should be used.])
   fi
 ])
index ea9286e..278df74 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 3
+# stdlib_h.m4 serial 4
 dnl Copyright (C) 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,6 +25,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
+  GNULIB_PUTENV=0;        AC_SUBST([GNULIB_PUTENV])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_CALLOC_POSIX=1;    AC_SUBST([HAVE_CALLOC_POSIX])
   HAVE_GETSUBOPT=1;       AC_SUBST([HAVE_GETSUBOPT])
@@ -32,4 +33,5 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_MKDTEMP=1;         AC_SUBST([HAVE_MKDTEMP])
   HAVE_REALLOC_POSIX=1;   AC_SUBST([HAVE_REALLOC_POSIX])
   REPLACE_MKSTEMP=0;      AC_SUBST([REPLACE_MKSTEMP])
+  REPLACE_PUTENV=0;       AC_SUBST([REPLACE_PUTENV])
 ])
index cba6a04..06a0710 100644 (file)
@@ -6,14 +6,17 @@ lib/putenv.c
 m4/putenv.m4
 
 Depends-on:
+stdlib
 malloc-posix
 
 configure.ac:
 gl_FUNC_PUTENV
+gl_STDLIB_MODULE_INDICATOR([putenv])
 
 Makefile.am:
 
 Include:
+#include <stdlib.h>
 
 License:
 LGPL
index 5a63df5..1c6b4f2 100644 (file)
@@ -29,12 +29,14 @@ stdlib.h: stdlib.in.h
              -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
              -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
              -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
+             -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
              -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
              -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
              -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
              -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
              -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
              -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
+             -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/stdlib.in.h; \
        } > $@-t