From 95ca965ed65a64988bc7bbac06a89fa3dd59a4c9 Mon Sep 17 00:00:00 2001 From: gmcgarry Date: Sun, 27 Apr 2008 11:31:40 +0000 Subject: [PATCH] Attempt to detect presence of C99 size specifiers on systems with old/cut-down libc. --- config.h.in | 5 +++- configure | 78 +++++++++++++++++++++++++++++++++++++++++++++++----- configure.ac | 21 ++++++++++++-- 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/config.h.in b/config.h.in index ebf8ed65..c27a5395 100644 --- a/config.h.in +++ b/config.h.in @@ -36,7 +36,10 @@ /* Define to 1 if you have the `basename' function. */ #undef HAVE_BASENAME -/* Define to 1 if your compiler supports GNU GCC-style variadic macros */ +/* Define to 1 if printf supports C99 size specifiers */ +#undef HAVE_C99_FORMAT + +/* Define to 1 if your compiler supports C99 variadic macros */ #undef HAVE_CPP_VARARG_MACRO_GCC /* Define to 1 if you have the `ffs' function. */ diff --git a/configure b/configure index 45b4033b..865397b1 100755 --- a/configure +++ b/configure @@ -4085,8 +4085,8 @@ echo "${ECHO_T}no" >&6 fi -echo "$as_me:$LINENO: checking for GNU GCC variadic macro support" >&5 -echo $ECHO_N "checking for GNU GCC variadic macro support... $ECHO_C" >&6 +echo "$as_me:$LINENO: checking for C99 variadic macro support" >&5 +echo $ECHO_N "checking for C99 variadic macro support... $ECHO_C" >&6 if test "${ac_have_variadic+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else @@ -4139,11 +4139,6 @@ _ACEOF fi - -# Checks for libraries. - -# Checks for header files. -# AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h]) ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4632,6 +4627,75 @@ fi done +echo "$as_me:$LINENO: checking for C99 printf size specifiers" >&5 +echo $ECHO_N "checking for C99 printf size specifiers... $ECHO_C" >&6 +if test "${ac_have_c99_format+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + if test "$cross_compiling" = yes; then + ac_have_c99_format=yes +else + cat >conftest.$ac_ext <<_ACEOF + + /* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ + + char buf[64]; + if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5) + exit(1); + else if (strcmp(buf, "12345")) + exit(2); + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./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_have_c99_format=yes +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + ac_have_c99_format=no +fi +rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + +fi +echo "$as_me:$LINENO: result: $ac_have_c99_format" >&5 +echo "${ECHO_T}$ac_have_c99_format" >&6 +if test $ac_have_c99_format = yes; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_C99_FORMAT 1 +_ACEOF + +fi + +# Checks for libraries. + +# Checks for header files. +# AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h]) diff --git a/configure.ac b/configure.ac index f66b270d..2ffb81d0 100644 --- a/configure.ac +++ b/configure.ac @@ -218,7 +218,7 @@ fi AC_CHECK_PROG(strip,strip,yes,no) -AC_CACHE_CHECK([for GNU GCC variadic macro support], ac_have_variadic, [ +AC_CACHE_CHECK([for C99 variadic macro support], ac_have_variadic, [ AC_COMPILE_IFELSE([ #define macro(...) func(__VA_ARGS__) int func(int a, ...); @@ -226,9 +226,26 @@ AC_CACHE_CHECK([for GNU GCC variadic macro support], ac_have_variadic, [ ], [ ac_have_variadic=yes ], [ ac_have_variadic=no ])]) if test $ac_have_variadic = yes ; then AC_DEFINE([HAVE_CPP_VARARG_MACRO_GCC], 1, - [Define to 1 if your compiler supports GNU GCC-style variadic macros]) + [Define to 1 if your compiler supports C99 variadic macros]) fi +AC_CACHE_CHECK([for C99 printf size specifiers], ac_have_c99_format, [ + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[ + char buf[64]; + if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5) + exit(1); + else if (strcmp(buf, "12345")) + exit(2); + ]])], + [ ac_have_c99_format=yes ], + [ ac_have_c99_format=no ], + [ ac_have_c99_format=yes ]) +]) +if test $ac_have_c99_format = yes; then + AC_DEFINE([HAVE_C99_FORMAT], 1, + [Define to 1 if printf supports C99 size specifiers]) +fi # Checks for libraries.