From: Bruno Haible Date: Thu, 1 Nov 2007 12:23:33 +0000 (+0100) Subject: Define the putenv substitute in rather than in . X-Git-Tag: v0.1~8016 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=2de77d6200b862971181d66a52de3d434ff7f47b;p=gnulib.git Define the putenv substitute in rather than in . --- diff --git a/ChangeLog b/ChangeLog index c5348926b..7866e745c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2007-11-01 Bruno Haible + + * lib/putenv.c: Include . 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 . + * 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 . + 2007-11-01 Jim Meyering Treat an empty date string exactly like "0". diff --git a/lib/putenv.c b/lib/putenv.c index 1d24a578d..351b40360 100644 --- a/lib/putenv.c +++ b/lib/putenv.c @@ -19,11 +19,8 @@ #include -/* 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 #include @@ -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; } diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index a297e9e56..7221ba245 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -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 diff --git a/m4/putenv.m4 b/m4/putenv.m4 index 43a5dc5be..ba7c5c743 100644 --- a/m4/putenv.m4 +++ b/m4/putenv.m4 @@ -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 ]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index ea9286ef4..278df744c 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -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]) ]) diff --git a/modules/putenv b/modules/putenv index cba6a047b..06a0710cb 100644 --- a/modules/putenv +++ b/modules/putenv @@ -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 License: LGPL diff --git a/modules/stdlib b/modules/stdlib index 5a63df531..1c6b4f23b 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -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