added test for snprintf() which may not be present in system headers, treat it similarly to vsnprintf() instead of assuming that it's always there

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35270 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-08-22 22:46:33 +00:00
parent 5844fc0775
commit 4a767dd5cd
5 changed files with 141 additions and 7 deletions

82
configure vendored
View File

@@ -31382,7 +31382,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
for ac_func in vsnprintf
for ac_func in snprintf vsnprintf
do do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5 echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -31563,6 +31564,85 @@ _ACEOF
fi fi
fi fi
if test "$ac_cv_func_snprintf" = "yes"; then
echo "$as_me:$LINENO: checking for snprintf declaration" >&5
echo $ECHO_N "checking for snprintf declaration... $ECHO_C" >&6
if test "${wx_cv_func_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_snprintf_decl=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
wx_cv_func_snprintf_decl=no
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: $wx_cv_func_snprintf_decl" >&5
echo "${ECHO_T}$wx_cv_func_snprintf_decl" >&6
if test "$wx_cv_func_snprintf_decl" = "yes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_SNPRINTF_DECL 1
_ACEOF
fi
fi
if test "$wxUSE_UNICODE" = yes; then if test "$wxUSE_UNICODE" = yes; then

View File

@@ -3932,7 +3932,7 @@ dnl stupidly, provides a dummy function declaration inside its extension)
dnl succeeds, even with C++ compiler, but the compilation of wxWidgets fails dnl succeeds, even with C++ compiler, but the compilation of wxWidgets fails
dnl dnl
dnl so we first check if the function is in the library dnl so we first check if the function is in the library
AC_CHECK_FUNCS(vsnprintf) AC_CHECK_FUNCS(snprintf vsnprintf)
if test "$ac_cv_func_vsnprintf" = "yes"; then if test "$ac_cv_func_vsnprintf" = "yes"; then
dnl yes it is -- now check if it is in the headers dnl yes it is -- now check if it is in the headers
@@ -3970,6 +3970,38 @@ if test "$ac_cv_func_vsnprintf" = "yes"; then
fi fi
fi fi
dnl the same as above but for snprintf() now: it's not present in at least AIX
dnl 4.2 headers
if test "$ac_cv_func_snprintf" = "yes"; then
AC_CACHE_CHECK([for snprintf declaration], wx_cv_func_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_snprintf_decl=yes,
wx_cv_func_snprintf_decl=no
)
]
)
if test "$wx_cv_func_snprintf_decl" = "yes"; then
AC_DEFINE(HAVE_SNPRINTF_DECL)
fi
fi
if test "$wxUSE_UNICODE" = yes; then if test "$wxUSE_UNICODE" = yes; then
dnl also look if we have wide char IO functions dnl also look if we have wide char IO functions
AC_CHECK_FUNCS(wputc wputchar putws fputws wprintf vswprintf) AC_CHECK_FUNCS(wputc wputchar putws fputws wprintf vswprintf)

View File

@@ -781,7 +781,7 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
/* printf() family saga */ /* printf() family saga */
/* /*
For some systems vsnprintf() exists in the system libraries but not in the For some systems [v]snprintf() exists in the system libraries but not in the
headers, so we need to declare it ourselves to be able to use it. headers, so we need to declare it ourselves to be able to use it.
*/ */
#if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL) #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
@@ -793,6 +793,15 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
int vsnprintf(char *str, size_t size, const char *format, va_list ap); int vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif /* !HAVE_VSNPRINTF_DECL */ #endif /* !HAVE_VSNPRINTF_DECL */
#if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
#ifdef __cplusplus
extern "C"
#else
extern
#endif
int snprintf(char *str, size_t size, const char *format, ...);
#endif /* !HAVE_SNPRINTF_DECL */
/* /*
First of all, we always want to define safe snprintf() function to be used 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() instead of sprintf(). Some compilers already have it (or rather vsnprintf()
@@ -820,12 +829,13 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
#endif #endif
#else /* ASCII */ #else /* ASCII */
/* all versions of CodeWarrior supported by wxWidgets apparently have */ /* all versions of CodeWarrior supported by wxWidgets apparently have */
/* vsnprintf() */ /* both snprintf() and vsnprintf() */
#if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__) #ifdef HAVE_SNPRINTF || defined(__MWERKS__) || defined(__WATCOMC__)
/* assume we have snprintf() too if we have vsnprintf() */
#define wxVsnprintf_ vsnprintf
#define wxSnprintf_ snprintf #define wxSnprintf_ snprintf
#endif #endif
#if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
#define wxVsnprintf_ vsnprintf
#endif
#endif #endif
#endif /* wxVsnprintf_ not defined yet */ #endif /* wxVsnprintf_ not defined yet */

View File

@@ -760,6 +760,12 @@
/* Define if you have shl_load() */ /* Define if you have shl_load() */
#undef HAVE_SHL_LOAD #undef HAVE_SHL_LOAD
/* Define if you have snprintf() */
#undef HAVE_SNPRINTF
/* Define if you have snprintf() declaration in the header */
#undef HAVE_SNPRINTF_DECL
/* define if you have statfs function */ /* define if you have statfs function */
#undef HAVE_STATFS #undef HAVE_STATFS

View File

@@ -804,6 +804,12 @@
/* Define if you have shl_load() */ /* Define if you have shl_load() */
#undef HAVE_SHL_LOAD #undef HAVE_SHL_LOAD
/* Define if you have snprintf() */
#undef HAVE_SNPRINTF
/* Define if you have snprintf() declaration in the header */
#undef HAVE_SNPRINTF_DECL
/* define if you have statfs function */ /* define if you have statfs function */
#undef HAVE_STATFS #undef HAVE_STATFS