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