From c35424ca7907f3c8bea67d3e0015ece45462e6ad Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 22 May 2015 22:12:42 +1000 Subject: [PATCH] all of NEED*PRINT are needed if %z is not supported (cherry picked from commit 7507c1826f7a7d6820d1323f6091e4d1aef29320) --- configure | 120 ++++++++++++++++++++++++---------------------- configure.in | 78 +++++++++++++++--------------- lib/lwres/print.c | 22 ++++++++- 3 files changed, 122 insertions(+), 98 deletions(-) diff --git a/configure b/configure index 6bbc7bc218..41b7e2b36e 100755 --- a/configure +++ b/configure @@ -719,8 +719,6 @@ LWRES_PLATFORM_USEDECLSPEC ISC_PLATFORM_USEDECLSPEC ISC_PLATFORM_RLIMITTYPE ISC_PLATFORM_HAVESYSUNH -ISC_PLATFORM_NEEDFPRINTF -ISC_PLATFORM_NEEDPRINTF LWRES_PLATFORM_QUADFORMAT ISC_PLATFORM_QUADFORMAT DST_EXTRA_SRCS @@ -729,9 +727,11 @@ USE_ISC_SPNEGO ISC_EXTRA_SRCS ISC_EXTRA_OBJS LWRES_PLATFORM_NEEDVSNPRINTF -ISC_PLATFORM_NEEDVSNPRINTF LWRES_PLATFORM_NEEDSPRINTF +ISC_PLATFORM_NEEDVSNPRINTF ISC_PLATFORM_NEEDSPRINTF +ISC_PLATFORM_NEEDFPRINTF +ISC_PLATFORM_NEEDPRINTF READLINE_LIB ISC_PLATFORM_NEEDSTRCASESTR ISC_PLATFORM_NEEDSTRLCAT @@ -18625,8 +18625,14 @@ esac ISC_PRINT_OBJS= ISC_PRINT_SRCS= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sprintf" >&5 -$as_echo_n "checking sprintf... " >&6; } +ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' +ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF' +ISC_PLATFORM_NEEDSPRINTF='#undef ISC_PLATFORM_NEEDSPRINTF' +ISC_PLATFORM_NEEDVSNPRINTF='#undef ISC_PLATFORM_NEEDVSNPRINTF' +LWRES_PLATFORM_NEEDVSNPRINTF='#undef LWRES_PLATFORM_NEEDVSNPRINTF' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sprintf return type" >&5 +$as_echo_n "checking sprintf return type... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -18641,25 +18647,22 @@ main () } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - + { $as_echo "$as_me:${as_lineno-$LINENO}: result: char *" >&5 +$as_echo "char *" >&6; } ISC_PRINT_OBJS="print.$O" ISC_PRINT_SRCS="print.c" ISC_PLATFORM_NEEDSPRINTF="#define ISC_PLATFORM_NEEDSPRINTF" LWRES_PLATFORM_NEEDSPRINTF="#define LWRES_PLATFORM_NEEDSPRINTF" else - ISC_PLATFORM_NEEDSPRINTF="#undef ISC_PLATFORM_NEEDSPRINTF" - LWRES_PLATFORM_NEEDSPRINTF="#undef LWRES_PLATFORM_NEEDSPRINTF" - + { $as_echo "$as_me:${as_lineno-$LINENO}: result: int" >&5 +$as_echo "int" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf" if test "x$ac_cv_func_vsnprintf" = xyes; then : - ISC_PLATFORM_NEEDVSNPRINTF="#undef ISC_PLATFORM_NEEDVSNPRINTF" - LWRES_PLATFORM_NEEDVSNPRINTF="#undef LWRES_PLATFORM_NEEDVSNPRINTF" + else ISC_PRINT_OBJS="print.$O" ISC_PRINT_SRCS="print.c" @@ -18668,20 +18671,62 @@ else fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking printf for %z support" >&5 +$as_echo_n "checking printf for %z support... " >&6; } +if test "$cross_compiling" = yes; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: assuming target platform supports %z" >&5 +$as_echo "assuming target platform supports %z" >&6; } +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +main() { + size_t j = 0; + char buf[100]; + buf[0] = 0; + sprintf(buf, "%zu", j); + exit(strcmp(buf, "0") != 0); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ISC_PRINT_OBJS="print.$O" + ISC_PRINT_SRCS="print.c" + ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1' + ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1' + ISC_PLATFORM_NEEDFSRINTF='#define ISC_PLATFORM_NEEDSPRINTF 1' + ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1" + LWRES_PLATFORM_NEEDVSNPRINTF="#define LWRES_PLATFORM_NEEDVSNPRINTF 1" +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + + + + + + + ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS $ISC_PRINT_OBJS" ISC_EXTRA_SRCS="$ISC_EXTRA_SRCS $ISC_PRINT_SRCS" + + ac_fn_c_check_func "$LINENO" "strerror" "ac_cv_func_strerror" if test "x$ac_cv_func_strerror" = xyes; then : $as_echo "#define HAVE_STRERROR 1" >>confdefs.h fi - - - - # # Use our own SPNEGO implementation? # @@ -18766,47 +18811,6 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking printf for %z support" >&5 -$as_echo_n "checking printf for %z support... " >&6; } -if test "$cross_compiling" = yes; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: assuming target platform supports %z" >&5 -$as_echo "assuming target platform supports %z" >&6; } - ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' - ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF' -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#include -main() { - /* Assume sprintf matches printf/fprintf. */ - size_t j = 0; - char buf[100]; - buf[0] = 0; - sprintf(buf, "%zu", j); - exit(strcmp(buf, "0") != 0); -} - -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' - ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF' -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - ISC_PRINT_OBJS="print.$O" - ISC_PRINT_SRCS="print.c" - ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1' - ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1' -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - - - # # Security Stuff diff --git a/configure.in b/configure.in index 05f05c98ec..e99804aa51 100644 --- a/configure.in +++ b/configure.in @@ -3248,40 +3248,65 @@ esac ISC_PRINT_OBJS= ISC_PRINT_SRCS= -AC_MSG_CHECKING(sprintf) +ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' +ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF' +ISC_PLATFORM_NEEDSPRINTF='#undef ISC_PLATFORM_NEEDSPRINTF' +ISC_PLATFORM_NEEDVSNPRINTF='#undef ISC_PLATFORM_NEEDVSNPRINTF' +LWRES_PLATFORM_NEEDVSNPRINTF='#undef LWRES_PLATFORM_NEEDVSNPRINTF' + +AC_MSG_CHECKING(sprintf return type) AC_TRY_COMPILE([ #include ], [ char buf[2]; return(*sprintf(buf,"x"));], -[ +[AC_MSG_RESULT(char *) ISC_PRINT_OBJS="print.$O" ISC_PRINT_SRCS="print.c" ISC_PLATFORM_NEEDSPRINTF="#define ISC_PLATFORM_NEEDSPRINTF" LWRES_PLATFORM_NEEDSPRINTF="#define LWRES_PLATFORM_NEEDSPRINTF" -], -[ISC_PLATFORM_NEEDSPRINTF="#undef ISC_PLATFORM_NEEDSPRINTF" - LWRES_PLATFORM_NEEDSPRINTF="#undef LWRES_PLATFORM_NEEDSPRINTF"] -) -AC_SUBST(ISC_PLATFORM_NEEDSPRINTF) -AC_SUBST(LWRES_PLATFORM_NEEDSPRINTF) +],[AC_MSG_RESULT(int)]) -AC_CHECK_FUNC(vsnprintf, - [ISC_PLATFORM_NEEDVSNPRINTF="#undef ISC_PLATFORM_NEEDVSNPRINTF" - LWRES_PLATFORM_NEEDVSNPRINTF="#undef LWRES_PLATFORM_NEEDVSNPRINTF"], +AC_CHECK_FUNC(vsnprintf, [], [ISC_PRINT_OBJS="print.$O" ISC_PRINT_SRCS="print.c" ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1" LWRES_PLATFORM_NEEDVSNPRINTF="#define LWRES_PLATFORM_NEEDVSNPRINTF 1"]) + +AC_MSG_CHECKING(printf for %z support) +AC_TRY_RUN([ +#include +main() { + size_t j = 0; + char buf[100]; + buf[0] = 0; + sprintf(buf, "%zu", j); + exit(strcmp(buf, "0") != 0); +} +], + [AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no) + ISC_PRINT_OBJS="print.$O" + ISC_PRINT_SRCS="print.c" + ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1' + ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1' + ISC_PLATFORM_NEEDFSRINTF='#define ISC_PLATFORM_NEEDSPRINTF 1' + ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1" + LWRES_PLATFORM_NEEDVSNPRINTF="#define LWRES_PLATFORM_NEEDVSNPRINTF 1"], + [AC_MSG_RESULT(assuming target platform supports %z)]) + +AC_SUBST(ISC_PLATFORM_NEEDPRINTF) +AC_SUBST(ISC_PLATFORM_NEEDFPRINTF) +AC_SUBST(ISC_PLATFORM_NEEDSPRINTF) AC_SUBST(ISC_PLATFORM_NEEDVSNPRINTF) +AC_SUBST(LWRES_PLATFORM_NEEDSPRINTF) AC_SUBST(LWRES_PLATFORM_NEEDVSNPRINTF) + ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS $ISC_PRINT_OBJS" ISC_EXTRA_SRCS="$ISC_EXTRA_SRCS $ISC_PRINT_SRCS" - -AC_CHECK_FUNC(strerror, AC_DEFINE(HAVE_STRERROR)) - AC_SUBST(ISC_EXTRA_OBJS) AC_SUBST(ISC_EXTRA_SRCS) +AC_CHECK_FUNC(strerror, AC_DEFINE(HAVE_STRERROR)) # # Use our own SPNEGO implementation? # @@ -3345,31 +3370,6 @@ main() { AC_SUBST(ISC_PLATFORM_QUADFORMAT) AC_SUBST(LWRES_PLATFORM_QUADFORMAT) -AC_MSG_CHECKING([printf for %z support]) -AC_TRY_RUN([ -#include -main() { - /* Assume sprintf matches printf/fprintf. */ - size_t j = 0; - char buf[100]; - buf[0] = 0; - sprintf(buf, "%zu", j); - exit(strcmp(buf, "0") != 0); -} -], - [AC_MSG_RESULT(yes) - ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' - ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF'], - [AC_MSG_RESULT(no) - ISC_PRINT_OBJS="print.$O" - ISC_PRINT_SRCS="print.c" - ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1' - ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1'], - [AC_MSG_RESULT([assuming target platform supports %z]) - ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF' - ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF']) -AC_SUBST(ISC_PLATFORM_NEEDPRINTF) -AC_SUBST(ISC_PLATFORM_NEEDFPRINTF) # # Security Stuff diff --git a/lib/lwres/print.c b/lib/lwres/print.c index 4f44814bec..8a9c64aa5c 100644 --- a/lib/lwres/print.c +++ b/lib/lwres/print.c @@ -66,6 +66,7 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { int h; int l; int q; + int z; int alt; int zero; int left; @@ -110,7 +111,7 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { /* * Reset flags. */ - dot = space = plus = left = zero = alt = h = l = q = 0; + dot = space = plus = left = zero = alt = h = l = q = z = 0; width = precision = 0; head = ""; length = pad = zeropad = 0; @@ -194,6 +195,10 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { format++; } goto doint; + case 'z': + z = 1; + format++; + goto doint; case 'n': case 'i': case 'd': @@ -216,6 +221,11 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { p = va_arg(ap, long *); REQUIRE(p != NULL); *p = str - save; + } else if (z) { + size_t *p; + p = va_arg(ap, size_t *); + REQUIRE(p != NULL); + *p = str - save; } else { int *p; p = va_arg(ap, int *); @@ -229,6 +239,8 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { tmpi = va_arg(ap, long long int); else if (l) tmpi = va_arg(ap, long int); + else if (z) + tmpi = va_arg(ap, size_t); else tmpi = va_arg(ap, int); if (tmpi < 0) { @@ -252,6 +264,8 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long long int); else if (l) tmpui = va_arg(ap, long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, int); sprintf(buf, @@ -265,6 +279,8 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long long int); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); sprintf(buf, "%" LWRES_PRINT_QUADFORMAT "u", @@ -276,6 +292,8 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long long int); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); if (alt) { @@ -292,6 +310,8 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned long long int); else if (l) tmpui = va_arg(ap, unsigned long int); + else if (z) + tmpui = va_arg(ap, size_t); else tmpui = va_arg(ap, unsigned int); if (alt) {