1# printf.m4 serial 70 2dnl Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl Test whether the *printf family of functions supports the 'j', 'z', 't', 8dnl 'L' size specifiers. (ISO C99, POSIX:2001) 9dnl Result is gl_cv_func_printf_sizes_c99. 10 11AC_DEFUN([gl_PRINTF_SIZES_C99], 12[ 13 AC_REQUIRE([AC_PROG_CC]) 14 AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 15 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 17 AC_CACHE_CHECK([whether printf supports size specifiers as in C99], 18 [gl_cv_func_printf_sizes_c99], 19 [ 20 AC_RUN_IFELSE( 21 [AC_LANG_SOURCE([[ 22#include <stddef.h> 23#include <stdio.h> 24#include <string.h> 25#include <sys/types.h> 26#if HAVE_STDINT_H_WITH_UINTMAX 27# include <stdint.h> 28#endif 29#if HAVE_INTTYPES_H_WITH_UINTMAX 30# include <inttypes.h> 31#endif 32static char buf[100]; 33int main () 34{ 35 int result = 0; 36#if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX 37 buf[0] = '\0'; 38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0 39 || strcmp (buf, "12345671 33") != 0) 40 result |= 1; 41#else 42 result |= 1; 43#endif 44 buf[0] = '\0'; 45 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0 46 || strcmp (buf, "12345672 33") != 0) 47 result |= 2; 48 buf[0] = '\0'; 49 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0 50 || strcmp (buf, "12345673 33") != 0) 51 result |= 4; 52 buf[0] = '\0'; 53 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0 54 || strcmp (buf, "1.5 33") != 0) 55 result |= 8; 56 return result; 57}]])], 58 [gl_cv_func_printf_sizes_c99=yes], 59 [gl_cv_func_printf_sizes_c99=no], 60 [ 61 case "$host_os" in 62changequote(,)dnl 63 # Guess yes on glibc systems. 64 *-gnu* | gnu*) gl_cv_func_printf_sizes_c99="guessing yes";; 65 # Guess yes on musl systems. 66 *-musl*) gl_cv_func_printf_sizes_c99="guessing yes";; 67 # Guess yes on FreeBSD >= 5. 68 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";; 69 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";; 70 # Guess yes on Mac OS X >= 10.3. 71 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";; 72 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";; 73 # Guess yes on OpenBSD >= 3.9. 74 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) 75 gl_cv_func_printf_sizes_c99="guessing no";; 76 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; 77 # Guess yes on Solaris >= 2.10. 78 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; 79 solaris*) gl_cv_func_printf_sizes_c99="guessing no";; 80 # Guess yes on NetBSD >= 3. 81 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 82 gl_cv_func_printf_sizes_c99="guessing no";; 83 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; 84 # Guess yes on Android. 85 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";; 86changequote([,])dnl 87 # Guess yes on MSVC, no on mingw. 88 mingw*) AC_EGREP_CPP([Known], [ 89#ifdef _MSC_VER 90 Known 91#endif 92 ], 93 [gl_cv_func_printf_sizes_c99="guessing yes"], 94 [gl_cv_func_printf_sizes_c99="guessing no"]) 95 ;; 96 # If we don't know, obey --enable-cross-guesses. 97 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";; 98 esac 99 ]) 100 ]) 101]) 102 103dnl Test whether the *printf family of functions supports 'long double' 104dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001) 105dnl Result is gl_cv_func_printf_long_double. 106 107AC_DEFUN([gl_PRINTF_LONG_DOUBLE], 108[ 109 AC_REQUIRE([AC_PROG_CC]) 110 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 111 AC_CACHE_CHECK([whether printf supports 'long double' arguments], 112 [gl_cv_func_printf_long_double], 113 [ 114 AC_RUN_IFELSE( 115 [AC_LANG_SOURCE([[ 116#include <stdio.h> 117#include <string.h> 118static char buf[10000]; 119int main () 120{ 121 int result = 0; 122 buf[0] = '\0'; 123 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0 124 || strcmp (buf, "1.750000 33") != 0) 125 result |= 1; 126 buf[0] = '\0'; 127 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0 128 || strcmp (buf, "1.750000e+00 33") != 0) 129 result |= 2; 130 buf[0] = '\0'; 131 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0 132 || strcmp (buf, "1.75 33") != 0) 133 result |= 4; 134 return result; 135}]])], 136 [gl_cv_func_printf_long_double=yes], 137 [gl_cv_func_printf_long_double=no], 138 [case "$host_os" in 139 # Guess no on BeOS. 140 beos*) gl_cv_func_printf_long_double="guessing no";; 141 # Guess yes on Android. 142 linux*-android*) gl_cv_func_printf_long_double="guessing yes";; 143 # Guess yes on MSVC, no on mingw. 144 mingw*) AC_EGREP_CPP([Known], [ 145#ifdef _MSC_VER 146 Known 147#endif 148 ], 149 [gl_cv_func_printf_long_double="guessing yes"], 150 [gl_cv_func_printf_long_double="guessing no"]) 151 ;; 152 *) gl_cv_func_printf_long_double="guessing yes";; 153 esac 154 ]) 155 ]) 156]) 157 158dnl Test whether the *printf family of functions supports infinite and NaN 159dnl 'double' arguments and negative zero arguments in the %f, %e, %g 160dnl directives. (ISO C99, POSIX:2001) 161dnl Result is gl_cv_func_printf_infinite. 162 163AC_DEFUN([gl_PRINTF_INFINITE], 164[ 165 AC_REQUIRE([AC_PROG_CC]) 166 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 167 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments], 168 [gl_cv_func_printf_infinite], 169 [ 170 AC_RUN_IFELSE( 171 [AC_LANG_SOURCE([[ 172#include <stdio.h> 173#include <string.h> 174static int 175strisnan (const char *string, size_t start_index, size_t end_index) 176{ 177 if (start_index < end_index) 178 { 179 if (string[start_index] == '-') 180 start_index++; 181 if (start_index + 3 <= end_index 182 && memcmp (string + start_index, "nan", 3) == 0) 183 { 184 start_index += 3; 185 if (start_index == end_index 186 || (string[start_index] == '(' && string[end_index - 1] == ')')) 187 return 1; 188 } 189 } 190 return 0; 191} 192static int 193have_minus_zero () 194{ 195 static double plus_zero = 0.0; 196 double minus_zero = - plus_zero; 197 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0; 198} 199static char buf[10000]; 200static double zero = 0.0; 201int main () 202{ 203 int result = 0; 204 if (sprintf (buf, "%f", 1.0 / zero) < 0 205 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 206 result |= 1; 207 if (sprintf (buf, "%f", -1.0 / zero) < 0 208 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 209 result |= 1; 210 if (sprintf (buf, "%f", zero / zero) < 0 211 || !strisnan (buf, 0, strlen (buf))) 212 result |= 2; 213 if (sprintf (buf, "%e", 1.0 / zero) < 0 214 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 215 result |= 4; 216 if (sprintf (buf, "%e", -1.0 / zero) < 0 217 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 218 result |= 4; 219 if (sprintf (buf, "%e", zero / zero) < 0 220 || !strisnan (buf, 0, strlen (buf))) 221 result |= 8; 222 if (sprintf (buf, "%g", 1.0 / zero) < 0 223 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 224 result |= 16; 225 if (sprintf (buf, "%g", -1.0 / zero) < 0 226 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 227 result |= 16; 228 if (sprintf (buf, "%g", zero / zero) < 0 229 || !strisnan (buf, 0, strlen (buf))) 230 result |= 32; 231 /* This test fails on HP-UX 10.20. */ 232 if (have_minus_zero ()) 233 if (sprintf (buf, "%g", - zero) < 0 234 || strcmp (buf, "-0") != 0) 235 result |= 64; 236 return result; 237}]])], 238 [gl_cv_func_printf_infinite=yes], 239 [gl_cv_func_printf_infinite=no], 240 [ 241 case "$host_os" in 242changequote(,)dnl 243 # Guess yes on glibc systems. 244 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";; 245 # Guess yes on musl systems. 246 *-musl*) gl_cv_func_printf_infinite="guessing yes";; 247 # Guess yes on FreeBSD >= 6. 248 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";; 249 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";; 250 # Guess yes on Mac OS X >= 10.3. 251 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";; 252 darwin*) gl_cv_func_printf_infinite="guessing yes";; 253 # Guess yes on HP-UX >= 11. 254 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";; 255 hpux*) gl_cv_func_printf_infinite="guessing yes";; 256 # Guess yes on NetBSD >= 3. 257 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 258 gl_cv_func_printf_infinite="guessing no";; 259 netbsd*) gl_cv_func_printf_infinite="guessing yes";; 260 # Guess yes on OpenBSD >= 6.0. 261 openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";; 262 openbsd*) gl_cv_func_printf_infinite="guessing yes";; 263 # Guess yes on BeOS. 264 beos*) gl_cv_func_printf_infinite="guessing yes";; 265 # Guess no on Android. 266 linux*-android*) gl_cv_func_printf_infinite="guessing no";; 267changequote([,])dnl 268 # Guess yes on MSVC, no on mingw. 269 mingw*) AC_EGREP_CPP([Known], [ 270#ifdef _MSC_VER 271 Known 272#endif 273 ], 274 [gl_cv_func_printf_infinite="guessing yes"], 275 [gl_cv_func_printf_infinite="guessing no"]) 276 ;; 277 # If we don't know, obey --enable-cross-guesses. 278 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";; 279 esac 280 ]) 281 ]) 282]) 283 284dnl Test whether the *printf family of functions supports infinite and NaN 285dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) 286dnl Result is gl_cv_func_printf_infinite_long_double. 287 288AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE], 289[ 290 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) 291 AC_REQUIRE([AC_PROG_CC]) 292 AC_REQUIRE([gl_BIGENDIAN]) 293 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) 294 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 295 dnl The user can set or unset the variable gl_printf_safe to indicate 296 dnl that he wishes a safe handling of non-IEEE-754 'long double' values. 297 if test -n "$gl_printf_safe"; then 298 AC_DEFINE([CHECK_PRINTF_SAFE], [1], 299 [Define if you wish *printf() functions that have a safe handling of 300 non-IEEE-754 'long double' values.]) 301 fi 302 case "$gl_cv_func_printf_long_double" in 303 *yes) 304 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments], 305 [gl_cv_func_printf_infinite_long_double], 306 [ 307 AC_RUN_IFELSE( 308 [AC_LANG_SOURCE([[ 309]GL_NOCRASH[ 310#include <float.h> 311#include <stdio.h> 312#include <string.h> 313static int 314strisnan (const char *string, size_t start_index, size_t end_index) 315{ 316 if (start_index < end_index) 317 { 318 if (string[start_index] == '-') 319 start_index++; 320 if (start_index + 3 <= end_index 321 && memcmp (string + start_index, "nan", 3) == 0) 322 { 323 start_index += 3; 324 if (start_index == end_index 325 || (string[start_index] == '(' && string[end_index - 1] == ')')) 326 return 1; 327 } 328 } 329 return 0; 330} 331static char buf[10000]; 332static long double zeroL = 0.0L; 333int main () 334{ 335 int result = 0; 336 nocrash_init(); 337 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0 338 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 339 result |= 1; 340 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0 341 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 342 result |= 1; 343 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0 344 || !strisnan (buf, 0, strlen (buf))) 345 result |= 1; 346 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0 347 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 348 result |= 1; 349 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0 350 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 351 result |= 1; 352 if (sprintf (buf, "%Le", zeroL / zeroL) < 0 353 || !strisnan (buf, 0, strlen (buf))) 354 result |= 1; 355 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0 356 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) 357 result |= 1; 358 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0 359 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) 360 result |= 1; 361 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0 362 || !strisnan (buf, 0, strlen (buf))) 363 result |= 1; 364#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE 365/* Representation of an 80-bit 'long double' as an initializer for a sequence 366 of 'unsigned int' words. */ 367# ifdef WORDS_BIGENDIAN 368# define LDBL80_WORDS(exponent,manthi,mantlo) \ 369 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ 370 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \ 371 (unsigned int) (mantlo) << 16 \ 372 } 373# else 374# define LDBL80_WORDS(exponent,manthi,mantlo) \ 375 { mantlo, manthi, exponent } 376# endif 377 { /* Quiet NaN. */ 378 static union { unsigned int word[4]; long double value; } x = 379 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; 380 if (sprintf (buf, "%Lf", x.value) < 0 381 || !strisnan (buf, 0, strlen (buf))) 382 result |= 2; 383 if (sprintf (buf, "%Le", x.value) < 0 384 || !strisnan (buf, 0, strlen (buf))) 385 result |= 2; 386 if (sprintf (buf, "%Lg", x.value) < 0 387 || !strisnan (buf, 0, strlen (buf))) 388 result |= 2; 389 } 390 { 391 /* Signalling NaN. */ 392 static union { unsigned int word[4]; long double value; } x = 393 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; 394 if (sprintf (buf, "%Lf", x.value) < 0 395 || !strisnan (buf, 0, strlen (buf))) 396 result |= 2; 397 if (sprintf (buf, "%Le", x.value) < 0 398 || !strisnan (buf, 0, strlen (buf))) 399 result |= 2; 400 if (sprintf (buf, "%Lg", x.value) < 0 401 || !strisnan (buf, 0, strlen (buf))) 402 result |= 2; 403 } 404 { /* Pseudo-NaN. */ 405 static union { unsigned int word[4]; long double value; } x = 406 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; 407 if (sprintf (buf, "%Lf", x.value) <= 0) 408 result |= 4; 409 if (sprintf (buf, "%Le", x.value) <= 0) 410 result |= 4; 411 if (sprintf (buf, "%Lg", x.value) <= 0) 412 result |= 4; 413 } 414 { /* Pseudo-Infinity. */ 415 static union { unsigned int word[4]; long double value; } x = 416 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; 417 if (sprintf (buf, "%Lf", x.value) <= 0) 418 result |= 8; 419 if (sprintf (buf, "%Le", x.value) <= 0) 420 result |= 8; 421 if (sprintf (buf, "%Lg", x.value) <= 0) 422 result |= 8; 423 } 424 { /* Pseudo-Zero. */ 425 static union { unsigned int word[4]; long double value; } x = 426 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; 427 if (sprintf (buf, "%Lf", x.value) <= 0) 428 result |= 16; 429 if (sprintf (buf, "%Le", x.value) <= 0) 430 result |= 16; 431 if (sprintf (buf, "%Lg", x.value) <= 0) 432 result |= 16; 433 } 434 { /* Unnormalized number. */ 435 static union { unsigned int word[4]; long double value; } x = 436 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; 437 if (sprintf (buf, "%Lf", x.value) <= 0) 438 result |= 32; 439 if (sprintf (buf, "%Le", x.value) <= 0) 440 result |= 32; 441 if (sprintf (buf, "%Lg", x.value) <= 0) 442 result |= 32; 443 } 444 { /* Pseudo-Denormal. */ 445 static union { unsigned int word[4]; long double value; } x = 446 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; 447 if (sprintf (buf, "%Lf", x.value) <= 0) 448 result |= 64; 449 if (sprintf (buf, "%Le", x.value) <= 0) 450 result |= 64; 451 if (sprintf (buf, "%Lg", x.value) <= 0) 452 result |= 64; 453 } 454#endif 455 return result; 456}]])], 457 [gl_cv_func_printf_infinite_long_double=yes], 458 [gl_cv_func_printf_infinite_long_double=no], 459 [case "$host_cpu" in 460 # Guess no on ia64, x86_64, i386. 461 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";; 462 *) 463 case "$host_os" in 464changequote(,)dnl 465 # Guess yes on glibc systems. 466 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";; 467 # Guess yes on musl systems. 468 *-musl*) gl_cv_func_printf_infinite_long_double="guessing yes";; 469 # Guess yes on FreeBSD >= 6. 470 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";; 471 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; 472 # Guess yes on HP-UX >= 11. 473 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; 474 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; 475 # Guess yes on OpenBSD >= 6.0. 476 openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";; 477 openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; 478 # Guess no on Android. 479 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";; 480changequote([,])dnl 481 # Guess yes on MSVC, no on mingw. 482 mingw*) AC_EGREP_CPP([Known], [ 483#ifdef _MSC_VER 484 Known 485#endif 486 ], 487 [gl_cv_func_printf_infinite_long_double="guessing yes"], 488 [gl_cv_func_printf_infinite_long_double="guessing no"]) 489 ;; 490 # If we don't know, obey --enable-cross-guesses. 491 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";; 492 esac 493 ;; 494 esac 495 ]) 496 ]) 497 ;; 498 *) 499 gl_cv_func_printf_infinite_long_double="irrelevant" 500 ;; 501 esac 502]) 503 504dnl Test whether the *printf family of functions supports the 'a' and 'A' 505dnl conversion specifier for hexadecimal output of floating-point numbers. 506dnl (ISO C99, POSIX:2001) 507dnl Result is gl_cv_func_printf_directive_a. 508 509AC_DEFUN([gl_PRINTF_DIRECTIVE_A], 510[ 511 AC_REQUIRE([AC_PROG_CC]) 512 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 513 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives], 514 [gl_cv_func_printf_directive_a], 515 [ 516 AC_RUN_IFELSE( 517 [AC_LANG_SOURCE([[ 518#include <stdio.h> 519#include <string.h> 520static char buf[100]; 521static double zero = 0.0; 522int main () 523{ 524 int result = 0; 525 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0 526 || (strcmp (buf, "0x1.922p+1 33") != 0 527 && strcmp (buf, "0x3.244p+0 33") != 0 528 && strcmp (buf, "0x6.488p-1 33") != 0 529 && strcmp (buf, "0xc.91p-2 33") != 0)) 530 result |= 1; 531 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0 532 || (strcmp (buf, "-0X1.922P+1 33") != 0 533 && strcmp (buf, "-0X3.244P+0 33") != 0 534 && strcmp (buf, "-0X6.488P-1 33") != 0 535 && strcmp (buf, "-0XC.91P-2 33") != 0)) 536 result |= 2; 537 /* This catches a FreeBSD 6.1 bug: it doesn't round. */ 538 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0 539 || (strcmp (buf, "0x1.83p+0 33") != 0 540 && strcmp (buf, "0x3.05p-1 33") != 0 541 && strcmp (buf, "0x6.0ap-2 33") != 0 542 && strcmp (buf, "0xc.14p-3 33") != 0)) 543 result |= 4; 544 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */ 545 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0 546 || (strcmp (buf, "0x2p+0 33") != 0 547 && strcmp (buf, "0x3p-1 33") != 0 548 && strcmp (buf, "0x6p-2 33") != 0 549 && strcmp (buf, "0xcp-3 33") != 0)) 550 result |= 4; 551 /* This catches a FreeBSD 6.1 bug. See 552 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */ 553 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0 554 || buf[0] == '0') 555 result |= 8; 556 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */ 557 if (sprintf (buf, "%.1a", 1.999) < 0 558 || (strcmp (buf, "0x1.0p+1") != 0 559 && strcmp (buf, "0x2.0p+0") != 0 560 && strcmp (buf, "0x4.0p-1") != 0 561 && strcmp (buf, "0x8.0p-2") != 0)) 562 result |= 16; 563 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a 564 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */ 565 if (sprintf (buf, "%.1La", 1.999L) < 0 566 || (strcmp (buf, "0x1.0p+1") != 0 567 && strcmp (buf, "0x2.0p+0") != 0 568 && strcmp (buf, "0x4.0p-1") != 0 569 && strcmp (buf, "0x8.0p-2") != 0)) 570 result |= 32; 571 return result; 572}]])], 573 [gl_cv_func_printf_directive_a=yes], 574 [gl_cv_func_printf_directive_a=no], 575 [ 576 case "$host_os" in 577 # Guess yes on glibc >= 2.5 systems. 578 *-gnu* | gnu*) 579 AC_EGREP_CPP([BZ2908], [ 580 #include <features.h> 581 #ifdef __GNU_LIBRARY__ 582 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__ 583 BZ2908 584 #endif 585 #endif 586 ], 587 [gl_cv_func_printf_directive_a="guessing yes"], 588 [gl_cv_func_printf_directive_a="guessing no"]) 589 ;; 590 # Guess yes on musl systems. 591 *-musl*) gl_cv_func_printf_directive_a="guessing yes";; 592 # Guess no on Android. 593 linux*-android*) gl_cv_func_printf_directive_a="guessing no";; 594 # Guess no on native Windows. 595 mingw*) gl_cv_func_printf_directive_a="guessing no";; 596 # If we don't know, obey --enable-cross-guesses. 597 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";; 598 esac 599 ]) 600 ]) 601]) 602 603dnl Test whether the *printf family of functions supports the %F format 604dnl directive. (ISO C99, POSIX:2001) 605dnl Result is gl_cv_func_printf_directive_f. 606 607AC_DEFUN([gl_PRINTF_DIRECTIVE_F], 608[ 609 AC_REQUIRE([AC_PROG_CC]) 610 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 611 AC_CACHE_CHECK([whether printf supports the 'F' directive], 612 [gl_cv_func_printf_directive_f], 613 [ 614 AC_RUN_IFELSE( 615 [AC_LANG_SOURCE([[ 616#include <stdio.h> 617#include <string.h> 618static char buf[100]; 619static double zero = 0.0; 620int main () 621{ 622 int result = 0; 623 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0 624 || strcmp (buf, "1234567.000000 33") != 0) 625 result |= 1; 626 if (sprintf (buf, "%F", 1.0 / zero) < 0 627 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0)) 628 result |= 2; 629 /* This catches a Cygwin 1.5.x bug. */ 630 if (sprintf (buf, "%.F", 1234.0) < 0 631 || strcmp (buf, "1234") != 0) 632 result |= 4; 633 return result; 634}]])], 635 [gl_cv_func_printf_directive_f=yes], 636 [gl_cv_func_printf_directive_f=no], 637 [ 638 case "$host_os" in 639changequote(,)dnl 640 # Guess yes on glibc systems. 641 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";; 642 # Guess yes on musl systems. 643 *-musl*) gl_cv_func_printf_directive_f="guessing yes";; 644 # Guess yes on FreeBSD >= 6. 645 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";; 646 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";; 647 # Guess yes on Mac OS X >= 10.3. 648 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";; 649 darwin*) gl_cv_func_printf_directive_f="guessing yes";; 650 # Guess yes on OpenBSD >= 6.0. 651 openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";; 652 openbsd*) gl_cv_func_printf_directive_f="guessing yes";; 653 # Guess yes on Solaris >= 2.10. 654 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";; 655 solaris*) gl_cv_func_printf_directive_f="guessing no";; 656 # Guess no on Android. 657 linux*-android*) gl_cv_func_printf_directive_f="guessing no";; 658changequote([,])dnl 659 # Guess yes on MSVC, no on mingw. 660 mingw*) AC_EGREP_CPP([Known], [ 661#ifdef _MSC_VER 662 Known 663#endif 664 ], 665 [gl_cv_func_printf_directive_f="guessing yes"], 666 [gl_cv_func_printf_directive_f="guessing no"]) 667 ;; 668 # If we don't know, obey --enable-cross-guesses. 669 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";; 670 esac 671 ]) 672 ]) 673]) 674 675dnl Test whether the *printf family of functions supports the %n format 676dnl directive. (ISO C99, POSIX:2001) 677dnl Result is gl_cv_func_printf_directive_n. 678 679AC_DEFUN([gl_PRINTF_DIRECTIVE_N], 680[ 681 AC_REQUIRE([AC_PROG_CC]) 682 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 683 AC_CACHE_CHECK([whether printf supports the 'n' directive], 684 [gl_cv_func_printf_directive_n], 685 [ 686 AC_RUN_IFELSE( 687 [AC_LANG_SOURCE([[ 688#include <stdio.h> 689#include <stdlib.h> 690#include <string.h> 691#ifdef _MSC_VER 692#include <inttypes.h> 693/* See page about "Parameter Validation" on msdn.microsoft.com. 694 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation> 695 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */ 696static void cdecl 697invalid_parameter_handler (const wchar_t *expression, 698 const wchar_t *function, 699 const wchar_t *file, unsigned int line, 700 uintptr_t dummy) 701{ 702 exit (1); 703} 704#endif 705static char fmtstring[10]; 706static char buf[100]; 707int main () 708{ 709 int count = -1; 710#ifdef _MSC_VER 711 _set_invalid_parameter_handler (invalid_parameter_handler); 712#endif 713 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) 714 support %n in format strings in read-only memory but not in writable 715 memory. */ 716 strcpy (fmtstring, "%d %n"); 717 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0 718 || strcmp (buf, "123 ") != 0 719 || count != 4) 720 return 1; 721 return 0; 722}]])], 723 [gl_cv_func_printf_directive_n=yes], 724 [gl_cv_func_printf_directive_n=no], 725 [case "$host_os" in 726 # Guess no on glibc when _FORTIFY_SOURCE >= 2. 727 *-gnu* | gnu*) AC_COMPILE_IFELSE( 728 [AC_LANG_SOURCE( 729 [[#if _FORTIFY_SOURCE >= 2 730 error fail 731 #endif 732 ]])], 733 [gl_cv_func_printf_directive_n="guessing yes"], 734 [gl_cv_func_printf_directive_n="guessing no"]) 735 ;; 736 # Guess no on Android. 737 linux*-android*) gl_cv_func_printf_directive_n="guessing no";; 738 # Guess no on native Windows. 739 mingw*) gl_cv_func_printf_directive_n="guessing no";; 740 *) gl_cv_func_printf_directive_n="guessing yes";; 741 esac 742 ]) 743 ]) 744]) 745 746dnl Test whether the *printf family of functions supports the %ls format 747dnl directive and in particular, when a precision is specified, whether 748dnl the functions stop converting the wide string argument when the number 749dnl of bytes that have been produced by this conversion equals or exceeds 750dnl the precision. 751dnl Result is gl_cv_func_printf_directive_ls. 752 753AC_DEFUN([gl_PRINTF_DIRECTIVE_LS], 754[ 755 AC_REQUIRE([AC_PROG_CC]) 756 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 757 AC_CACHE_CHECK([whether printf supports the 'ls' directive], 758 [gl_cv_func_printf_directive_ls], 759 [ 760 AC_RUN_IFELSE( 761 [AC_LANG_SOURCE([[ 762/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 763 <wchar.h>. 764 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 765 included before <wchar.h>. */ 766#include <stddef.h> 767#include <stdio.h> 768#include <time.h> 769#include <wchar.h> 770#include <string.h> 771int main () 772{ 773 int result = 0; 774 char buf[100]; 775 /* Test whether %ls works at all. 776 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on 777 Cygwin 1.5. */ 778 { 779 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 }; 780 buf[0] = '\0'; 781 if (sprintf (buf, "%ls", wstring) < 0 782 || strcmp (buf, "abc") != 0) 783 result |= 1; 784 } 785 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an 786 assertion failure inside libc), but not on OpenBSD 4.0. */ 787 { 788 static const wchar_t wstring[] = { 'a', 0 }; 789 buf[0] = '\0'; 790 if (sprintf (buf, "%ls", wstring) < 0 791 || strcmp (buf, "a") != 0) 792 result |= 2; 793 } 794 /* Test whether precisions in %ls are supported as specified in ISO C 99 795 section 7.19.6.1: 796 "If a precision is specified, no more than that many bytes are written 797 (including shift sequences, if any), and the array shall contain a 798 null wide character if, to equal the multibyte character sequence 799 length given by the precision, the function would need to access a 800 wide character one past the end of the array." 801 This test fails on Solaris 10. */ 802 { 803 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 }; 804 buf[0] = '\0'; 805 if (sprintf (buf, "%.2ls", wstring) < 0 806 || strcmp (buf, "ab") != 0) 807 result |= 8; 808 } 809 return result; 810}]])], 811 [gl_cv_func_printf_directive_ls=yes], 812 [gl_cv_func_printf_directive_ls=no], 813 [ 814changequote(,)dnl 815 case "$host_os" in 816 # Guess yes on OpenBSD >= 6.0. 817 openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";; 818 openbsd*) gl_cv_func_printf_directive_ls="guessing yes";; 819 irix*) gl_cv_func_printf_directive_ls="guessing no";; 820 solaris*) gl_cv_func_printf_directive_ls="guessing no";; 821 cygwin*) gl_cv_func_printf_directive_ls="guessing no";; 822 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; 823 # Guess no on Android. 824 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";; 825 # Guess yes on native Windows. 826 mingw*) gl_cv_func_printf_directive_ls="guessing yes";; 827 *) gl_cv_func_printf_directive_ls="guessing yes";; 828 esac 829changequote([,])dnl 830 ]) 831 ]) 832]) 833 834dnl Test whether the *printf family of functions supports POSIX/XSI format 835dnl strings with positions. (POSIX:2001) 836dnl Result is gl_cv_func_printf_positions. 837 838AC_DEFUN([gl_PRINTF_POSITIONS], 839[ 840 AC_REQUIRE([AC_PROG_CC]) 841 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 842 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions], 843 [gl_cv_func_printf_positions], 844 [ 845 AC_RUN_IFELSE( 846 [AC_LANG_SOURCE([[ 847#include <stdio.h> 848#include <string.h> 849/* The string "%2$d %1$d", with dollar characters protected from the shell's 850 dollar expansion (possibly an autoconf bug). */ 851static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; 852static char buf[100]; 853int main () 854{ 855 sprintf (buf, format, 33, 55); 856 return (strcmp (buf, "55 33") != 0); 857}]])], 858 [gl_cv_func_printf_positions=yes], 859 [gl_cv_func_printf_positions=no], 860 [ 861changequote(,)dnl 862 case "$host_os" in 863 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*) 864 gl_cv_func_printf_positions="guessing no";; 865 beos*) gl_cv_func_printf_positions="guessing no";; 866 # Guess yes on Android. 867 linux*-android*) gl_cv_func_printf_positions="guessing yes";; 868 # Guess no on native Windows. 869 mingw* | pw*) gl_cv_func_printf_positions="guessing no";; 870 *) gl_cv_func_printf_positions="guessing yes";; 871 esac 872changequote([,])dnl 873 ]) 874 ]) 875]) 876 877dnl Test whether the *printf family of functions supports POSIX/XSI format 878dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001) 879dnl Result is gl_cv_func_printf_flag_grouping. 880 881AC_DEFUN([gl_PRINTF_FLAG_GROUPING], 882[ 883 AC_REQUIRE([AC_PROG_CC]) 884 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 885 AC_CACHE_CHECK([whether printf supports the grouping flag], 886 [gl_cv_func_printf_flag_grouping], 887 [ 888 AC_RUN_IFELSE( 889 [AC_LANG_SOURCE([[ 890#include <stdio.h> 891#include <string.h> 892static char buf[100]; 893int main () 894{ 895 if (sprintf (buf, "%'d %d", 1234567, 99) < 0 896 || buf[strlen (buf) - 1] != '9') 897 return 1; 898 return 0; 899}]])], 900 [gl_cv_func_printf_flag_grouping=yes], 901 [gl_cv_func_printf_flag_grouping=no], 902 [ 903changequote(,)dnl 904 case "$host_os" in 905 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; 906 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; 907 # Guess no on Android. 908 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";; 909 # Guess no on native Windows. 910 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; 911 *) gl_cv_func_printf_flag_grouping="guessing yes";; 912 esac 913changequote([,])dnl 914 ]) 915 ]) 916]) 917 918dnl Test whether the *printf family of functions supports the - flag correctly. 919dnl (ISO C99.) See 920dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html> 921dnl Result is gl_cv_func_printf_flag_leftadjust. 922 923AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST], 924[ 925 AC_REQUIRE([AC_PROG_CC]) 926 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 927 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly], 928 [gl_cv_func_printf_flag_leftadjust], 929 [ 930 AC_RUN_IFELSE( 931 [AC_LANG_SOURCE([[ 932#include <stdio.h> 933#include <string.h> 934static char buf[100]; 935int main () 936{ 937 /* Check that a '-' flag is not annihilated by a negative width. */ 938 if (sprintf (buf, "a%-*sc", -3, "b") < 0 939 || strcmp (buf, "ab c") != 0) 940 return 1; 941 return 0; 942}]])], 943 [gl_cv_func_printf_flag_leftadjust=yes], 944 [gl_cv_func_printf_flag_leftadjust=no], 945 [ 946changequote(,)dnl 947 case "$host_os" in 948 # Guess yes on HP-UX 11. 949 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; 950 # Guess no on HP-UX 10 and older. 951 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; 952 # Guess yes on Android. 953 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";; 954 # Guess yes on native Windows. 955 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";; 956 # Guess yes otherwise. 957 *) gl_cv_func_printf_flag_leftadjust="guessing yes";; 958 esac 959changequote([,])dnl 960 ]) 961 ]) 962]) 963 964dnl Test whether the *printf family of functions supports padding of non-finite 965dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See 966dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> 967dnl Result is gl_cv_func_printf_flag_zero. 968 969AC_DEFUN([gl_PRINTF_FLAG_ZERO], 970[ 971 AC_REQUIRE([AC_PROG_CC]) 972 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 973 AC_CACHE_CHECK([whether printf supports the zero flag correctly], 974 [gl_cv_func_printf_flag_zero], 975 [ 976 AC_RUN_IFELSE( 977 [AC_LANG_SOURCE([[ 978#include <stdio.h> 979#include <string.h> 980static char buf[100]; 981static double zero = 0.0; 982int main () 983{ 984 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0 985 || (strcmp (buf, " inf") != 0 986 && strcmp (buf, " infinity") != 0)) 987 return 1; 988 return 0; 989}]])], 990 [gl_cv_func_printf_flag_zero=yes], 991 [gl_cv_func_printf_flag_zero=no], 992 [ 993changequote(,)dnl 994 case "$host_os" in 995 # Guess yes on glibc systems. 996 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";; 997 # Guess yes on musl systems. 998 *-musl*) gl_cv_func_printf_flag_zero="guessing yes";; 999 # Guess yes on BeOS. 1000 beos*) gl_cv_func_printf_flag_zero="guessing yes";; 1001 # Guess no on Android. 1002 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";; 1003 # Guess no on native Windows. 1004 mingw*) gl_cv_func_printf_flag_zero="guessing no";; 1005 # If we don't know, obey --enable-cross-guesses. 1006 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";; 1007 esac 1008changequote([,])dnl 1009 ]) 1010 ]) 1011]) 1012 1013dnl Test whether the *printf family of functions supports large precisions. 1014dnl On mingw, precisions larger than 512 are treated like 512, in integer, 1015dnl floating-point or pointer output. On Solaris 10/x86, precisions larger 1016dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC, 1017dnl precisions larger than 510 in floating-point output yield wrong results. 1018dnl On AIX 7.1, precisions larger than 998 in floating-point output yield 1019dnl wrong results. On BeOS, precisions larger than 1044 crash the program. 1020dnl Result is gl_cv_func_printf_precision. 1021 1022AC_DEFUN([gl_PRINTF_PRECISION], 1023[ 1024 AC_REQUIRE([AC_PROG_CC]) 1025 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1026 AC_CACHE_CHECK([whether printf supports large precisions], 1027 [gl_cv_func_printf_precision], 1028 [ 1029 AC_RUN_IFELSE( 1030 [AC_LANG_SOURCE([[ 1031#include <stdio.h> 1032#include <string.h> 1033static char buf[5000]; 1034int main () 1035{ 1036 int result = 0; 1037#ifdef __BEOS__ 1038 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */ 1039 return 1; 1040#endif 1041 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3) 1042 result |= 1; 1043 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5) 1044 result |= 2; 1045 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5 1046 || buf[0] != '1') 1047 result |= 4; 1048 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5 1049 || buf[0] != '1') 1050 result |= 4; 1051 return result; 1052}]])], 1053 [gl_cv_func_printf_precision=yes], 1054 [gl_cv_func_printf_precision=no], 1055 [ 1056changequote(,)dnl 1057 case "$host_os" in 1058 # Guess no only on Solaris, native Windows, and BeOS systems. 1059 solaris*) gl_cv_func_printf_precision="guessing no" ;; 1060 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; 1061 beos*) gl_cv_func_printf_precision="guessing no" ;; 1062 # Guess yes on Android. 1063 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;; 1064 *) gl_cv_func_printf_precision="guessing yes" ;; 1065 esac 1066changequote([,])dnl 1067 ]) 1068 ]) 1069]) 1070 1071dnl Test whether the *printf family of functions recovers gracefully in case 1072dnl of an out-of-memory condition, or whether it crashes the entire program. 1073dnl Result is gl_cv_func_printf_enomem. 1074 1075AC_DEFUN([gl_PRINTF_ENOMEM], 1076[ 1077 AC_REQUIRE([AC_PROG_CC]) 1078 AC_REQUIRE([gl_MULTIARCH]) 1079 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1080 AC_CACHE_CHECK([whether printf survives out-of-memory conditions], 1081 [gl_cv_func_printf_enomem], 1082 [ 1083 gl_cv_func_printf_enomem="guessing no" 1084 if test "$cross_compiling" = no; then 1085 if test $APPLE_UNIVERSAL_BUILD = 0; then 1086 AC_LANG_CONFTEST([AC_LANG_SOURCE([[ 1087]GL_NOCRASH[ 1088#include <stdio.h> 1089#include <sys/types.h> 1090#include <sys/time.h> 1091#include <sys/resource.h> 1092#include <errno.h> 1093int main() 1094{ 1095 struct rlimit limit; 1096 int ret; 1097 nocrash_init (); 1098 /* Some printf implementations allocate temporary space with malloc. */ 1099 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */ 1100#ifdef RLIMIT_DATA 1101 if (getrlimit (RLIMIT_DATA, &limit) < 0) 1102 return 77; 1103 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) 1104 limit.rlim_max = 5000000; 1105 limit.rlim_cur = limit.rlim_max; 1106 if (setrlimit (RLIMIT_DATA, &limit) < 0) 1107 return 77; 1108#endif 1109 /* On Linux systems, malloc() is limited by RLIMIT_AS. */ 1110#ifdef RLIMIT_AS 1111 if (getrlimit (RLIMIT_AS, &limit) < 0) 1112 return 77; 1113 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) 1114 limit.rlim_max = 5000000; 1115 limit.rlim_cur = limit.rlim_max; 1116 if (setrlimit (RLIMIT_AS, &limit) < 0) 1117 return 77; 1118#endif 1119 /* Some printf implementations allocate temporary space on the stack. */ 1120#ifdef RLIMIT_STACK 1121 if (getrlimit (RLIMIT_STACK, &limit) < 0) 1122 return 77; 1123 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) 1124 limit.rlim_max = 5000000; 1125 limit.rlim_cur = limit.rlim_max; 1126 if (setrlimit (RLIMIT_STACK, &limit) < 0) 1127 return 77; 1128#endif 1129 ret = printf ("%.5000000f", 1.0); 1130 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM)); 1131} 1132 ]])]) 1133 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 1134 (./conftest 2>&AS_MESSAGE_LOG_FD 1135 result=$? 1136 _AS_ECHO_LOG([\$? = $result]) 1137 if test $result != 0 && test $result != 77; then result=1; fi 1138 exit $result 1139 ) >/dev/null 2>/dev/null 1140 case $? in 1141 0) gl_cv_func_printf_enomem="yes" ;; 1142 77) gl_cv_func_printf_enomem="guessing no" ;; 1143 *) gl_cv_func_printf_enomem="no" ;; 1144 esac 1145 else 1146 gl_cv_func_printf_enomem="guessing no" 1147 fi 1148 rm -fr conftest* 1149 else 1150 dnl A universal build on Apple Mac OS X platforms. 1151 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode. 1152 dnl But we need a configuration result that is valid in both modes. 1153 gl_cv_func_printf_enomem="guessing no" 1154 fi 1155 fi 1156 if test "$gl_cv_func_printf_enomem" = "guessing no"; then 1157changequote(,)dnl 1158 case "$host_os" in 1159 # Guess yes on glibc systems. 1160 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";; 1161 # Guess yes on Solaris. 1162 solaris*) gl_cv_func_printf_enomem="guessing yes";; 1163 # Guess yes on AIX. 1164 aix*) gl_cv_func_printf_enomem="guessing yes";; 1165 # Guess yes on HP-UX/hppa. 1166 hpux*) case "$host_cpu" in 1167 hppa*) gl_cv_func_printf_enomem="guessing yes";; 1168 *) gl_cv_func_printf_enomem="guessing no";; 1169 esac 1170 ;; 1171 # Guess yes on IRIX. 1172 irix*) gl_cv_func_printf_enomem="guessing yes";; 1173 # Guess yes on OSF/1. 1174 osf*) gl_cv_func_printf_enomem="guessing yes";; 1175 # Guess yes on BeOS. 1176 beos*) gl_cv_func_printf_enomem="guessing yes";; 1177 # Guess yes on Haiku. 1178 haiku*) gl_cv_func_printf_enomem="guessing yes";; 1179 # Guess no on Android. 1180 linux*-android*) gl_cv_func_printf_enomem="guessing no";; 1181 # If we don't know, obey --enable-cross-guesses. 1182 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";; 1183 esac 1184changequote([,])dnl 1185 fi 1186 ]) 1187]) 1188 1189dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001) 1190dnl Result is ac_cv_func_snprintf. 1191 1192AC_DEFUN([gl_SNPRINTF_PRESENCE], 1193[ 1194 AC_CHECK_FUNCS_ONCE([snprintf]) 1195]) 1196 1197dnl Test whether the string produced by the snprintf function is always NUL 1198dnl terminated. (ISO C99, POSIX:2001) 1199dnl Result is gl_cv_func_snprintf_truncation_c99. 1200 1201AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99], 1202[ 1203 AC_REQUIRE([AC_PROG_CC]) 1204 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1205 AC_REQUIRE([gl_SNPRINTF_PRESENCE]) 1206 AC_CACHE_CHECK([whether snprintf truncates the result as in C99], 1207 [gl_cv_func_snprintf_truncation_c99], 1208 [ 1209 AC_RUN_IFELSE( 1210 [AC_LANG_SOURCE([[ 1211#include <stdio.h> 1212#include <string.h> 1213#if HAVE_SNPRINTF 1214# define my_snprintf snprintf 1215#else 1216# include <stdarg.h> 1217static int my_snprintf (char *buf, int size, const char *format, ...) 1218{ 1219 va_list args; 1220 int ret; 1221 va_start (args, format); 1222 ret = vsnprintf (buf, size, format, args); 1223 va_end (args); 1224 return ret; 1225} 1226#endif 1227static char buf[100]; 1228int main () 1229{ 1230 strcpy (buf, "ABCDEF"); 1231 my_snprintf (buf, 3, "%d %d", 4567, 89); 1232 if (memcmp (buf, "45\0DEF", 6) != 0) 1233 return 1; 1234 return 0; 1235}]])], 1236 [gl_cv_func_snprintf_truncation_c99=yes], 1237 [gl_cv_func_snprintf_truncation_c99=no], 1238 [ 1239changequote(,)dnl 1240 case "$host_os" in 1241 # Guess yes on glibc systems. 1242 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1243 # Guess yes on musl systems. 1244 *-musl*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1245 # Guess yes on FreeBSD >= 5. 1246 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1247 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1248 # Guess yes on Mac OS X >= 10.3. 1249 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1250 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1251 # Guess yes on OpenBSD >= 3.9. 1252 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) 1253 gl_cv_func_snprintf_truncation_c99="guessing no";; 1254 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1255 # Guess yes on Solaris >= 2.6. 1256 solaris2.[0-5] | solaris2.[0-5].*) 1257 gl_cv_func_snprintf_truncation_c99="guessing no";; 1258 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1259 # Guess yes on AIX >= 4. 1260 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1261 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1262 # Guess yes on HP-UX >= 11. 1263 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1264 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1265 # Guess yes on IRIX >= 6.5. 1266 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1267 # Guess yes on OSF/1 >= 5. 1268 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1269 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1270 # Guess yes on NetBSD >= 3. 1271 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 1272 gl_cv_func_snprintf_truncation_c99="guessing no";; 1273 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1274 # Guess yes on BeOS. 1275 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1276 # Guess yes on Android. 1277 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1278 # Guess no on native Windows. 1279 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1280 # If we don't know, obey --enable-cross-guesses. 1281 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";; 1282 esac 1283changequote([,])dnl 1284 ]) 1285 ]) 1286]) 1287 1288dnl Test whether the return value of the snprintf function is the number 1289dnl of bytes (excluding the terminating NUL) that would have been produced 1290dnl if the buffer had been large enough. (ISO C99, POSIX:2001) 1291dnl For example, this test program fails on IRIX 6.5: 1292dnl --------------------------------------------------------------------- 1293dnl #include <stdio.h> 1294dnl int main() 1295dnl { 1296dnl static char buf[8]; 1297dnl int retval = snprintf (buf, 3, "%d", 12345); 1298dnl return retval >= 0 && retval < 3; 1299dnl } 1300dnl --------------------------------------------------------------------- 1301dnl Result is gl_cv_func_snprintf_retval_c99. 1302 1303AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99], 1304[ 1305 AC_REQUIRE([AC_PROG_CC]) 1306 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1307 AC_REQUIRE([gl_SNPRINTF_PRESENCE]) 1308 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99], 1309 [gl_cv_func_snprintf_retval_c99], 1310 [ 1311 AC_RUN_IFELSE( 1312 [AC_LANG_SOURCE([[ 1313#include <stdio.h> 1314#include <string.h> 1315#if HAVE_SNPRINTF 1316# define my_snprintf snprintf 1317#else 1318# include <stdarg.h> 1319static int my_snprintf (char *buf, int size, const char *format, ...) 1320{ 1321 va_list args; 1322 int ret; 1323 va_start (args, format); 1324 ret = vsnprintf (buf, size, format, args); 1325 va_end (args); 1326 return ret; 1327} 1328#endif 1329static char buf[100]; 1330int main () 1331{ 1332 strcpy (buf, "ABCDEF"); 1333 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7) 1334 return 1; 1335 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7) 1336 return 2; 1337 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7) 1338 return 3; 1339 return 0; 1340}]])], 1341 [gl_cv_func_snprintf_retval_c99=yes], 1342 [gl_cv_func_snprintf_retval_c99=no], 1343 [case "$host_os" in 1344changequote(,)dnl 1345 # Guess yes on glibc systems. 1346 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1347 # Guess yes on musl systems. 1348 *-musl*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1349 # Guess yes on FreeBSD >= 5. 1350 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";; 1351 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1352 # Guess yes on Mac OS X >= 10.3. 1353 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";; 1354 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1355 # Guess yes on OpenBSD >= 3.9. 1356 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) 1357 gl_cv_func_snprintf_retval_c99="guessing no";; 1358 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1359 # Guess yes on Solaris >= 2.10. 1360 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; 1361 solaris*) gl_cv_func_printf_sizes_c99="guessing no";; 1362 # Guess yes on AIX >= 4. 1363 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";; 1364 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1365 # Guess yes on NetBSD >= 3. 1366 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 1367 gl_cv_func_snprintf_retval_c99="guessing no";; 1368 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1369 # Guess yes on BeOS. 1370 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1371 # Guess yes on Android. 1372 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1373changequote([,])dnl 1374 # Guess yes on MSVC, no on mingw. 1375 mingw*) AC_EGREP_CPP([Known], [ 1376#ifdef _MSC_VER 1377 Known 1378#endif 1379 ], 1380 [gl_cv_func_snprintf_retval_c99="guessing yes"], 1381 [gl_cv_func_snprintf_retval_c99="guessing no"]) 1382 ;; 1383 # If we don't know, obey --enable-cross-guesses. 1384 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";; 1385 esac 1386 ]) 1387 ]) 1388]) 1389 1390dnl Test whether the snprintf function supports the %n format directive 1391dnl also in truncated portions of the format string. (ISO C99, POSIX:2001) 1392dnl Result is gl_cv_func_snprintf_directive_n. 1393 1394AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N], 1395[ 1396 AC_REQUIRE([AC_PROG_CC]) 1397 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1398 AC_REQUIRE([gl_SNPRINTF_PRESENCE]) 1399 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive], 1400 [gl_cv_func_snprintf_directive_n], 1401 [ 1402 AC_RUN_IFELSE( 1403 [AC_LANG_SOURCE([[ 1404#include <stdio.h> 1405#include <string.h> 1406#if HAVE_SNPRINTF 1407# define my_snprintf snprintf 1408#else 1409# include <stdarg.h> 1410static int my_snprintf (char *buf, int size, const char *format, ...) 1411{ 1412 va_list args; 1413 int ret; 1414 va_start (args, format); 1415 ret = vsnprintf (buf, size, format, args); 1416 va_end (args); 1417 return ret; 1418} 1419#endif 1420static char fmtstring[10]; 1421static char buf[100]; 1422int main () 1423{ 1424 int count = -1; 1425 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) 1426 support %n in format strings in read-only memory but not in writable 1427 memory. */ 1428 strcpy (fmtstring, "%d %n"); 1429 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55); 1430 if (count != 6) 1431 return 1; 1432 return 0; 1433}]])], 1434 [gl_cv_func_snprintf_directive_n=yes], 1435 [gl_cv_func_snprintf_directive_n=no], 1436 [ 1437 case "$host_os" in 1438 # Guess no on glibc when _FORTIFY_SOURCE >= 2. 1439 *-gnu* | gnu*) AC_COMPILE_IFELSE( 1440 [AC_LANG_SOURCE( 1441 [[#if _FORTIFY_SOURCE >= 2 1442 error fail 1443 #endif 1444 ]])], 1445 [gl_cv_func_snprintf_directive_n="guessing yes"], 1446 [gl_cv_func_snprintf_directive_n="guessing no"]) 1447 ;; 1448changequote(,)dnl 1449 # Guess yes on musl systems. 1450 *-musl*) gl_cv_func_snprintf_directive_n="guessing yes";; 1451 # Guess yes on FreeBSD >= 5. 1452 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";; 1453 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";; 1454 # Guess yes on Mac OS X >= 10.3. 1455 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";; 1456 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";; 1457 # Guess yes on Solaris >= 2.6. 1458 solaris2.[0-5] | solaris2.[0-5].*) 1459 gl_cv_func_snprintf_directive_n="guessing no";; 1460 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";; 1461 # Guess yes on AIX >= 4. 1462 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";; 1463 aix*) gl_cv_func_snprintf_directive_n="guessing yes";; 1464 # Guess yes on IRIX >= 6.5. 1465 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";; 1466 # Guess yes on OSF/1 >= 5. 1467 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";; 1468 osf*) gl_cv_func_snprintf_directive_n="guessing yes";; 1469 # Guess yes on NetBSD >= 3. 1470 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 1471 gl_cv_func_snprintf_directive_n="guessing no";; 1472 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";; 1473 # Guess yes on BeOS. 1474 beos*) gl_cv_func_snprintf_directive_n="guessing yes";; 1475 # Guess no on Android. 1476 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";; 1477 # Guess no on native Windows. 1478 mingw*) gl_cv_func_snprintf_directive_n="guessing no";; 1479 # If we don't know, obey --enable-cross-guesses. 1480 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";; 1481changequote([,])dnl 1482 esac 1483 ]) 1484 ]) 1485]) 1486 1487dnl Test whether the snprintf function, when passed a size = 1, writes any 1488dnl output without bounds in this case, behaving like sprintf. This is the 1489dnl case on Linux libc5. 1490dnl Result is gl_cv_func_snprintf_size1. 1491 1492AC_DEFUN([gl_SNPRINTF_SIZE1], 1493[ 1494 AC_REQUIRE([AC_PROG_CC]) 1495 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1496 AC_REQUIRE([gl_SNPRINTF_PRESENCE]) 1497 AC_CACHE_CHECK([whether snprintf respects a size of 1], 1498 [gl_cv_func_snprintf_size1], 1499 [ 1500 AC_RUN_IFELSE( 1501 [AC_LANG_SOURCE([[ 1502#include <stdio.h> 1503#if HAVE_SNPRINTF 1504# define my_snprintf snprintf 1505#else 1506# include <stdarg.h> 1507static int my_snprintf (char *buf, int size, const char *format, ...) 1508{ 1509 va_list args; 1510 int ret; 1511 va_start (args, format); 1512 ret = vsnprintf (buf, size, format, args); 1513 va_end (args); 1514 return ret; 1515} 1516#endif 1517int main() 1518{ 1519 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; 1520 my_snprintf (buf, 1, "%d", 12345); 1521 return buf[1] != 'E'; 1522}]])], 1523 [gl_cv_func_snprintf_size1=yes], 1524 [gl_cv_func_snprintf_size1=no], 1525 [case "$host_os" in 1526 # Guess yes on Android. 1527 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;; 1528 # Guess yes on native Windows. 1529 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;; 1530 *) gl_cv_func_snprintf_size1="guessing yes" ;; 1531 esac 1532 ]) 1533 ]) 1534]) 1535 1536dnl Test whether the vsnprintf function, when passed a zero size, produces no 1537dnl output. (ISO C99, POSIX:2001) 1538dnl For example, snprintf nevertheless writes a NUL byte in this case 1539dnl on OSF/1 5.1: 1540dnl --------------------------------------------------------------------- 1541dnl #include <stdio.h> 1542dnl int main() 1543dnl { 1544dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; 1545dnl snprintf (buf, 0, "%d", 12345); 1546dnl return buf[0] != 'D'; 1547dnl } 1548dnl --------------------------------------------------------------------- 1549dnl And vsnprintf writes any output without bounds in this case, behaving like 1550dnl vsprintf, on HP-UX 11 and OSF/1 5.1: 1551dnl --------------------------------------------------------------------- 1552dnl #include <stdarg.h> 1553dnl #include <stdio.h> 1554dnl static int my_snprintf (char *buf, int size, const char *format, ...) 1555dnl { 1556dnl va_list args; 1557dnl int ret; 1558dnl va_start (args, format); 1559dnl ret = vsnprintf (buf, size, format, args); 1560dnl va_end (args); 1561dnl return ret; 1562dnl } 1563dnl int main() 1564dnl { 1565dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; 1566dnl my_snprintf (buf, 0, "%d", 12345); 1567dnl return buf[0] != 'D'; 1568dnl } 1569dnl --------------------------------------------------------------------- 1570dnl Result is gl_cv_func_vsnprintf_zerosize_c99. 1571 1572AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99], 1573[ 1574 AC_REQUIRE([AC_PROG_CC]) 1575 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1576 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99], 1577 [gl_cv_func_vsnprintf_zerosize_c99], 1578 [ 1579 AC_RUN_IFELSE( 1580 [AC_LANG_SOURCE([[ 1581#include <stdarg.h> 1582#include <stdio.h> 1583static int my_snprintf (char *buf, int size, const char *format, ...) 1584{ 1585 va_list args; 1586 int ret; 1587 va_start (args, format); 1588 ret = vsnprintf (buf, size, format, args); 1589 va_end (args); 1590 return ret; 1591} 1592int main() 1593{ 1594 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; 1595 my_snprintf (buf, 0, "%d", 12345); 1596 return buf[0] != 'D'; 1597}]])], 1598 [gl_cv_func_vsnprintf_zerosize_c99=yes], 1599 [gl_cv_func_vsnprintf_zerosize_c99=no], 1600 [ 1601changequote(,)dnl 1602 case "$host_os" in 1603 # Guess yes on glibc systems. 1604 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1605 # Guess yes on musl systems. 1606 *-musl*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1607 # Guess yes on FreeBSD >= 5. 1608 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1609 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1610 # Guess yes on Mac OS X >= 10.3. 1611 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1612 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1613 # Guess yes on Cygwin. 1614 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1615 # Guess yes on Solaris >= 2.6. 1616 solaris2.[0-5] | solaris2.[0-5].*) 1617 gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1618 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1619 # Guess yes on AIX >= 4. 1620 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1621 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1622 # Guess yes on IRIX >= 6.5. 1623 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1624 # Guess yes on NetBSD >= 3. 1625 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 1626 gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1627 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1628 # Guess yes on BeOS. 1629 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1630 # Guess yes on Android. 1631 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1632 # Guess yes on native Windows. 1633 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1634 # If we don't know, obey --enable-cross-guesses. 1635 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";; 1636 esac 1637changequote([,])dnl 1638 ]) 1639 ]) 1640]) 1641 1642dnl The results of these tests on various platforms are: 1643dnl 1644dnl 1 = gl_PRINTF_SIZES_C99 1645dnl 2 = gl_PRINTF_LONG_DOUBLE 1646dnl 3 = gl_PRINTF_INFINITE 1647dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE 1648dnl 5 = gl_PRINTF_DIRECTIVE_A 1649dnl 6 = gl_PRINTF_DIRECTIVE_F 1650dnl 7 = gl_PRINTF_DIRECTIVE_N 1651dnl 8 = gl_PRINTF_DIRECTIVE_LS 1652dnl 9 = gl_PRINTF_POSITIONS 1653dnl 10 = gl_PRINTF_FLAG_GROUPING 1654dnl 11 = gl_PRINTF_FLAG_LEFTADJUST 1655dnl 12 = gl_PRINTF_FLAG_ZERO 1656dnl 13 = gl_PRINTF_PRECISION 1657dnl 14 = gl_PRINTF_ENOMEM 1658dnl 15 = gl_SNPRINTF_PRESENCE 1659dnl 16 = gl_SNPRINTF_TRUNCATION_C99 1660dnl 17 = gl_SNPRINTF_RETVAL_C99 1661dnl 18 = gl_SNPRINTF_DIRECTIVE_N 1662dnl 19 = gl_SNPRINTF_SIZE1 1663dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99 1664dnl 1665dnl 1 = checking whether printf supports size specifiers as in C99... 1666dnl 2 = checking whether printf supports 'long double' arguments... 1667dnl 3 = checking whether printf supports infinite 'double' arguments... 1668dnl 4 = checking whether printf supports infinite 'long double' arguments... 1669dnl 5 = checking whether printf supports the 'a' and 'A' directives... 1670dnl 6 = checking whether printf supports the 'F' directive... 1671dnl 7 = checking whether printf supports the 'n' directive... 1672dnl 8 = checking whether printf supports the 'ls' directive... 1673dnl 9 = checking whether printf supports POSIX/XSI format strings with positions... 1674dnl 10 = checking whether printf supports the grouping flag... 1675dnl 11 = checking whether printf supports the left-adjust flag correctly... 1676dnl 12 = checking whether printf supports the zero flag correctly... 1677dnl 13 = checking whether printf supports large precisions... 1678dnl 14 = checking whether printf survives out-of-memory conditions... 1679dnl 15 = checking for snprintf... 1680dnl 16 = checking whether snprintf truncates the result as in C99... 1681dnl 17 = checking whether snprintf returns a byte count as in C99... 1682dnl 18 = checking whether snprintf fully supports the 'n' directive... 1683dnl 19 = checking whether snprintf respects a size of 1... 1684dnl 20 = checking whether vsnprintf respects a zero size as in C99... 1685dnl 1686dnl . = yes, # = no. 1687dnl 1688dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1689dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . . 1690dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . . 1691dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . . 1692dnl Mac OS X 10.13.5 . . . # # . # . . . . . . . . . . # . . 1693dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . . 1694dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . . 1695dnl OpenBSD 6.0, 6.7 . . . . # . . . . . . . . # . . . . . . 1696dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . . 1697dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . 1698dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . 1699dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . 1700dnl Solaris 11.4 . . # # # . . # . . . # . . . . . . . . 1701dnl Solaris 11.3 . . . . # . . # . . . . . . . . . . . . 1702dnl Solaris 11.0 . . # # # . . # . . . # . . . . . . . . 1703dnl Solaris 10 . . # # # . . # . . . # # . . . . . . . 1704dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . . 1705dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # 1706dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . . 1707dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . . 1708dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . . 1709dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . . 1710dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . # 1711dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? # 1712dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . . 1713dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . # 1714dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # # 1715dnl NetBSD 9.0 . . . . # . . . . . . . . . . . . . . . 1716dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . . 1717dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ? 1718dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . . 1719dnl Haiku . . . # # # . # . . . . . ? . . ? . . . 1720dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . . 1721dnl Android 4.3 . . # # # # # # . # . # . # . . . # . . 1722dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . . 1723dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . . 1724dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . . 1725dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . . 1726