diff options
| author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-15 04:22:57 -0500 |
|---|---|---|
| committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-15 05:19:08 -0500 |
| commit | 71cdb52799220f8d9052643baf1d3e9836a9c755 (patch) | |
| tree | 27aee97a35d9ab51f0d8f64a46690bd41a5f8c1b /gl/m4/printf.m4 | |
| parent | f7afa46586645e50498d8b2d0c67884f014dc3a4 (diff) | |
| download | monitoring-plugins-71cdb52799220f8d9052643baf1d3e9836a9c755.tar.gz | |
Sync with gnulib
Diffstat (limited to 'gl/m4/printf.m4')
| -rw-r--r-- | gl/m4/printf.m4 | 1322 |
1 files changed, 1322 insertions, 0 deletions
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4 new file mode 100644 index 00000000..4d109935 --- /dev/null +++ b/gl/m4/printf.m4 | |||
| @@ -0,0 +1,1322 @@ | |||
| 1 | # printf.m4 serial 26 | ||
| 2 | dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | dnl Test whether the *printf family of functions supports the 'j', 'z', 't', | ||
| 8 | dnl 'L' size specifiers. (ISO C99, POSIX:2001) | ||
| 9 | dnl Result is gl_cv_func_printf_sizes_c99. | ||
| 10 | |||
| 11 | AC_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_TRY_RUN([ | ||
| 21 | #include <stddef.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <sys/types.h> | ||
| 25 | #if HAVE_STDINT_H_WITH_UINTMAX | ||
| 26 | # include <stdint.h> | ||
| 27 | #endif | ||
| 28 | #if HAVE_INTTYPES_H_WITH_UINTMAX | ||
| 29 | # include <inttypes.h> | ||
| 30 | #endif | ||
| 31 | static char buf[100]; | ||
| 32 | int main () | ||
| 33 | { | ||
| 34 | #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX | ||
| 35 | buf[0] = '\0'; | ||
| 36 | if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0 | ||
| 37 | || strcmp (buf, "12345671 33") != 0) | ||
| 38 | return 1; | ||
| 39 | #endif | ||
| 40 | buf[0] = '\0'; | ||
| 41 | if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0 | ||
| 42 | || strcmp (buf, "12345672 33") != 0) | ||
| 43 | return 1; | ||
| 44 | buf[0] = '\0'; | ||
| 45 | if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0 | ||
| 46 | || strcmp (buf, "12345673 33") != 0) | ||
| 47 | return 1; | ||
| 48 | buf[0] = '\0'; | ||
| 49 | if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0 | ||
| 50 | || strcmp (buf, "1.5 33") != 0) | ||
| 51 | return 1; | ||
| 52 | return 0; | ||
| 53 | }], [gl_cv_func_printf_sizes_c99=yes], [gl_cv_func_printf_sizes_c99=no], | ||
| 54 | [ | ||
| 55 | changequote(,)dnl | ||
| 56 | case "$host_os" in | ||
| 57 | # Guess yes on glibc systems. | ||
| 58 | *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 59 | # Guess yes on FreeBSD >= 5. | ||
| 60 | freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 61 | freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 62 | # Guess yes on MacOS X >= 10.3. | ||
| 63 | darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 64 | darwin*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 65 | # Guess yes on OpenBSD >= 3.9. | ||
| 66 | openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) | ||
| 67 | gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 68 | openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 69 | # Guess yes on Solaris >= 2.10. | ||
| 70 | solaris2.[0-9]*) gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 71 | solaris*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 72 | # Guess yes on NetBSD >= 3. | ||
| 73 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 74 | gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 75 | netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; | ||
| 76 | # If we don't know, assume the worst. | ||
| 77 | *) gl_cv_func_printf_sizes_c99="guessing no";; | ||
| 78 | esac | ||
| 79 | changequote([,])dnl | ||
| 80 | ]) | ||
| 81 | ]) | ||
| 82 | ]) | ||
| 83 | |||
| 84 | dnl Test whether the *printf family of functions supports 'long double' | ||
| 85 | dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001) | ||
| 86 | dnl Result is gl_cv_func_printf_long_double. | ||
| 87 | |||
| 88 | AC_DEFUN([gl_PRINTF_LONG_DOUBLE], | ||
| 89 | [ | ||
| 90 | AC_REQUIRE([AC_PROG_CC]) | ||
| 91 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 92 | AC_CACHE_CHECK([whether printf supports 'long double' arguments], | ||
| 93 | [gl_cv_func_printf_long_double], | ||
| 94 | [ | ||
| 95 | AC_TRY_RUN([ | ||
| 96 | #include <stdio.h> | ||
| 97 | #include <string.h> | ||
| 98 | static char buf[10000]; | ||
| 99 | int main () | ||
| 100 | { | ||
| 101 | buf[0] = '\0'; | ||
| 102 | if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0 | ||
| 103 | || strcmp (buf, "1.750000 33") != 0) | ||
| 104 | return 1; | ||
| 105 | buf[0] = '\0'; | ||
| 106 | if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0 | ||
| 107 | || strcmp (buf, "1.750000e+00 33") != 0) | ||
| 108 | return 1; | ||
| 109 | buf[0] = '\0'; | ||
| 110 | if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0 | ||
| 111 | || strcmp (buf, "1.75 33") != 0) | ||
| 112 | return 1; | ||
| 113 | return 0; | ||
| 114 | }], [gl_cv_func_printf_long_double=yes], [gl_cv_func_printf_long_double=no], | ||
| 115 | [ | ||
| 116 | changequote(,)dnl | ||
| 117 | case "$host_os" in | ||
| 118 | beos*) gl_cv_func_printf_long_double="guessing no";; | ||
| 119 | mingw* | pw*) gl_cv_func_printf_long_double="guessing no";; | ||
| 120 | *) gl_cv_func_printf_long_double="guessing yes";; | ||
| 121 | esac | ||
| 122 | changequote([,])dnl | ||
| 123 | ]) | ||
| 124 | ]) | ||
| 125 | ]) | ||
| 126 | |||
| 127 | dnl Test whether the *printf family of functions supports infinite and NaN | ||
| 128 | dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) | ||
| 129 | dnl Result is gl_cv_func_printf_infinite. | ||
| 130 | |||
| 131 | AC_DEFUN([gl_PRINTF_INFINITE], | ||
| 132 | [ | ||
| 133 | AC_REQUIRE([AC_PROG_CC]) | ||
| 134 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 135 | AC_CACHE_CHECK([whether printf supports infinite 'double' arguments], | ||
| 136 | [gl_cv_func_printf_infinite], | ||
| 137 | [ | ||
| 138 | AC_TRY_RUN([ | ||
| 139 | #include <stdio.h> | ||
| 140 | #include <string.h> | ||
| 141 | static int | ||
| 142 | strisnan (const char *string, size_t start_index, size_t end_index) | ||
| 143 | { | ||
| 144 | if (start_index < end_index) | ||
| 145 | { | ||
| 146 | if (string[start_index] == '-') | ||
| 147 | start_index++; | ||
| 148 | if (start_index + 3 <= end_index | ||
| 149 | && memcmp (string + start_index, "nan", 3) == 0) | ||
| 150 | { | ||
| 151 | start_index += 3; | ||
| 152 | if (start_index == end_index | ||
| 153 | || (string[start_index] == '(' && string[end_index - 1] == ')')) | ||
| 154 | return 1; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | return 0; | ||
| 158 | } | ||
| 159 | static char buf[10000]; | ||
| 160 | static double zero = 0.0; | ||
| 161 | int main () | ||
| 162 | { | ||
| 163 | if (sprintf (buf, "%f", 1.0 / 0.0) < 0 | ||
| 164 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 165 | return 1; | ||
| 166 | if (sprintf (buf, "%f", -1.0 / 0.0) < 0 | ||
| 167 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 168 | return 1; | ||
| 169 | if (sprintf (buf, "%f", zero / zero) < 0 | ||
| 170 | || !strisnan (buf, 0, strlen (buf))) | ||
| 171 | return 1; | ||
| 172 | if (sprintf (buf, "%e", 1.0 / 0.0) < 0 | ||
| 173 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 174 | return 1; | ||
| 175 | if (sprintf (buf, "%e", -1.0 / 0.0) < 0 | ||
| 176 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 177 | return 1; | ||
| 178 | if (sprintf (buf, "%e", zero / zero) < 0 | ||
| 179 | || !strisnan (buf, 0, strlen (buf))) | ||
| 180 | return 1; | ||
| 181 | if (sprintf (buf, "%g", 1.0 / 0.0) < 0 | ||
| 182 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 183 | return 1; | ||
| 184 | if (sprintf (buf, "%g", -1.0 / 0.0) < 0 | ||
| 185 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 186 | return 1; | ||
| 187 | if (sprintf (buf, "%g", zero / zero) < 0 | ||
| 188 | || !strisnan (buf, 0, strlen (buf))) | ||
| 189 | return 1; | ||
| 190 | return 0; | ||
| 191 | }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no], | ||
| 192 | [ | ||
| 193 | changequote(,)dnl | ||
| 194 | case "$host_os" in | ||
| 195 | # Guess yes on glibc systems. | ||
| 196 | *-gnu*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 197 | # Guess yes on FreeBSD >= 6. | ||
| 198 | freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";; | ||
| 199 | freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 200 | # Guess yes on MacOS X >= 10.3. | ||
| 201 | darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";; | ||
| 202 | darwin*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 203 | # Guess yes on HP-UX >= 11. | ||
| 204 | hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";; | ||
| 205 | hpux*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 206 | # Guess yes on NetBSD >= 3. | ||
| 207 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 208 | gl_cv_func_printf_infinite="guessing no";; | ||
| 209 | netbsd*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 210 | # Guess yes on BeOS. | ||
| 211 | beos*) gl_cv_func_printf_infinite="guessing yes";; | ||
| 212 | # If we don't know, assume the worst. | ||
| 213 | *) gl_cv_func_printf_infinite="guessing no";; | ||
| 214 | esac | ||
| 215 | changequote([,])dnl | ||
| 216 | ]) | ||
| 217 | ]) | ||
| 218 | ]) | ||
| 219 | |||
| 220 | dnl Test whether the *printf family of functions supports infinite and NaN | ||
| 221 | dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) | ||
| 222 | dnl Result is gl_cv_func_printf_infinite_long_double. | ||
| 223 | |||
| 224 | AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE], | ||
| 225 | [ | ||
| 226 | AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) | ||
| 227 | AC_REQUIRE([AC_PROG_CC]) | ||
| 228 | AC_REQUIRE([AC_C_BIGENDIAN]) | ||
| 229 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 230 | dnl The user can set or unset the variable gl_printf_safe to indicate | ||
| 231 | dnl that he wishes a safe handling of non-IEEE-754 'long double' values. | ||
| 232 | if test -n "$gl_printf_safe"; then | ||
| 233 | AC_DEFINE([CHECK_PRINTF_SAFE], [1], | ||
| 234 | [Define if you wish *printf() functions that have a safe handling of | ||
| 235 | non-IEEE-754 'long double' values.]) | ||
| 236 | fi | ||
| 237 | case "$gl_cv_func_printf_long_double" in | ||
| 238 | *yes) | ||
| 239 | AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments], | ||
| 240 | [gl_cv_func_printf_infinite_long_double], | ||
| 241 | [ | ||
| 242 | AC_TRY_RUN([ | ||
| 243 | ]GL_NOCRASH[ | ||
| 244 | #include <float.h> | ||
| 245 | #include <stdio.h> | ||
| 246 | #include <string.h> | ||
| 247 | static int | ||
| 248 | strisnan (const char *string, size_t start_index, size_t end_index) | ||
| 249 | { | ||
| 250 | if (start_index < end_index) | ||
| 251 | { | ||
| 252 | if (string[start_index] == '-') | ||
| 253 | start_index++; | ||
| 254 | if (start_index + 3 <= end_index | ||
| 255 | && memcmp (string + start_index, "nan", 3) == 0) | ||
| 256 | { | ||
| 257 | start_index += 3; | ||
| 258 | if (start_index == end_index | ||
| 259 | || (string[start_index] == '(' && string[end_index - 1] == ')')) | ||
| 260 | return 1; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | static char buf[10000]; | ||
| 266 | static long double zeroL = 0.0L; | ||
| 267 | int main () | ||
| 268 | { | ||
| 269 | nocrash_init(); | ||
| 270 | if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0 | ||
| 271 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 272 | return 1; | ||
| 273 | if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0 | ||
| 274 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 275 | return 1; | ||
| 276 | if (sprintf (buf, "%Lf", zeroL / zeroL) < 0 | ||
| 277 | || !strisnan (buf, 0, strlen (buf))) | ||
| 278 | return 1; | ||
| 279 | if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0 | ||
| 280 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 281 | return 1; | ||
| 282 | if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0 | ||
| 283 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 284 | return 1; | ||
| 285 | if (sprintf (buf, "%Le", zeroL / zeroL) < 0 | ||
| 286 | || !strisnan (buf, 0, strlen (buf))) | ||
| 287 | return 1; | ||
| 288 | if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0 | ||
| 289 | || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) | ||
| 290 | return 1; | ||
| 291 | if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0 | ||
| 292 | || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) | ||
| 293 | return 1; | ||
| 294 | if (sprintf (buf, "%Lg", zeroL / zeroL) < 0 | ||
| 295 | || !strisnan (buf, 0, strlen (buf))) | ||
| 296 | return 1; | ||
| 297 | #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_)) | ||
| 298 | /* Representation of an 80-bit 'long double' as an initializer for a sequence | ||
| 299 | of 'unsigned int' words. */ | ||
| 300 | # ifdef WORDS_BIGENDIAN | ||
| 301 | # define LDBL80_WORDS(exponent,manthi,mantlo) \ | ||
| 302 | { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ | ||
| 303 | ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \ | ||
| 304 | (unsigned int) (mantlo) << 16 \ | ||
| 305 | } | ||
| 306 | # else | ||
| 307 | # define LDBL80_WORDS(exponent,manthi,mantlo) \ | ||
| 308 | { mantlo, manthi, exponent } | ||
| 309 | # endif | ||
| 310 | { /* Quiet NaN. */ | ||
| 311 | static union { unsigned int word[4]; long double value; } x = | ||
| 312 | { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; | ||
| 313 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 314 | || !strisnan (buf, 0, strlen (buf))) | ||
| 315 | return 1; | ||
| 316 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 317 | || !strisnan (buf, 0, strlen (buf))) | ||
| 318 | return 1; | ||
| 319 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 320 | || !strisnan (buf, 0, strlen (buf))) | ||
| 321 | return 1; | ||
| 322 | } | ||
| 323 | { | ||
| 324 | /* Signalling NaN. */ | ||
| 325 | static union { unsigned int word[4]; long double value; } x = | ||
| 326 | { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; | ||
| 327 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 328 | || !strisnan (buf, 0, strlen (buf))) | ||
| 329 | return 1; | ||
| 330 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 331 | || !strisnan (buf, 0, strlen (buf))) | ||
| 332 | return 1; | ||
| 333 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 334 | || !strisnan (buf, 0, strlen (buf))) | ||
| 335 | return 1; | ||
| 336 | } | ||
| 337 | { /* Pseudo-NaN. */ | ||
| 338 | static union { unsigned int word[4]; long double value; } x = | ||
| 339 | { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; | ||
| 340 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 341 | || !strisnan (buf, 0, strlen (buf))) | ||
| 342 | return 1; | ||
| 343 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 344 | || !strisnan (buf, 0, strlen (buf))) | ||
| 345 | return 1; | ||
| 346 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 347 | || !strisnan (buf, 0, strlen (buf))) | ||
| 348 | return 1; | ||
| 349 | } | ||
| 350 | { /* Pseudo-Infinity. */ | ||
| 351 | static union { unsigned int word[4]; long double value; } x = | ||
| 352 | { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; | ||
| 353 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 354 | || !strisnan (buf, 0, strlen (buf))) | ||
| 355 | return 1; | ||
| 356 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 357 | || !strisnan (buf, 0, strlen (buf))) | ||
| 358 | return 1; | ||
| 359 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 360 | || !strisnan (buf, 0, strlen (buf))) | ||
| 361 | return 1; | ||
| 362 | } | ||
| 363 | { /* Pseudo-Zero. */ | ||
| 364 | static union { unsigned int word[4]; long double value; } x = | ||
| 365 | { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; | ||
| 366 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 367 | || !strisnan (buf, 0, strlen (buf))) | ||
| 368 | return 1; | ||
| 369 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 370 | || !strisnan (buf, 0, strlen (buf))) | ||
| 371 | return 1; | ||
| 372 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 373 | || !strisnan (buf, 0, strlen (buf))) | ||
| 374 | return 1; | ||
| 375 | } | ||
| 376 | { /* Unnormalized number. */ | ||
| 377 | static union { unsigned int word[4]; long double value; } x = | ||
| 378 | { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; | ||
| 379 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 380 | || !strisnan (buf, 0, strlen (buf))) | ||
| 381 | return 1; | ||
| 382 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 383 | || !strisnan (buf, 0, strlen (buf))) | ||
| 384 | return 1; | ||
| 385 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 386 | || !strisnan (buf, 0, strlen (buf))) | ||
| 387 | return 1; | ||
| 388 | } | ||
| 389 | { /* Pseudo-Denormal. */ | ||
| 390 | static union { unsigned int word[4]; long double value; } x = | ||
| 391 | { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; | ||
| 392 | if (sprintf (buf, "%Lf", x.value) < 0 | ||
| 393 | || !strisnan (buf, 0, strlen (buf))) | ||
| 394 | return 1; | ||
| 395 | if (sprintf (buf, "%Le", x.value) < 0 | ||
| 396 | || !strisnan (buf, 0, strlen (buf))) | ||
| 397 | return 1; | ||
| 398 | if (sprintf (buf, "%Lg", x.value) < 0 | ||
| 399 | || !strisnan (buf, 0, strlen (buf))) | ||
| 400 | return 1; | ||
| 401 | } | ||
| 402 | #endif | ||
| 403 | return 0; | ||
| 404 | }], | ||
| 405 | [gl_cv_func_printf_infinite_long_double=yes], | ||
| 406 | [gl_cv_func_printf_infinite_long_double=no], | ||
| 407 | [ | ||
| 408 | changequote(,)dnl | ||
| 409 | case "$host_cpu" in | ||
| 410 | # Guess no on ia64, x86_64, i386. | ||
| 411 | ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 412 | *) | ||
| 413 | case "$host_os" in | ||
| 414 | # Guess yes on glibc systems. | ||
| 415 | *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";; | ||
| 416 | # Guess yes on FreeBSD >= 6. | ||
| 417 | freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 418 | freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; | ||
| 419 | # Guess yes on MacOS X >= 10.3. | ||
| 420 | darwin[1-6].*) gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 421 | darwin*) gl_cv_func_printf_infinite_long_double="guessing yes";; | ||
| 422 | # Guess yes on HP-UX >= 11. | ||
| 423 | hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 424 | hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; | ||
| 425 | # Guess yes on NetBSD >= 3. | ||
| 426 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 427 | gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 428 | netbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; | ||
| 429 | # If we don't know, assume the worst. | ||
| 430 | *) gl_cv_func_printf_infinite_long_double="guessing no";; | ||
| 431 | esac | ||
| 432 | ;; | ||
| 433 | esac | ||
| 434 | changequote([,])dnl | ||
| 435 | ]) | ||
| 436 | ]) | ||
| 437 | ;; | ||
| 438 | *) | ||
| 439 | gl_cv_func_printf_infinite_long_double="irrelevant" | ||
| 440 | ;; | ||
| 441 | esac | ||
| 442 | ]) | ||
| 443 | |||
| 444 | dnl Test whether the *printf family of functions supports the 'a' and 'A' | ||
| 445 | dnl conversion specifier for hexadecimal output of floating-point numbers. | ||
| 446 | dnl (ISO C99, POSIX:2001) | ||
| 447 | dnl Result is gl_cv_func_printf_directive_a. | ||
| 448 | |||
| 449 | AC_DEFUN([gl_PRINTF_DIRECTIVE_A], | ||
| 450 | [ | ||
| 451 | AC_REQUIRE([AC_PROG_CC]) | ||
| 452 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 453 | AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives], | ||
| 454 | [gl_cv_func_printf_directive_a], | ||
| 455 | [ | ||
| 456 | AC_TRY_RUN([ | ||
| 457 | #include <stdio.h> | ||
| 458 | #include <string.h> | ||
| 459 | static char buf[100]; | ||
| 460 | int main () | ||
| 461 | { | ||
| 462 | if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0 | ||
| 463 | || (strcmp (buf, "0x1.922p+1 33") != 0 | ||
| 464 | && strcmp (buf, "0x3.244p+0 33") != 0 | ||
| 465 | && strcmp (buf, "0x6.488p-1 33") != 0 | ||
| 466 | && strcmp (buf, "0xc.91p-2 33") != 0)) | ||
| 467 | return 1; | ||
| 468 | if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0 | ||
| 469 | || (strcmp (buf, "-0X1.922P+1 33") != 0 | ||
| 470 | && strcmp (buf, "-0X3.244P+0 33") != 0 | ||
| 471 | && strcmp (buf, "-0X6.488P-1 33") != 0 | ||
| 472 | && strcmp (buf, "-0XC.91P-2 33") != 0)) | ||
| 473 | return 1; | ||
| 474 | /* This catches a FreeBSD 6.1 bug: it doesn't round. */ | ||
| 475 | if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0 | ||
| 476 | || (strcmp (buf, "0x1.83p+0 33") != 0 | ||
| 477 | && strcmp (buf, "0x3.05p-1 33") != 0 | ||
| 478 | && strcmp (buf, "0x6.0ap-2 33") != 0 | ||
| 479 | && strcmp (buf, "0xc.14p-3 33") != 0)) | ||
| 480 | return 1; | ||
| 481 | /* This catches a FreeBSD 6.1 bug. See | ||
| 482 | <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ | ||
| 483 | if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0 | ||
| 484 | || buf[0] == '0') | ||
| 485 | return 1; | ||
| 486 | /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */ | ||
| 487 | if (sprintf (buf, "%.1a", 1.999) < 0 | ||
| 488 | || (strcmp (buf, "0x1.0p+1") != 0 | ||
| 489 | && strcmp (buf, "0x2.0p+0") != 0 | ||
| 490 | && strcmp (buf, "0x4.0p-1") != 0 | ||
| 491 | && strcmp (buf, "0x8.0p-2") != 0)) | ||
| 492 | return 1; | ||
| 493 | /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a | ||
| 494 | glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */ | ||
| 495 | if (sprintf (buf, "%.1La", 1.999L) < 0 | ||
| 496 | || (strcmp (buf, "0x1.0p+1") != 0 | ||
| 497 | && strcmp (buf, "0x2.0p+0") != 0 | ||
| 498 | && strcmp (buf, "0x4.0p-1") != 0 | ||
| 499 | && strcmp (buf, "0x8.0p-2") != 0)) | ||
| 500 | return 1; | ||
| 501 | return 0; | ||
| 502 | }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no], | ||
| 503 | [ | ||
| 504 | case "$host_os" in | ||
| 505 | # Guess yes on glibc >= 2.5 systems. | ||
| 506 | *-gnu*) | ||
| 507 | AC_EGREP_CPP([BZ2908], [ | ||
| 508 | #include <features.h> | ||
| 509 | #ifdef __GNU_LIBRARY__ | ||
| 510 | #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2) | ||
| 511 | BZ2908 | ||
| 512 | #endif | ||
| 513 | #endif | ||
| 514 | ], | ||
| 515 | [gl_cv_func_printf_directive_a="guessing yes"], | ||
| 516 | [gl_cv_func_printf_directive_a="guessing no"]) | ||
| 517 | ;; | ||
| 518 | # If we don't know, assume the worst. | ||
| 519 | *) gl_cv_func_printf_directive_a="guessing no";; | ||
| 520 | esac | ||
| 521 | ]) | ||
| 522 | ]) | ||
| 523 | ]) | ||
| 524 | |||
| 525 | dnl Test whether the *printf family of functions supports the %F format | ||
| 526 | dnl directive. (ISO C99, POSIX:2001) | ||
| 527 | dnl Result is gl_cv_func_printf_directive_f. | ||
| 528 | |||
| 529 | AC_DEFUN([gl_PRINTF_DIRECTIVE_F], | ||
| 530 | [ | ||
| 531 | AC_REQUIRE([AC_PROG_CC]) | ||
| 532 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 533 | AC_CACHE_CHECK([whether printf supports the 'F' directive], | ||
| 534 | [gl_cv_func_printf_directive_f], | ||
| 535 | [ | ||
| 536 | AC_TRY_RUN([ | ||
| 537 | #include <stdio.h> | ||
| 538 | #include <string.h> | ||
| 539 | static char buf[100]; | ||
| 540 | int main () | ||
| 541 | { | ||
| 542 | if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0 | ||
| 543 | || strcmp (buf, "1234567.000000 33") != 0) | ||
| 544 | return 1; | ||
| 545 | if (sprintf (buf, "%F", 1.0 / 0.0) < 0 | ||
| 546 | || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0)) | ||
| 547 | return 1; | ||
| 548 | /* This catches a Cygwin 2007 bug. */ | ||
| 549 | if (sprintf (buf, "%.F", 1234.0) < 0 | ||
| 550 | || strcmp (buf, "1234") != 0) | ||
| 551 | return 1; | ||
| 552 | return 0; | ||
| 553 | }], [gl_cv_func_printf_directive_f=yes], [gl_cv_func_printf_directive_f=no], | ||
| 554 | [ | ||
| 555 | changequote(,)dnl | ||
| 556 | case "$host_os" in | ||
| 557 | # Guess yes on glibc systems. | ||
| 558 | *-gnu*) gl_cv_func_printf_directive_f="guessing yes";; | ||
| 559 | # Guess yes on FreeBSD >= 6. | ||
| 560 | freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";; | ||
| 561 | freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";; | ||
| 562 | # Guess yes on MacOS X >= 10.3. | ||
| 563 | darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";; | ||
| 564 | darwin*) gl_cv_func_printf_directive_f="guessing yes";; | ||
| 565 | # Guess yes on Solaris >= 2.10. | ||
| 566 | solaris2.[0-9]*) gl_cv_func_printf_directive_f="guessing no";; | ||
| 567 | solaris*) gl_cv_func_printf_directive_f="guessing yes";; | ||
| 568 | # If we don't know, assume the worst. | ||
| 569 | *) gl_cv_func_printf_directive_f="guessing no";; | ||
| 570 | esac | ||
| 571 | changequote([,])dnl | ||
| 572 | ]) | ||
| 573 | ]) | ||
| 574 | ]) | ||
| 575 | |||
| 576 | dnl Test whether the *printf family of functions supports the %n format | ||
| 577 | dnl directive. (ISO C99, POSIX:2001) | ||
| 578 | dnl Result is gl_cv_func_printf_directive_n. | ||
| 579 | |||
| 580 | AC_DEFUN([gl_PRINTF_DIRECTIVE_N], | ||
| 581 | [ | ||
| 582 | AC_REQUIRE([AC_PROG_CC]) | ||
| 583 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 584 | AC_CACHE_CHECK([whether printf supports the 'n' directive], | ||
| 585 | [gl_cv_func_printf_directive_n], | ||
| 586 | [ | ||
| 587 | AC_TRY_RUN([ | ||
| 588 | #include <stdio.h> | ||
| 589 | #include <string.h> | ||
| 590 | static char fmtstring[10]; | ||
| 591 | static char buf[100]; | ||
| 592 | int main () | ||
| 593 | { | ||
| 594 | int count = -1; | ||
| 595 | /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) | ||
| 596 | support %n in format strings in read-only memory but not in writable | ||
| 597 | memory. */ | ||
| 598 | strcpy (fmtstring, "%d %n"); | ||
| 599 | if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0 | ||
| 600 | || strcmp (buf, "123 ") != 0 | ||
| 601 | || count != 4) | ||
| 602 | return 1; | ||
| 603 | return 0; | ||
| 604 | }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no], | ||
| 605 | [ | ||
| 606 | changequote(,)dnl | ||
| 607 | case "$host_os" in | ||
| 608 | *) gl_cv_func_printf_directive_n="guessing yes";; | ||
| 609 | esac | ||
| 610 | changequote([,])dnl | ||
| 611 | ]) | ||
| 612 | ]) | ||
| 613 | ]) | ||
| 614 | |||
| 615 | dnl Test whether the *printf family of functions supports POSIX/XSI format | ||
| 616 | dnl strings with positions. (POSIX:2001) | ||
| 617 | dnl Result is gl_cv_func_printf_positions. | ||
| 618 | |||
| 619 | AC_DEFUN([gl_PRINTF_POSITIONS], | ||
| 620 | [ | ||
| 621 | AC_REQUIRE([AC_PROG_CC]) | ||
| 622 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 623 | AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions], | ||
| 624 | [gl_cv_func_printf_positions], | ||
| 625 | [ | ||
| 626 | AC_TRY_RUN([ | ||
| 627 | #include <stdio.h> | ||
| 628 | #include <string.h> | ||
| 629 | /* The string "%2$d %1$d", with dollar characters protected from the shell's | ||
| 630 | dollar expansion (possibly an autoconf bug). */ | ||
| 631 | static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; | ||
| 632 | static char buf[100]; | ||
| 633 | int main () | ||
| 634 | { | ||
| 635 | sprintf (buf, format, 33, 55); | ||
| 636 | return (strcmp (buf, "55 33") != 0); | ||
| 637 | }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no], | ||
| 638 | [ | ||
| 639 | changequote(,)dnl | ||
| 640 | case "$host_os" in | ||
| 641 | netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*) | ||
| 642 | gl_cv_func_printf_positions="guessing no";; | ||
| 643 | beos*) gl_cv_func_printf_positions="guessing no";; | ||
| 644 | mingw* | pw*) gl_cv_func_printf_positions="guessing no";; | ||
| 645 | *) gl_cv_func_printf_positions="guessing yes";; | ||
| 646 | esac | ||
| 647 | changequote([,])dnl | ||
| 648 | ]) | ||
| 649 | ]) | ||
| 650 | ]) | ||
| 651 | |||
| 652 | dnl Test whether the *printf family of functions supports POSIX/XSI format | ||
| 653 | dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001) | ||
| 654 | dnl Result is gl_cv_func_printf_flag_grouping. | ||
| 655 | |||
| 656 | AC_DEFUN([gl_PRINTF_FLAG_GROUPING], | ||
| 657 | [ | ||
| 658 | AC_REQUIRE([AC_PROG_CC]) | ||
| 659 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 660 | AC_CACHE_CHECK([whether printf supports the grouping flag], | ||
| 661 | [gl_cv_func_printf_flag_grouping], | ||
| 662 | [ | ||
| 663 | AC_TRY_RUN([ | ||
| 664 | #include <stdio.h> | ||
| 665 | #include <string.h> | ||
| 666 | static char buf[100]; | ||
| 667 | int main () | ||
| 668 | { | ||
| 669 | if (sprintf (buf, "%'d %d", 1234567, 99) < 0 | ||
| 670 | || buf[strlen (buf) - 1] != '9') | ||
| 671 | return 1; | ||
| 672 | return 0; | ||
| 673 | }], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no], | ||
| 674 | [ | ||
| 675 | changequote(,)dnl | ||
| 676 | case "$host_os" in | ||
| 677 | cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; | ||
| 678 | netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; | ||
| 679 | mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; | ||
| 680 | *) gl_cv_func_printf_flag_grouping="guessing yes";; | ||
| 681 | esac | ||
| 682 | changequote([,])dnl | ||
| 683 | ]) | ||
| 684 | ]) | ||
| 685 | ]) | ||
| 686 | |||
| 687 | dnl Test whether the *printf family of functions supports the - flag correctly. | ||
| 688 | dnl (ISO C99.) See | ||
| 689 | dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html> | ||
| 690 | dnl Result is gl_cv_func_printf_flag_leftadjust. | ||
| 691 | |||
| 692 | AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST], | ||
| 693 | [ | ||
| 694 | AC_REQUIRE([AC_PROG_CC]) | ||
| 695 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 696 | AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly], | ||
| 697 | [gl_cv_func_printf_flag_leftadjust], | ||
| 698 | [ | ||
| 699 | AC_TRY_RUN([ | ||
| 700 | #include <stdio.h> | ||
| 701 | #include <string.h> | ||
| 702 | static char buf[100]; | ||
| 703 | int main () | ||
| 704 | { | ||
| 705 | /* Check that a '-' flag is not annihilated by a negative width. */ | ||
| 706 | if (sprintf (buf, "a%-*sc", -3, "b") < 0 | ||
| 707 | || strcmp (buf, "ab c") != 0) | ||
| 708 | return 1; | ||
| 709 | return 0; | ||
| 710 | }], | ||
| 711 | [gl_cv_func_printf_flag_leftadjust=yes], | ||
| 712 | [gl_cv_func_printf_flag_leftadjust=no], | ||
| 713 | [ | ||
| 714 | changequote(,)dnl | ||
| 715 | case "$host_os" in | ||
| 716 | # Guess yes on HP-UX 11. | ||
| 717 | hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; | ||
| 718 | # Guess no on HP-UX 10 and older. | ||
| 719 | hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; | ||
| 720 | # Guess yes otherwise. | ||
| 721 | *) gl_cv_func_printf_flag_leftadjust="guessing yes";; | ||
| 722 | esac | ||
| 723 | changequote([,])dnl | ||
| 724 | ]) | ||
| 725 | ]) | ||
| 726 | ]) | ||
| 727 | |||
| 728 | dnl Test whether the *printf family of functions supports padding of non-finite | ||
| 729 | dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See | ||
| 730 | dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> | ||
| 731 | dnl Result is gl_cv_func_printf_flag_zero. | ||
| 732 | |||
| 733 | AC_DEFUN([gl_PRINTF_FLAG_ZERO], | ||
| 734 | [ | ||
| 735 | AC_REQUIRE([AC_PROG_CC]) | ||
| 736 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 737 | AC_CACHE_CHECK([whether printf supports the zero flag correctly], | ||
| 738 | [gl_cv_func_printf_flag_zero], | ||
| 739 | [ | ||
| 740 | AC_TRY_RUN([ | ||
| 741 | #include <stdio.h> | ||
| 742 | #include <string.h> | ||
| 743 | static char buf[100]; | ||
| 744 | int main () | ||
| 745 | { | ||
| 746 | if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0 | ||
| 747 | || (strcmp (buf, " inf") != 0 | ||
| 748 | && strcmp (buf, " infinity") != 0)) | ||
| 749 | return 1; | ||
| 750 | return 0; | ||
| 751 | }], [gl_cv_func_printf_flag_zero=yes], [gl_cv_func_printf_flag_zero=no], | ||
| 752 | [ | ||
| 753 | changequote(,)dnl | ||
| 754 | case "$host_os" in | ||
| 755 | # Guess yes on glibc systems. | ||
| 756 | *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";; | ||
| 757 | # Guess yes on BeOS. | ||
| 758 | beos*) gl_cv_func_printf_flag_zero="guessing yes";; | ||
| 759 | # If we don't know, assume the worst. | ||
| 760 | *) gl_cv_func_printf_flag_zero="guessing no";; | ||
| 761 | esac | ||
| 762 | changequote([,])dnl | ||
| 763 | ]) | ||
| 764 | ]) | ||
| 765 | ]) | ||
| 766 | |||
| 767 | dnl Test whether the *printf family of functions supports large precisions. | ||
| 768 | dnl On mingw, precisions larger than 512 are treated like 512, in integer, | ||
| 769 | dnl floating-point or pointer output. On BeOS, precisions larger than 1044 | ||
| 770 | dnl crash the program. | ||
| 771 | dnl Result is gl_cv_func_printf_precision. | ||
| 772 | |||
| 773 | AC_DEFUN([gl_PRINTF_PRECISION], | ||
| 774 | [ | ||
| 775 | AC_REQUIRE([AC_PROG_CC]) | ||
| 776 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 777 | AC_CACHE_CHECK([whether printf supports large precisions], | ||
| 778 | [gl_cv_func_printf_precision], | ||
| 779 | [ | ||
| 780 | AC_TRY_RUN([ | ||
| 781 | #include <stdio.h> | ||
| 782 | #include <string.h> | ||
| 783 | static char buf[5000]; | ||
| 784 | int main () | ||
| 785 | { | ||
| 786 | #ifdef __BEOS__ | ||
| 787 | /* On BeOS, this would crash and show a dialog box. Avoid the crash. */ | ||
| 788 | return 1; | ||
| 789 | #endif | ||
| 790 | if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3) | ||
| 791 | return 1; | ||
| 792 | return 0; | ||
| 793 | }], [gl_cv_func_printf_precision=yes], [gl_cv_func_printf_precision=no], | ||
| 794 | [ | ||
| 795 | changequote(,)dnl | ||
| 796 | case "$host_os" in | ||
| 797 | # Guess no only on native Win32 and BeOS systems. | ||
| 798 | mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; | ||
| 799 | beos*) gl_cv_func_printf_precision="guessing no" ;; | ||
| 800 | *) gl_cv_func_printf_precision="guessing yes" ;; | ||
| 801 | esac | ||
| 802 | changequote([,])dnl | ||
| 803 | ]) | ||
| 804 | ]) | ||
| 805 | ]) | ||
| 806 | |||
| 807 | dnl Test whether the *printf family of functions recovers gracefully in case | ||
| 808 | dnl of an out-of-memory condition, or whether it crashes the entire program. | ||
| 809 | dnl Result is gl_cv_func_printf_enomem. | ||
| 810 | |||
| 811 | AC_DEFUN([gl_PRINTF_ENOMEM], | ||
| 812 | [ | ||
| 813 | AC_REQUIRE([AC_PROG_CC]) | ||
| 814 | AC_REQUIRE([gl_MULTIARCH]) | ||
| 815 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 816 | AC_CACHE_CHECK([whether printf survives out-of-memory conditions], | ||
| 817 | [gl_cv_func_printf_enomem], | ||
| 818 | [ | ||
| 819 | gl_cv_func_printf_enomem="guessing no" | ||
| 820 | if test "$cross_compiling" = no; then | ||
| 821 | if test $APPLE_UNIVERSAL_BUILD = 0; then | ||
| 822 | AC_LANG_CONFTEST([AC_LANG_SOURCE([ | ||
| 823 | ]GL_NOCRASH[ | ||
| 824 | changequote(,)dnl | ||
| 825 | #include <stdio.h> | ||
| 826 | #include <sys/types.h> | ||
| 827 | #include <sys/time.h> | ||
| 828 | #include <sys/resource.h> | ||
| 829 | #include <errno.h> | ||
| 830 | int main() | ||
| 831 | { | ||
| 832 | struct rlimit limit; | ||
| 833 | int ret; | ||
| 834 | nocrash_init (); | ||
| 835 | /* Some printf implementations allocate temporary space with malloc. */ | ||
| 836 | /* On BSD systems, malloc() is limited by RLIMIT_DATA. */ | ||
| 837 | #ifdef RLIMIT_DATA | ||
| 838 | if (getrlimit (RLIMIT_DATA, &limit) < 0) | ||
| 839 | return 77; | ||
| 840 | if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) | ||
| 841 | limit.rlim_max = 5000000; | ||
| 842 | limit.rlim_cur = limit.rlim_max; | ||
| 843 | if (setrlimit (RLIMIT_DATA, &limit) < 0) | ||
| 844 | return 77; | ||
| 845 | #endif | ||
| 846 | /* On Linux systems, malloc() is limited by RLIMIT_AS. */ | ||
| 847 | #ifdef RLIMIT_AS | ||
| 848 | if (getrlimit (RLIMIT_AS, &limit) < 0) | ||
| 849 | return 77; | ||
| 850 | if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) | ||
| 851 | limit.rlim_max = 5000000; | ||
| 852 | limit.rlim_cur = limit.rlim_max; | ||
| 853 | if (setrlimit (RLIMIT_AS, &limit) < 0) | ||
| 854 | return 77; | ||
| 855 | #endif | ||
| 856 | /* Some printf implementations allocate temporary space on the stack. */ | ||
| 857 | #ifdef RLIMIT_STACK | ||
| 858 | if (getrlimit (RLIMIT_STACK, &limit) < 0) | ||
| 859 | return 77; | ||
| 860 | if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) | ||
| 861 | limit.rlim_max = 5000000; | ||
| 862 | limit.rlim_cur = limit.rlim_max; | ||
| 863 | if (setrlimit (RLIMIT_STACK, &limit) < 0) | ||
| 864 | return 77; | ||
| 865 | #endif | ||
| 866 | ret = printf ("%.5000000f", 1.0); | ||
| 867 | return !(ret == 5000002 || (ret < 0 && errno == ENOMEM)); | ||
| 868 | } | ||
| 869 | changequote([,])dnl | ||
| 870 | ])]) | ||
| 871 | if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then | ||
| 872 | (./conftest | ||
| 873 | result=$? | ||
| 874 | if test $result != 0 && test $result != 77; then result=1; fi | ||
| 875 | exit $result | ||
| 876 | ) >/dev/null 2>/dev/null | ||
| 877 | case $? in | ||
| 878 | 0) gl_cv_func_printf_enomem="yes" ;; | ||
| 879 | 77) gl_cv_func_printf_enomem="guessing no" ;; | ||
| 880 | *) gl_cv_func_printf_enomem="no" ;; | ||
| 881 | esac | ||
| 882 | else | ||
| 883 | gl_cv_func_printf_enomem="guessing no" | ||
| 884 | fi | ||
| 885 | rm -fr conftest* | ||
| 886 | else | ||
| 887 | dnl A universal build on Apple MacOS X platforms. | ||
| 888 | dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode. | ||
| 889 | dnl But we need a configuration result that is valid in both modes. | ||
| 890 | gl_cv_func_printf_enomem="guessing no" | ||
| 891 | fi | ||
| 892 | fi | ||
| 893 | if test "$gl_cv_func_printf_enomem" = "guessing no"; then | ||
| 894 | changequote(,)dnl | ||
| 895 | case "$host_os" in | ||
| 896 | # Guess yes on glibc systems. | ||
| 897 | *-gnu*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 898 | # Guess yes on Solaris. | ||
| 899 | solaris*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 900 | # Guess yes on AIX. | ||
| 901 | aix*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 902 | # Guess yes on HP-UX/hppa. | ||
| 903 | hpux*) case "$host_cpu" in | ||
| 904 | hppa*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 905 | *) gl_cv_func_printf_enomem="guessing no";; | ||
| 906 | esac | ||
| 907 | ;; | ||
| 908 | # Guess yes on IRIX. | ||
| 909 | irix*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 910 | # Guess yes on OSF/1. | ||
| 911 | osf*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 912 | # Guess yes on BeOS. | ||
| 913 | beos*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 914 | # Guess yes on Haiku. | ||
| 915 | haiku*) gl_cv_func_printf_enomem="guessing yes";; | ||
| 916 | # If we don't know, assume the worst. | ||
| 917 | *) gl_cv_func_printf_enomem="guessing no";; | ||
| 918 | esac | ||
| 919 | changequote([,])dnl | ||
| 920 | fi | ||
| 921 | ]) | ||
| 922 | ]) | ||
| 923 | |||
| 924 | dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001) | ||
| 925 | dnl Result is ac_cv_func_snprintf. | ||
| 926 | |||
| 927 | AC_DEFUN([gl_SNPRINTF_PRESENCE], | ||
| 928 | [ | ||
| 929 | AC_CHECK_FUNCS_ONCE([snprintf]) | ||
| 930 | ]) | ||
| 931 | |||
| 932 | dnl Test whether the string produced by the snprintf function is always NUL | ||
| 933 | dnl terminated. (ISO C99, POSIX:2001) | ||
| 934 | dnl Result is gl_cv_func_snprintf_truncation_c99. | ||
| 935 | |||
| 936 | AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99], | ||
| 937 | [ | ||
| 938 | AC_REQUIRE([AC_PROG_CC]) | ||
| 939 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 940 | AC_CACHE_CHECK([whether snprintf truncates the result as in C99], | ||
| 941 | [gl_cv_func_snprintf_truncation_c99], | ||
| 942 | [ | ||
| 943 | AC_TRY_RUN([ | ||
| 944 | #include <stdio.h> | ||
| 945 | #include <string.h> | ||
| 946 | static char buf[100]; | ||
| 947 | int main () | ||
| 948 | { | ||
| 949 | strcpy (buf, "ABCDEF"); | ||
| 950 | snprintf (buf, 3, "%d %d", 4567, 89); | ||
| 951 | if (memcmp (buf, "45\0DEF", 6) != 0) | ||
| 952 | return 1; | ||
| 953 | return 0; | ||
| 954 | }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no], | ||
| 955 | [ | ||
| 956 | changequote(,)dnl | ||
| 957 | case "$host_os" in | ||
| 958 | # Guess yes on glibc systems. | ||
| 959 | *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 960 | # Guess yes on FreeBSD >= 5. | ||
| 961 | freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 962 | freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 963 | # Guess yes on MacOS X >= 10.3. | ||
| 964 | darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 965 | darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 966 | # Guess yes on OpenBSD >= 3.9. | ||
| 967 | openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) | ||
| 968 | gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 969 | openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 970 | # Guess yes on Solaris >= 2.6. | ||
| 971 | solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 972 | solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 973 | # Guess yes on AIX >= 4. | ||
| 974 | aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 975 | aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 976 | # Guess yes on HP-UX >= 11. | ||
| 977 | hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 978 | hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 979 | # Guess yes on IRIX >= 6.5. | ||
| 980 | irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 981 | # Guess yes on OSF/1 >= 5. | ||
| 982 | osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 983 | osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 984 | # Guess yes on NetBSD >= 3. | ||
| 985 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 986 | gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 987 | netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 988 | # Guess yes on BeOS. | ||
| 989 | beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";; | ||
| 990 | # If we don't know, assume the worst. | ||
| 991 | *) gl_cv_func_snprintf_truncation_c99="guessing no";; | ||
| 992 | esac | ||
| 993 | changequote([,])dnl | ||
| 994 | ]) | ||
| 995 | ]) | ||
| 996 | ]) | ||
| 997 | |||
| 998 | dnl Test whether the return value of the snprintf function is the number | ||
| 999 | dnl of bytes (excluding the terminating NUL) that would have been produced | ||
| 1000 | dnl if the buffer had been large enough. (ISO C99, POSIX:2001) | ||
| 1001 | dnl For example, this test program fails on IRIX 6.5: | ||
| 1002 | dnl --------------------------------------------------------------------- | ||
| 1003 | dnl #include <stdio.h> | ||
| 1004 | dnl int main() | ||
| 1005 | dnl { | ||
| 1006 | dnl static char buf[8]; | ||
| 1007 | dnl int retval = snprintf (buf, 3, "%d", 12345); | ||
| 1008 | dnl return retval >= 0 && retval < 3; | ||
| 1009 | dnl } | ||
| 1010 | dnl --------------------------------------------------------------------- | ||
| 1011 | dnl Result is gl_cv_func_snprintf_retval_c99. | ||
| 1012 | |||
| 1013 | AC_DEFUN([gl_SNPRINTF_RETVAL_C99], | ||
| 1014 | [ | ||
| 1015 | AC_REQUIRE([AC_PROG_CC]) | ||
| 1016 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 1017 | AC_CACHE_CHECK([whether snprintf returns a byte count as in C99], | ||
| 1018 | [gl_cv_func_snprintf_retval_c99], | ||
| 1019 | [ | ||
| 1020 | AC_TRY_RUN([ | ||
| 1021 | #include <stdio.h> | ||
| 1022 | #include <string.h> | ||
| 1023 | static char buf[100]; | ||
| 1024 | int main () | ||
| 1025 | { | ||
| 1026 | strcpy (buf, "ABCDEF"); | ||
| 1027 | if (snprintf (buf, 3, "%d %d", 4567, 89) != 7) | ||
| 1028 | return 1; | ||
| 1029 | return 0; | ||
| 1030 | }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no], | ||
| 1031 | [ | ||
| 1032 | changequote(,)dnl | ||
| 1033 | case "$host_os" in | ||
| 1034 | # Guess yes on glibc systems. | ||
| 1035 | *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1036 | # Guess yes on FreeBSD >= 5. | ||
| 1037 | freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1038 | freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1039 | # Guess yes on MacOS X >= 10.3. | ||
| 1040 | darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1041 | darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1042 | # Guess yes on OpenBSD >= 3.9. | ||
| 1043 | openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) | ||
| 1044 | gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1045 | openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1046 | # Guess yes on Solaris >= 2.6. | ||
| 1047 | solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1048 | solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1049 | # Guess yes on AIX >= 4. | ||
| 1050 | aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1051 | aix*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1052 | # Guess yes on NetBSD >= 3. | ||
| 1053 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 1054 | gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1055 | netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1056 | # Guess yes on BeOS. | ||
| 1057 | beos*) gl_cv_func_snprintf_retval_c99="guessing yes";; | ||
| 1058 | # If we don't know, assume the worst. | ||
| 1059 | *) gl_cv_func_snprintf_retval_c99="guessing no";; | ||
| 1060 | esac | ||
| 1061 | changequote([,])dnl | ||
| 1062 | ]) | ||
| 1063 | ]) | ||
| 1064 | ]) | ||
| 1065 | |||
| 1066 | dnl Test whether the snprintf function supports the %n format directive | ||
| 1067 | dnl also in truncated portions of the format string. (ISO C99, POSIX:2001) | ||
| 1068 | dnl Result is gl_cv_func_snprintf_directive_n. | ||
| 1069 | |||
| 1070 | AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N], | ||
| 1071 | [ | ||
| 1072 | AC_REQUIRE([AC_PROG_CC]) | ||
| 1073 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 1074 | AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive], | ||
| 1075 | [gl_cv_func_snprintf_directive_n], | ||
| 1076 | [ | ||
| 1077 | AC_TRY_RUN([ | ||
| 1078 | #include <stdio.h> | ||
| 1079 | #include <string.h> | ||
| 1080 | static char fmtstring[10]; | ||
| 1081 | static char buf[100]; | ||
| 1082 | int main () | ||
| 1083 | { | ||
| 1084 | int count = -1; | ||
| 1085 | /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) | ||
| 1086 | support %n in format strings in read-only memory but not in writable | ||
| 1087 | memory. */ | ||
| 1088 | strcpy (fmtstring, "%d %n"); | ||
| 1089 | snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55); | ||
| 1090 | if (count != 6) | ||
| 1091 | return 1; | ||
| 1092 | return 0; | ||
| 1093 | }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no], | ||
| 1094 | [ | ||
| 1095 | changequote(,)dnl | ||
| 1096 | case "$host_os" in | ||
| 1097 | # Guess yes on glibc systems. | ||
| 1098 | *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1099 | # Guess yes on FreeBSD >= 5. | ||
| 1100 | freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1101 | freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1102 | # Guess yes on MacOS X >= 10.3. | ||
| 1103 | darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1104 | darwin*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1105 | # Guess yes on Solaris >= 2.6. | ||
| 1106 | solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1107 | solaris*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1108 | # Guess yes on AIX >= 4. | ||
| 1109 | aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1110 | aix*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1111 | # Guess yes on IRIX >= 6.5. | ||
| 1112 | irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1113 | # Guess yes on OSF/1 >= 5. | ||
| 1114 | osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1115 | osf*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1116 | # Guess yes on NetBSD >= 3. | ||
| 1117 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 1118 | gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1119 | netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1120 | # Guess yes on BeOS. | ||
| 1121 | beos*) gl_cv_func_snprintf_directive_n="guessing yes";; | ||
| 1122 | # If we don't know, assume the worst. | ||
| 1123 | *) gl_cv_func_snprintf_directive_n="guessing no";; | ||
| 1124 | esac | ||
| 1125 | changequote([,])dnl | ||
| 1126 | ]) | ||
| 1127 | ]) | ||
| 1128 | ]) | ||
| 1129 | |||
| 1130 | dnl Test whether the snprintf function, when passed a size = 1, writes any | ||
| 1131 | dnl output without bounds in this case, behaving like sprintf. This is the | ||
| 1132 | dnl case on Linux libc5. | ||
| 1133 | dnl Result is gl_cv_func_snprintf_size1. | ||
| 1134 | |||
| 1135 | AC_DEFUN([gl_SNPRINTF_SIZE1], | ||
| 1136 | [ | ||
| 1137 | AC_REQUIRE([AC_PROG_CC]) | ||
| 1138 | AC_CACHE_CHECK([whether snprintf respects a size of 1], | ||
| 1139 | [gl_cv_func_snprintf_size1], | ||
| 1140 | [ | ||
| 1141 | AC_TRY_RUN([ | ||
| 1142 | #include <stdio.h> | ||
| 1143 | int main() | ||
| 1144 | { | ||
| 1145 | static char buf[8] = "DEADBEEF"; | ||
| 1146 | snprintf (buf, 1, "%d", 12345); | ||
| 1147 | return buf[1] != 'E'; | ||
| 1148 | }], | ||
| 1149 | [gl_cv_func_snprintf_size1=yes], | ||
| 1150 | [gl_cv_func_snprintf_size1=no], | ||
| 1151 | [gl_cv_func_snprintf_size1="guessing yes"]) | ||
| 1152 | ]) | ||
| 1153 | ]) | ||
| 1154 | |||
| 1155 | dnl Test whether the vsnprintf function, when passed a zero size, produces no | ||
| 1156 | dnl output. (ISO C99, POSIX:2001) | ||
| 1157 | dnl For example, snprintf nevertheless writes a NUL byte in this case | ||
| 1158 | dnl on OSF/1 5.1: | ||
| 1159 | dnl --------------------------------------------------------------------- | ||
| 1160 | dnl #include <stdio.h> | ||
| 1161 | dnl int main() | ||
| 1162 | dnl { | ||
| 1163 | dnl static char buf[8] = "DEADBEEF"; | ||
| 1164 | dnl snprintf (buf, 0, "%d", 12345); | ||
| 1165 | dnl return buf[0] != 'D'; | ||
| 1166 | dnl } | ||
| 1167 | dnl --------------------------------------------------------------------- | ||
| 1168 | dnl And vsnprintf writes any output without bounds in this case, behaving like | ||
| 1169 | dnl vsprintf, on HP-UX 11 and OSF/1 5.1: | ||
| 1170 | dnl --------------------------------------------------------------------- | ||
| 1171 | dnl #include <stdarg.h> | ||
| 1172 | dnl #include <stdio.h> | ||
| 1173 | dnl static int my_snprintf (char *buf, int size, const char *format, ...) | ||
| 1174 | dnl { | ||
| 1175 | dnl va_list args; | ||
| 1176 | dnl int ret; | ||
| 1177 | dnl va_start (args, format); | ||
| 1178 | dnl ret = vsnprintf (buf, size, format, args); | ||
| 1179 | dnl va_end (args); | ||
| 1180 | dnl return ret; | ||
| 1181 | dnl } | ||
| 1182 | dnl int main() | ||
| 1183 | dnl { | ||
| 1184 | dnl static char buf[8] = "DEADBEEF"; | ||
| 1185 | dnl my_snprintf (buf, 0, "%d", 12345); | ||
| 1186 | dnl return buf[0] != 'D'; | ||
| 1187 | dnl } | ||
| 1188 | dnl --------------------------------------------------------------------- | ||
| 1189 | dnl Result is gl_cv_func_vsnprintf_zerosize_c99. | ||
| 1190 | |||
| 1191 | AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99], | ||
| 1192 | [ | ||
| 1193 | AC_REQUIRE([AC_PROG_CC]) | ||
| 1194 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 1195 | AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99], | ||
| 1196 | [gl_cv_func_vsnprintf_zerosize_c99], | ||
| 1197 | [ | ||
| 1198 | AC_TRY_RUN([ | ||
| 1199 | #include <stdarg.h> | ||
| 1200 | #include <stdio.h> | ||
| 1201 | static int my_snprintf (char *buf, int size, const char *format, ...) | ||
| 1202 | { | ||
| 1203 | va_list args; | ||
| 1204 | int ret; | ||
| 1205 | va_start (args, format); | ||
| 1206 | ret = vsnprintf (buf, size, format, args); | ||
| 1207 | va_end (args); | ||
| 1208 | return ret; | ||
| 1209 | } | ||
| 1210 | int main() | ||
| 1211 | { | ||
| 1212 | static char buf[8] = "DEADBEEF"; | ||
| 1213 | my_snprintf (buf, 0, "%d", 12345); | ||
| 1214 | return buf[0] != 'D'; | ||
| 1215 | }], | ||
| 1216 | [gl_cv_func_vsnprintf_zerosize_c99=yes], | ||
| 1217 | [gl_cv_func_vsnprintf_zerosize_c99=no], | ||
| 1218 | [ | ||
| 1219 | changequote(,)dnl | ||
| 1220 | case "$host_os" in | ||
| 1221 | # Guess yes on glibc systems. | ||
| 1222 | *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1223 | # Guess yes on FreeBSD >= 5. | ||
| 1224 | freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1225 | freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1226 | # Guess yes on MacOS X >= 10.3. | ||
| 1227 | darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1228 | darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1229 | # Guess yes on Cygwin. | ||
| 1230 | cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1231 | # Guess yes on Solaris >= 2.6. | ||
| 1232 | solaris2.[0-5]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1233 | solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1234 | # Guess yes on AIX >= 4. | ||
| 1235 | aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1236 | aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1237 | # Guess yes on IRIX >= 6.5. | ||
| 1238 | irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1239 | # Guess yes on NetBSD >= 3. | ||
| 1240 | netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) | ||
| 1241 | gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1242 | netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1243 | # Guess yes on BeOS. | ||
| 1244 | beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1245 | # Guess yes on mingw. | ||
| 1246 | mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; | ||
| 1247 | # If we don't know, assume the worst. | ||
| 1248 | *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; | ||
| 1249 | esac | ||
| 1250 | changequote([,])dnl | ||
| 1251 | ]) | ||
| 1252 | ]) | ||
| 1253 | ]) | ||
| 1254 | |||
| 1255 | dnl The results of these tests on various platforms are: | ||
| 1256 | dnl | ||
| 1257 | dnl 1 = gl_PRINTF_SIZES_C99 | ||
| 1258 | dnl 2 = gl_PRINTF_LONG_DOUBLE | ||
| 1259 | dnl 3 = gl_PRINTF_INFINITE | ||
| 1260 | dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE | ||
| 1261 | dnl 5 = gl_PRINTF_DIRECTIVE_A | ||
| 1262 | dnl 6 = gl_PRINTF_DIRECTIVE_F | ||
| 1263 | dnl 7 = gl_PRINTF_DIRECTIVE_N | ||
| 1264 | dnl 8 = gl_PRINTF_POSITIONS | ||
| 1265 | dnl 9 = gl_PRINTF_FLAG_GROUPING | ||
| 1266 | dnl 10 = gl_PRINTF_FLAG_LEFTADJUST | ||
| 1267 | dnl 11 = gl_PRINTF_FLAG_ZERO | ||
| 1268 | dnl 12 = gl_PRINTF_PRECISION | ||
| 1269 | dnl 13 = gl_PRINTF_ENOMEM | ||
| 1270 | dnl 14 = gl_SNPRINTF_PRESENCE | ||
| 1271 | dnl 15 = gl_SNPRINTF_TRUNCATION_C99 | ||
| 1272 | dnl 16 = gl_SNPRINTF_RETVAL_C99 | ||
| 1273 | dnl 17 = gl_SNPRINTF_DIRECTIVE_N | ||
| 1274 | dnl 18 = gl_SNPRINTF_SIZE1 | ||
| 1275 | dnl 19 = gl_VSNPRINTF_ZEROSIZE_C99 | ||
| 1276 | dnl | ||
| 1277 | dnl 1 = checking whether printf supports size specifiers as in C99... | ||
| 1278 | dnl 2 = checking whether printf supports 'long double' arguments... | ||
| 1279 | dnl 3 = checking whether printf supports infinite 'double' arguments... | ||
| 1280 | dnl 4 = checking whether printf supports infinite 'long double' arguments... | ||
| 1281 | dnl 5 = checking whether printf supports the 'a' and 'A' directives... | ||
| 1282 | dnl 6 = checking whether printf supports the 'F' directive... | ||
| 1283 | dnl 7 = checking whether printf supports the 'n' directive... | ||
| 1284 | dnl 8 = checking whether printf supports POSIX/XSI format strings with positions... | ||
| 1285 | dnl 9 = checking whether printf supports the grouping flag... | ||
| 1286 | dnl 10 = checking whether printf supports the left-adjust flag correctly... | ||
| 1287 | dnl 11 = checking whether printf supports the zero flag correctly... | ||
| 1288 | dnl 12 = checking whether printf supports large precisions... | ||
| 1289 | dnl 13 = checking whether printf survives out-of-memory conditions... | ||
| 1290 | dnl 14 = checking for snprintf... | ||
| 1291 | dnl 15 = checking whether snprintf truncates the result as in C99... | ||
| 1292 | dnl 16 = checking whether snprintf returns a byte count as in C99... | ||
| 1293 | dnl 17 = checking whether snprintf fully supports the 'n' directive... | ||
| 1294 | dnl 18 = checking whether snprintf respects a size of 1... | ||
| 1295 | dnl 19 = checking whether vsnprintf respects a zero size as in C99... | ||
| 1296 | dnl | ||
| 1297 | dnl . = yes, # = no. | ||
| 1298 | dnl | ||
| 1299 | dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ||
| 1300 | dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . | ||
| 1301 | dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . | ||
| 1302 | dnl FreeBSD 5.4, 6.1 . . . . # . . . . . # . # . . . . . . | ||
| 1303 | dnl MacOS X 10.3.9 . . . . # . . . . . # . # . . . . . . | ||
| 1304 | dnl OpenBSD 3.9, 4.0 . . # # # # . . # . # . # . . . . . . | ||
| 1305 | dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . ? # ? ? . . . . . . | ||
| 1306 | dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . . # ? # ? ? . . . . . . | ||
| 1307 | dnl Solaris 10 . . # # # . . . . . # . . . . . . . . | ||
| 1308 | dnl Solaris 2.6 ... 9 # . # # # # . . . . # . . . . . . . . | ||
| 1309 | dnl Solaris 2.5.1 # . # # # # . . . . # . . # # # # # # | ||
| 1310 | dnl AIX 5.2 . . # # # . . . . . # . . . . . . . . | ||
| 1311 | dnl AIX 4.3.2, 5.1 # . # # # # . . . . # . . . . . . . . | ||
| 1312 | dnl HP-UX 11.31 . . . . # . . . . . # . . . . # # . . | ||
| 1313 | dnl HP-UX 11.{00,11,23} # . . . # # . . . . # . . . . # # . # | ||
| 1314 | dnl HP-UX 10.20 # . . . # # . . . # # . . . . # # ? # | ||
| 1315 | dnl IRIX 6.5 # . # # # # . . . . # . . . . # . . . | ||
| 1316 | dnl OSF/1 5.1 # . # # # # . . . . # . . . . # . . # | ||
| 1317 | dnl OSF/1 4.0d # . # # # # . . . . # . . # # # # # # | ||
| 1318 | dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? ? ? ? . . . ? ? ? | ||
| 1319 | dnl NetBSD 3.0 . . . . # # . # # ? # . # . . . . . . | ||
| 1320 | dnl Haiku . . . # # # . . . . . . ? . . . . . . | ||
| 1321 | dnl BeOS # # . # # # . # . ? . # ? . . . . . . | ||
| 1322 | dnl mingw # # # # # # . # # . # # ? . # # # . . | ||
