From 3b99ec70a69f55388d8cf2f8e433ee93f5edbaa5 Mon Sep 17 00:00:00 2001 From: fxcoudert Date: Thu, 23 Aug 2007 13:03:35 +0000 Subject: [PATCH] PR libfortran/23138 * acinclude.m4 (LIBGFOR_CHECK_MINGW_SNPRINTF): New check. * configure.ac: Use LIBGFOR_CHECK_MINGW_SNPRINTF. * libgfortran.h: If HAVE_MINGW_SNPRINTF is true, use __mingw_snprintf instead of snprintf. * config.h.in: Regenerate. * configure: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127739 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgfortran/ChangeLog | 10 ++++++ libgfortran/acinclude.m4 | 16 ++++++++++ libgfortran/config.h.in | 3 ++ libgfortran/configure | 77 +++++++++++++++++++++++++++++++++++++++++++++++ libgfortran/configure.ac | 3 ++ libgfortran/libgfortran.h | 10 ++++++ 6 files changed, 119 insertions(+) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 2fabcb2..e9832a0 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,13 @@ +2007-08-23 Francois-Xavier Coudert + + PR libfortran/23138 + * acinclude.m4 (LIBGFOR_CHECK_MINGW_SNPRINTF): New check. + * configure.ac: Use LIBGFOR_CHECK_MINGW_SNPRINTF. + * libgfortran.h: If HAVE_MINGW_SNPRINTF is true, use __mingw_snprintf + instead of snprintf. + * config.h.in: Regenerate. + * configure: Regenerate. + 2007-08-22 Bernhard Fischer * libgfortran/Makefile.am (AM_CPPFLAGS): Commentary typo fix. diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4 index 1270a98..40ce535 100644 --- a/libgfortran/acinclude.m4 +++ b/libgfortran/acinclude.m4 @@ -386,3 +386,19 @@ AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [ AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.]) fi ]) + +dnl Check whether we have a mingw that provides a __mingw_snprintf function +AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [ + AC_CACHE_CHECK([whether __mingw_snprintf is present], have_mingw_snprintf, [ + AC_TRY_LINK([ +#include +extern int __mingw_snprintf (char *, size_t, const char *, ...); +],[ +__mingw_snprintf (NULL, 0, "%d\n", 1); +], + eval "have_mingw_snprintf=yes", eval "have_mingw_snprintf=no") + ]) + if test x"$have_mingw_snprintf" = xyes; then + AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.]) + fi +]) diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in index 4099c39..877fc5a 100644 --- a/libgfortran/config.h.in +++ b/libgfortran/config.h.in @@ -522,6 +522,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define if you have __mingw_snprintf. */ +#undef HAVE_MINGW_SNPRINTF + /* Define to 1 if you have the `mkstemp' function. */ #undef HAVE_MKSTEMP diff --git a/libgfortran/configure b/libgfortran/configure index c68cb74..f71c590 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -31797,6 +31797,83 @@ _ACEOF fi +# Check whether __mingw_snprintf() is present + + echo "$as_me:$LINENO: checking whether __mingw_snprintf is present" >&5 +echo $ECHO_N "checking whether __mingw_snprintf is present... $ECHO_C" >&6 +if test "${have_mingw_snprintf+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + if test x$gcc_no_link = xyes; then + { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5 +echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;} + { (exit 1); exit 1; }; } +fi +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +extern int __mingw_snprintf (char *, size_t, const char *, ...); + +int +main () +{ + +__mingw_snprintf (NULL, 0, "%d\n", 1); + + ; + 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 + eval "have_mingw_snprintf=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "have_mingw_snprintf=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi +echo "$as_me:$LINENO: result: $have_mingw_snprintf" >&5 +echo "${ECHO_T}$have_mingw_snprintf" >&6 + if test x"$have_mingw_snprintf" = xyes; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_MINGW_SNPRINTF 1 +_ACEOF + + fi + + # Check for GNU libc feenableexcept echo "$as_me:$LINENO: checking for feenableexcept in -lm" >&5 echo $ECHO_N "checking for feenableexcept in -lm... $ECHO_C" >&6 diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index 8709e16..8aa3b63 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -383,6 +383,9 @@ LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY # Check whether the system has a working stat() LIBGFOR_CHECK_WORKING_STAT +# Check whether __mingw_snprintf() is present +LIBGFOR_CHECK_MINGW_SNPRINTF + # Check for GNU libc feenableexcept AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])]) diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index ce6d28e..6c687f7 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -70,6 +70,16 @@ typedef off_t gfc_offset; #endif +/* On mingw, work around the buggy Windows snprintf() by using the one + mingw provides, __mingw_snprintf(). We also provide a prototype for + __mingw_snprintf(), because the mingw headers currently don't have one. */ +#if HAVE_MINGW_SNPRINTF +extern int __mingw_snprintf (char *, size_t, const char *, ...); +#undef snprintf +#define snprintf __mingw_snprintf +#endif + + /* For a library, a standard prefix is a requirement in order to partition the namespace. IPREFIX is for symbols intended to be internal to the library. */ -- 2.7.4