From 4a767dd5cd3134a9b291c97140ab49347340c813 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 22 Aug 2005 22:46:33 +0000 Subject: [PATCH] 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 --- configure | 82 ++++++++++++++++++++++++++++++++++++++++++++- configure.in | 34 ++++++++++++++++++- include/wx/wxchar.h | 18 +++++++--- setup.h.in | 6 ++++ setup.h_vms | 6 ++++ 5 files changed, 140 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 6331bb8866..ab3ac0ee66 100755 --- a/configure +++ b/configure @@ -31382,7 +31382,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -for ac_func in vsnprintf + +for ac_func in snprintf vsnprintf do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -31563,6 +31564,85 @@ _ACEOF 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 + #include + #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 diff --git a/configure.in b/configure.in index c409dd47ef..f557bd7da9 100644 --- a/configure.in +++ b/configure.in @@ -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 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 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 +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 + #include + #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 dnl also look if we have wide char IO functions AC_CHECK_FUNCS(wputc wputchar putws fputws wprintf vswprintf) diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index 604bc2879c..461bd9219f 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -781,7 +781,7 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */ /* 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. */ #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); #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 instead of sprintf(). Some compilers already have it (or rather vsnprintf() @@ -820,11 +829,12 @@ WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */ #endif #else /* ASCII */ /* all versions of CodeWarrior supported by wxWidgets apparently have */ - /* vsnprintf() */ + /* both snprintf() and vsnprintf() */ + #ifdef HAVE_SNPRINTF || defined(__MWERKS__) || defined(__WATCOMC__) + #define wxSnprintf_ snprintf + #endif #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__) - /* assume we have snprintf() too if we have vsnprintf() */ #define wxVsnprintf_ vsnprintf - #define wxSnprintf_ snprintf #endif #endif #endif /* wxVsnprintf_ not defined yet */ diff --git a/setup.h.in b/setup.h.in index 3094b511cf..9308b9b34c 100644 --- a/setup.h.in +++ b/setup.h.in @@ -760,6 +760,12 @@ /* Define if you 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 */ #undef HAVE_STATFS diff --git a/setup.h_vms b/setup.h_vms index 4f6b80e93f..af1e6594b9 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -804,6 +804,12 @@ /* Define if you 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 */ #undef HAVE_STATFS -- 2.47.2