From f536f0053913f5c9407e734e3c6cb5af8897ace1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Sep 2005 22:34:03 +0000 Subject: [PATCH] don't declare strptime() ourselves if the system already does it, we might have a slightly different declaration and this causes problems git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35699 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- configure | 83 +++++++++++++++++++++++++++++++++++++++++ configure.in | 27 +++++++++++++- src/common/datetime.cpp | 6 +-- 3 files changed, 111 insertions(+), 5 deletions(-) diff --git a/configure b/configure index dcfac727bb..b4a3a93efa 100755 --- a/configure +++ b/configure @@ -38965,6 +38965,89 @@ _ACEOF fi done + if test "$ac_cv_func_strptime" = "yes"; then + echo "$as_me:$LINENO: checking for strptime declaration" >&5 +echo $ECHO_N "checking for strptime declaration... $ECHO_C" >&6 +if test "${wx_cv_func_strptime_decl+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + + + ac_ext=cc +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + 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 () +{ + + struct tm t; + strptime("foo", "bar", &t); + + ; + 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_strptime_decl=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +wx_cv_func_strptime_decl=no + +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +fi +echo "$as_me:$LINENO: result: $wx_cv_func_strptime_decl" >&5 +echo "${ECHO_T}$wx_cv_func_strptime_decl" >&6 + fi + if test "$wx_cv_func_strptime_decl" = "yes"; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_STRPTIME_DECL 1 +_ACEOF + + fi echo "$as_me:$LINENO: checking for timezone variable in " >&5 echo $ECHO_N "checking for timezone variable in ... $ECHO_C" >&6 diff --git a/configure.in b/configure.in index 905f546f7c..1f9311a28d 100644 --- a/configure.in +++ b/configure.in @@ -5436,11 +5436,34 @@ fi dnl --------------------------------------------------------------------------- dnl time/date functions -dnl ------------------------------------------------------------------------ +dnl --------------------------------------------------------------------------- if test "$wxUSE_DATETIME" = "yes"; then - dnl check for strptime + dnl check for strptime and for its declaration as some systems lack it AC_CHECK_FUNCS(strptime) + if test "$ac_cv_func_strptime" = "yes"; then + AC_CACHE_CHECK([for strptime declaration], wx_cv_func_strptime_decl, + [ + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE( + [ + #include + ], + [ + struct tm t; + strptime("foo", "bar", &t); + ], + wx_cv_func_strptime_decl=yes, + wx_cv_func_strptime_decl=no + ) + AC_LANG_RESTORE + ] + ) + fi + if test "$wx_cv_func_strptime_decl" = "yes"; then + AC_DEFINE(HAVE_STRPTIME_DECL) + fi dnl check for timezone variable dnl doesn't exist under Darwin / Mac OS X which uses tm_gmtoff instead diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 6622496e33..e00d14f757 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -392,9 +392,9 @@ static wxString CallStrftime(const wxChar *format, const tm* tm) #ifdef HAVE_STRPTIME -// glibc2 doesn't define this in the headers unless _XOPEN_SOURCE is defined -// which, unfortunately, wreaks havoc elsewhere -#if defined(__GLIBC__) && (__GLIBC__ == 2) +#if wxUSE_UNIX && !defined(HAVE_STRPTIME_DECL) + // configure detected that we had strptime() but not its declaration, + // provide it ourselves extern "C" char *strptime(const char *, const char *, struct tm *); #endif -- 2.45.2