diff --git a/src/common/autoconfig.h.in b/src/common/autoconfig.h.in index 15fc12e1..c701088d 100644 --- a/src/common/autoconfig.h.in +++ b/src/common/autoconfig.h.in @@ -24,3 +24,5 @@ /* iconv parameter 2 is const char** */ #undef RCL_ICONV_INBUF_CONST +/* putenv parameter is const */ +#undef PUTENV_ARG_CONST diff --git a/src/configure b/src/configure index 8fa0c57a..c7105c54 100755 --- a/src/configure +++ b/src/configure @@ -2341,6 +2341,66 @@ _ACEOF fi + +echo "$as_me:$LINENO: checking for type of string parameter to putenv" >&5 +echo $ECHO_N "checking for type of string parameter to putenv... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + #include + +int +main () +{ + + putenv((const char *)0); + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_cxx_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + rcl_putenv_string_const="1" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +rcl_putenv_string_const="0" +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +if test X$rcl_putenv_string_const = X1 ; then + +cat >>confdefs.h <<\_ACEOF +#define PUTENV_ARG_CONST 1 +_ACEOF + +fi + #### Look for Xapian # Extract the first word of "xapian-config", so it can be a program name with args. set dummy xapian-config; ac_word=$2 diff --git a/src/configure.ac b/src/configure.ac index af4c6fb3..2f401da5 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -155,6 +155,17 @@ if test X$rcl_iconv_inbuf_const = X1 ; then AC_DEFINE(RCL_ICONV_INBUF_CONST, 1, [iconv parameter 2 is const char**]) fi + +AC_MSG_CHECKING(for type of string parameter to putenv) +AC_TRY_COMPILE([ + #include + ],[ + putenv((const char *)0); + ], rcl_putenv_string_const="1", rcl_putenv_string_const="0") +if test X$rcl_putenv_string_const = X1 ; then + AC_DEFINE(PUTENV_ARG_CONST, 1, [putenv parameter is const]) +fi + #### Look for Xapian AC_PATH_PROG(XAPIAN_CONFIG, xapian-config, no) if test "$XAPIAN_CONFIG" = "no" ; then diff --git a/src/mk/AIX b/src/mk/AIX index c94c1795..2302a01b 100644 --- a/src/mk/AIX +++ b/src/mk/AIX @@ -1,8 +1,7 @@ include $(depth)/mk/commondefs include $(depth)/mk/localdefs -ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \ - -DPUTENV_ARG_NOT_CONST +ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) CC = gcc CXX = g++ diff --git a/src/mk/Darwin b/src/mk/Darwin index 49f5cd46..05512b83 100644 --- a/src/mk/Darwin +++ b/src/mk/Darwin @@ -2,7 +2,6 @@ include $(depth)/mk/commondefs include $(depth)/mk/localdefs ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \ - -DPUTENV_ARG_NOT_CONST \ -DHAVE_VASPRINTF=1 \ -DHAVE_MKDTEMP=1 \ -DSTATFS_INCLUDE="" diff --git a/src/mk/Linux b/src/mk/Linux index 02b650c0..3457d9e5 100644 --- a/src/mk/Linux +++ b/src/mk/Linux @@ -4,7 +4,6 @@ include $(depth)/mk/localdefs ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \ -D_GNU_SOURCE \ - -DPUTENV_ARG_NOT_CONST \ -DHAVE_VASPRINTF=1 \ -DHAVE_MKDTEMP=1 diff --git a/src/mk/SunOS b/src/mk/SunOS index 71f143bf..784c0960 100644 --- a/src/mk/SunOS +++ b/src/mk/SunOS @@ -1,8 +1,7 @@ include $(depth)/mk/commondefs include $(depth)/mk/localdefs -ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \ - -DPUTENV_ARG_NOT_CONST +ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) CC = gcc CXX = g++ diff --git a/src/utils/execmd.cpp b/src/utils/execmd.cpp index 4333603f..3b8df3ff 100644 --- a/src/utils/execmd.cpp +++ b/src/utils/execmd.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: execmd.cpp,v 1.24 2007-05-23 08:28:35 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: execmd.cpp,v 1.25 2007-07-14 16:53:00 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -18,6 +18,9 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.24 2007-05-23 08:28:35 dockes Exp * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TEST_EXECMD +#include "autoconfig.h" + +#include #include #include #include @@ -27,7 +30,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.24 2007-05-23 08:28:35 dockes Exp #include #include -#ifdef PUTENV_ARG_NOT_CONST +#if !defined(PUTENV_ARG_CONST) #include #endif @@ -360,10 +363,10 @@ int ExecCmd::doexec(const string &cmd, const list& args, for (vector::const_iterator it = m_env.begin(); it != m_env.end(); it++) { -#ifdef PUTENV_ARG_NOT_CONST - ::putenv(strdup(it->c_str())); -#else +#ifdef PUTENV_ARG_CONST ::putenv(it->c_str()); +#else + ::putenv(strdup(it->c_str())); #endif } execvp(cmd.c_str(), (char *const*)argv);