Handle the case when (v)snprintf have the format declared as char* instead of

const char*.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35438 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Michael Wetherell
2005-09-07 18:28:03 +00:00
parent c4295812f4
commit 62fa8b3a1d
5 changed files with 323 additions and 11 deletions

231
configure vendored
View File

@@ -28093,6 +28093,74 @@ echo "$as_me: error: can't link a simple motif program" >&2;}
{ (exit 1); exit 1; }; }
fi
echo "$as_me:$LINENO: checking for SgCreateList in -lSgm" >&5
echo $ECHO_N "checking for SgCreateList in -lSgm... $ECHO_C" >&6
if test "${ac_cv_lib_Sgm_SgCreateList+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lSgm $LIBS"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char SgCreateList ();
int
main ()
{
SgCreateList ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 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_c_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_exeext'
{ (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
ac_cv_lib_Sgm_SgCreateList=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_Sgm_SgCreateList=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_Sgm_SgCreateList" >&5
echo "${ECHO_T}$ac_cv_lib_Sgm_SgCreateList" >&6
if test $ac_cv_lib_Sgm_SgCreateList = yes; then
libsgm_link=" -lSgm"
fi
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $TOOLKIT_INCLUDE"
echo "$as_me:$LINENO: checking for Motif 2" >&5
@@ -28230,7 +28298,7 @@ fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS=$save_CFLAGS
GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXm${libp_link} -lXmu -lXext -lXt${libsm_ice_link} -lX11"
GUI_TK_LIBRARY="$GUI_TK_LIBRARY${libsgm_link} -lXm${libp_link} -lXmu -lXext -lXt${libsm_ice_link} -lX11"
TOOLKIT=MOTIF
GUIDIST=MOTIF_DIST
fi
@@ -31498,8 +31566,7 @@ main ()
char *buf;
va_list ap;
const char *fmt = "%s";
vsnprintf(buf, 10u, fmt, ap);
vsnprintf(buf, 10u, "%s", ap);
;
return 0;
@@ -31546,6 +31613,84 @@ echo "${ECHO_T}$wx_cv_func_vsnprintf_decl" >&6
#define HAVE_VSNPRINTF_DECL 1
_ACEOF
echo "$as_me:$LINENO: checking if vsnprintf declaration is broken" >&5
echo $ECHO_N "checking if vsnprintf declaration is broken... $ECHO_C" >&6
if test "${wx_cv_func_broken_vsnprintf_decl+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <stdio.h>
#include <stdarg.h>
#ifdef __MSL__
#if __MSL__ >= 0x6000
namespace std {}
using namespace std;
#endif
#endif
int
main ()
{
char *buf;
va_list ap;
const char *fmt = "%s";
vsnprintf(buf, 10u, fmt, ap);
;
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
wx_cv_func_broken_vsnprintf_decl=no
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
wx_cv_func_broken_vsnprintf_decl=yes
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: $wx_cv_func_broken_vsnprintf_decl" >&5
echo "${ECHO_T}$wx_cv_func_broken_vsnprintf_decl" >&6
if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_BROKEN_VSNPRINTF_DECL 1
_ACEOF
fi
fi
fi
@@ -31577,8 +31722,7 @@ main ()
{
char *buf;
const char *fmt = "%s";
snprintf(buf, 10u, fmt, "wx");
snprintf(buf, 10u, "%s", "wx");
;
return 0;
@@ -31625,6 +31769,83 @@ echo "${ECHO_T}$wx_cv_func_snprintf_decl" >&6
#define HAVE_SNPRINTF_DECL 1
_ACEOF
echo "$as_me:$LINENO: checking if snprintf declaration is broken" >&5
echo $ECHO_N "checking if snprintf declaration is broken... $ECHO_C" >&6
if test "${wx_cv_func_broken_snprintf_decl+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <stdio.h>
#include <stdarg.h>
#ifdef __MSL__
#if __MSL__ >= 0x6000
namespace std {}
using namespace std;
#endif
#endif
int
main ()
{
char *buf;
const char *fmt = "%s";
snprintf(buf, 10u, fmt, "wx");
;
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
wx_cv_func_broken_snprintf_decl=no
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
wx_cv_func_broken_snprintf_decl=yes
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: $wx_cv_func_broken_snprintf_decl" >&5
echo "${ECHO_T}$wx_cv_func_broken_snprintf_decl" >&6
if test "$wx_cv_func_broken_snprintf_decl" = "yes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_BROKEN_SNPRINTF_DECL 1
_ACEOF
fi
fi
fi

View File

@@ -3997,8 +3997,7 @@ if test "$ac_cv_func_vsnprintf" = "yes"; then
[
char *buf;
va_list ap;
const char *fmt = "%s";
vsnprintf(buf, 10u, fmt, ap);
vsnprintf(buf, 10u, "%s", ap);
],
wx_cv_func_vsnprintf_decl=yes,
wx_cv_func_vsnprintf_decl=no
@@ -4008,6 +4007,37 @@ if test "$ac_cv_func_vsnprintf" = "yes"; then
if test "$wx_cv_func_vsnprintf_decl" = "yes"; then
AC_DEFINE(HAVE_VSNPRINTF_DECL)
dnl we know there is a vsnprintf declaration, but some old headers
dnl may have one taking a "char *" format instead of "const char *"
AC_CACHE_CHECK([if vsnprintf declaration is broken], wx_cv_func_broken_vsnprintf_decl,
[
AC_TRY_COMPILE(
[
#include <stdio.h>
#include <stdarg.h>
#ifdef __MSL__
#if __MSL__ >= 0x6000
namespace std {}
using namespace std;
#endif
#endif
],
[
char *buf;
va_list ap;
const char *fmt = "%s";
vsnprintf(buf, 10u, fmt, ap);
],
wx_cv_func_broken_vsnprintf_decl=no,
wx_cv_func_broken_vsnprintf_decl=yes
)
]
)
if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then
AC_DEFINE(HAVE_BROKEN_VSNPRINTF_DECL)
fi
fi
fi
@@ -4029,8 +4059,7 @@ if test "$ac_cv_func_snprintf" = "yes"; then
],
[
char *buf;
const char *fmt = "%s";
snprintf(buf, 10u, fmt, "wx");
snprintf(buf, 10u, "%s", "wx");
],
wx_cv_func_snprintf_decl=yes,
wx_cv_func_snprintf_decl=no
@@ -4040,6 +4069,36 @@ if test "$ac_cv_func_snprintf" = "yes"; then
if test "$wx_cv_func_snprintf_decl" = "yes"; then
AC_DEFINE(HAVE_SNPRINTF_DECL)
dnl we know there is an snprintf declaration, but some old headers
dnl may have one taking a "char *" format instead of "const char *"
AC_CACHE_CHECK([if snprintf declaration is broken], wx_cv_func_broken_snprintf_decl,
[
AC_TRY_COMPILE(
[
#include <stdio.h>
#include <stdarg.h>
#ifdef __MSL__
#if __MSL__ >= 0x6000
namespace std {}
using namespace std;
#endif
#endif
],
[
char *buf;
const char *fmt = "%s";
snprintf(buf, 10u, fmt, "wx");
],
wx_cv_func_broken_snprintf_decl=no,
wx_cv_func_broken_snprintf_decl=yes
)
]
)
if test "$wx_cv_func_broken_snprintf_decl" = "yes"; then
AC_DEFINE(HAVE_BROKEN_SNPRINTF_DECL)
fi
fi
fi

View File

@@ -802,6 +802,16 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
int snprintf(char *str, size_t size, const char *format, ...);
#endif /* !HAVE_SNPRINTF_DECL */
/* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
* same isn't done for snprintf below, the builtin wxSnprintf_ is used
* instead since it's already a simple wrapper */
#ifdef HAVE_BROKEN_VSNPRINTF_DECL
inline int wx_fixed_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
return vsnprintf(str, size, (char*)format, ap);
}
#endif
/*
First of all, we always want to define safe snprintf() function to be used
instead of sprintf(). Some compilers already have it (or rather vsnprintf()
@@ -831,10 +841,16 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
/* all versions of CodeWarrior supported by wxWidgets apparently have */
/* both snprintf() and vsnprintf() */
#if defined(HAVE_SNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
#define wxSnprintf_ snprintf
#ifndef HAVE_BROKEN_SNPRINTF_DECL
#define wxSnprintf_ snprintf
#endif
#endif
#if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
#define wxVsnprintf_ vsnprintf
#ifndef HAVE_BROKEN_VSNPRINTF_DECL
#define wxVsnprintf_ vsnprintf
#else
#define wxVsnprintf_ wx_fixed_vsnprintf
#endif
#endif
#endif
#endif /* wxVsnprintf_ not defined yet */

View File

@@ -769,6 +769,10 @@
/* Define if you have snprintf() declaration in the header */
#undef HAVE_SNPRINTF_DECL
/* Define if you have a _broken_ snprintf() declaration in the header,
* with 'char*' for the 3rd parameter instead of 'const char*' */
#undef HAVE_BROKEN_SNPRINTF_DECL
/* define if you have statfs function */
#undef HAVE_STATFS
@@ -793,6 +797,10 @@
/* Define if you have vsnprintf() declaration in the header */
#undef HAVE_VSNPRINTF_DECL
/* Define if you have a _broken_ vsnprintf() declaration in the header,
* with 'char*' for the 3rd parameter instead of 'const char*' */
#undef HAVE_BROKEN_VSNPRINTF_DECL
/* Define if you have usleep() */
#undef HAVE_USLEEP

View File

@@ -813,6 +813,10 @@
/* Define if you have snprintf() declaration in the header */
#undef HAVE_SNPRINTF_DECL
/* Define if you have a _broken_ snprintf() declaration in the header,
* with 'char*' for the 3rd parameter instead of 'const char*' */
#undef HAVE_BROKEN_SNPRINTF_DECL
/* define if you have statfs function */
#undef HAVE_STATFS
@@ -837,6 +841,10 @@
/* Define if you have vsnprintf() declaration in the header */
#undef HAVE_VSNPRINTF_DECL
/* Define if you have a _broken_ vsnprintf() declaration in the header,
* with 'char*' for the 3rd parameter instead of 'const char*' */
#undef HAVE_BROKEN_VSNPRINTF_DECL
/* Define if you have usleep() */
#define HAVE_USLEEP 1