handle putenv arg constness in configure

This commit is contained in:
dockes 2007-07-14 16:53:00 +00:00
parent 6ed2673331
commit 94b6fa9dd5
8 changed files with 83 additions and 11 deletions

View File

@ -24,3 +24,5 @@
/* iconv parameter 2 is const char** */
#undef RCL_ICONV_INBUF_CONST
/* putenv parameter is const */
#undef PUTENV_ARG_CONST

60
src/configure vendored
View File

@ -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 <stdlib.h>
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

View File

@ -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 <stdlib.h>
],[
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

View File

@ -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++

View File

@ -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="<sys/mount.h>"

View File

@ -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

View File

@ -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++

View File

@ -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 <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
@ -27,7 +30,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.24 2007-05-23 08:28:35 dockes Exp
#include <errno.h>
#include <signal.h>
#ifdef PUTENV_ARG_NOT_CONST
#if !defined(PUTENV_ARG_CONST)
#include <string.h>
#endif
@ -360,10 +363,10 @@ int ExecCmd::doexec(const string &cmd, const list<string>& args,
for (vector<string>::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);