2
dnl Copyright (C) 2003, 2007-2011 Free Software Foundation, Inc.
2
dnl Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
5
5
dnl with or without modifications, as long as this notice is preserved.
63
63
# Guess yes on FreeBSD >= 5.
64
64
freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";;
65
65
freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
66
# Guess yes on MacOS X >= 10.3.
66
# Guess yes on Mac OS X >= 10.3.
67
67
darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
68
68
darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
69
69
# Guess yes on OpenBSD >= 3.9.
181
if (sprintf (buf, "%f", 1.0 / 0.0) < 0
181
if (sprintf (buf, "%f", 1.0 / zero) < 0
182
182
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
184
if (sprintf (buf, "%f", -1.0 / 0.0) < 0
184
if (sprintf (buf, "%f", -1.0 / zero) < 0
185
185
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
187
187
if (sprintf (buf, "%f", zero / zero) < 0
188
188
|| !strisnan (buf, 0, strlen (buf)))
190
if (sprintf (buf, "%e", 1.0 / 0.0) < 0
190
if (sprintf (buf, "%e", 1.0 / zero) < 0
191
191
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
193
if (sprintf (buf, "%e", -1.0 / 0.0) < 0
193
if (sprintf (buf, "%e", -1.0 / zero) < 0
194
194
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
196
196
if (sprintf (buf, "%e", zero / zero) < 0
197
197
|| !strisnan (buf, 0, strlen (buf)))
199
if (sprintf (buf, "%g", 1.0 / 0.0) < 0
199
if (sprintf (buf, "%g", 1.0 / zero) < 0
200
200
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
202
if (sprintf (buf, "%g", -1.0 / 0.0) < 0
202
if (sprintf (buf, "%g", -1.0 / zero) < 0
203
203
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
205
205
if (sprintf (buf, "%g", zero / zero) < 0
222
222
# Guess yes on FreeBSD >= 6.
223
223
freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";;
224
224
freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
225
# Guess yes on MacOS X >= 10.3.
225
# Guess yes on Mac OS X >= 10.3.
226
226
darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
227
227
darwin*) gl_cv_func_printf_infinite="guessing yes";;
228
228
# Guess yes on HP-UX >= 11.
297
if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
298
if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
298
299
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
300
if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
301
if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
301
302
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
303
304
if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
304
305
|| !strisnan (buf, 0, strlen (buf)))
306
if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
307
if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
307
308
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
309
if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
310
if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
310
311
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
312
313
if (sprintf (buf, "%Le", zeroL / zeroL) < 0
313
314
|| !strisnan (buf, 0, strlen (buf)))
315
if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
316
if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
316
317
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
318
if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
319
if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
319
320
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
321
322
if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
322
323
|| !strisnan (buf, 0, strlen (buf)))
324
#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_))
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
325
326
/* Representation of an 80-bit 'long double' as an initializer for a sequence
326
327
of 'unsigned int' words. */
327
328
# ifdef WORDS_BIGENDIAN
503
505
/* This catches a FreeBSD 6.1 bug. See
504
506
<http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
505
if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
507
if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
506
508
|| buf[0] == '0')
508
/* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
510
/* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
509
511
if (sprintf (buf, "%.1a", 1.999) < 0
510
512
|| (strcmp (buf, "0x1.0p+1") != 0
511
513
&& strcmp (buf, "0x2.0p+0") != 0
512
514
&& strcmp (buf, "0x4.0p-1") != 0
513
515
&& strcmp (buf, "0x8.0p-2") != 0))
515
/* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
517
/* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
516
518
glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
517
519
if (sprintf (buf, "%.1La", 1.999L) < 0
518
520
|| (strcmp (buf, "0x1.0p+1") != 0
562
564
#include <stdio.h>
563
565
#include <string.h>
564
566
static char buf[100];
567
static double zero = 0.0;
568
571
if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
569
572
|| strcmp (buf, "1234567.000000 33") != 0)
571
if (sprintf (buf, "%F", 1.0 / 0.0) < 0
574
if (sprintf (buf, "%F", 1.0 / zero) < 0
572
575
|| (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
574
577
/* This catches a Cygwin 1.5.x bug. */
587
590
# Guess yes on FreeBSD >= 6.
588
591
freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
589
592
freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
590
# Guess yes on MacOS X >= 10.3.
593
# Guess yes on Mac OS X >= 10.3.
591
594
darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
592
595
darwin*) gl_cv_func_printf_directive_f="guessing yes";;
593
596
# Guess yes on Solaris >= 2.10.
616
619
[AC_LANG_SOURCE([[
617
620
#include <stdio.h>
618
622
#include <string.h>
624
/* See page about "Parameter Validation" on msdn.microsoft.com. */
626
invalid_parameter_handler (const wchar_t *expression,
627
const wchar_t *function,
628
const wchar_t *file, unsigned int line,
619
634
static char fmtstring[10];
620
635
static char buf[100];
640
_set_invalid_parameter_handler (invalid_parameter_handler);
624
642
/* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
625
643
support %n in format strings in read-only memory but not in writable
862
881
#include <stdio.h>
863
882
#include <string.h>
864
883
static char buf[100];
884
static double zero = 0.0;
867
if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
887
if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
868
888
|| (strcmp (buf, " inf") != 0
869
889
&& strcmp (buf, " infinity") != 0))
933
953
changequote(,)dnl
934
954
case "$host_os" in
935
# Guess no only on Solaris, native Win32, and BeOS systems.
955
# Guess no only on Solaris, native Windows, and BeOS systems.
936
956
solaris*) gl_cv_func_printf_precision="guessing no" ;;
937
957
mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
938
958
beos*) gl_cv_func_printf_precision="guessing no" ;;
1083
1105
[AC_LANG_SOURCE([[
1084
1106
#include <stdio.h>
1085
1107
#include <string.h>
1109
# define my_snprintf snprintf
1111
# include <stdarg.h>
1112
static int my_snprintf (char *buf, int size, const char *format, ...)
1116
va_start (args, format);
1117
ret = vsnprintf (buf, size, format, args);
1086
1122
static char buf[100];
1089
1125
strcpy (buf, "ABCDEF");
1090
snprintf (buf, 3, "%d %d", 4567, 89);
1126
my_snprintf (buf, 3, "%d %d", 4567, 89);
1091
1127
if (memcmp (buf, "45\0DEF", 6) != 0)
1102
1138
# Guess yes on FreeBSD >= 5.
1103
1139
freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1104
1140
freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1105
# Guess yes on MacOS X >= 10.3.
1141
# Guess yes on Mac OS X >= 10.3.
1106
1142
darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1107
1143
darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1108
1144
# Guess yes on OpenBSD >= 3.9.
1164
1201
[AC_LANG_SOURCE([[
1165
1202
#include <stdio.h>
1166
1203
#include <string.h>
1205
# define my_snprintf snprintf
1207
# include <stdarg.h>
1208
static int my_snprintf (char *buf, int size, const char *format, ...)
1212
va_start (args, format);
1213
ret = vsnprintf (buf, size, format, args);
1167
1218
static char buf[100];
1170
1221
strcpy (buf, "ABCDEF");
1171
if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1222
if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1173
if (snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1224
if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1175
if (snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1226
if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1186
1237
# Guess yes on FreeBSD >= 5.
1187
1238
freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1188
1239
freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1189
# Guess yes on MacOS X >= 10.3.
1240
# Guess yes on Mac OS X >= 10.3.
1190
1241
darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1191
1242
darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1192
1243
# Guess yes on OpenBSD >= 3.9.
1237
1303
support %n in format strings in read-only memory but not in writable
1239
1305
strcpy (fmtstring, "%d %n");
1240
snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1306
my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1241
1307
if (count != 6)
1252
1318
# Guess yes on FreeBSD >= 5.
1253
1319
freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1254
1320
freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1255
# Guess yes on MacOS X >= 10.3.
1321
# Guess yes on Mac OS X >= 10.3.
1256
1322
darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1257
1323
darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1258
1324
# Guess yes on Solaris >= 2.6.
1289
1355
AC_DEFUN([gl_SNPRINTF_SIZE1],
1291
1357
AC_REQUIRE([AC_PROG_CC])
1358
AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1292
1359
AC_CACHE_CHECK([whether snprintf respects a size of 1],
1293
1360
[gl_cv_func_snprintf_size1],
1296
1363
[AC_LANG_SOURCE([[
1297
1364
#include <stdio.h>
1366
# define my_snprintf snprintf
1368
# include <stdarg.h>
1369
static int my_snprintf (char *buf, int size, const char *format, ...)
1373
va_start (args, format);
1374
ret = vsnprintf (buf, size, format, args);
1300
1381
static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1301
snprintf (buf, 1, "%d", 12345);
1382
my_snprintf (buf, 1, "%d", 12345);
1302
1383
return buf[1] != 'E';
1304
1385
[gl_cv_func_snprintf_size1=yes],
1379
1460
# Guess yes on FreeBSD >= 5.
1380
1461
freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1381
1462
freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1382
# Guess yes on MacOS X >= 10.3.
1463
# Guess yes on Mac OS X >= 10.3.
1383
1464
darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1384
1465
darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1385
1466
# Guess yes on Cygwin.
1459
1540
dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1460
1541
dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1461
1542
dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1462
dnl MacOS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1463
dnl MacOS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1543
dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1544
dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1464
1545
dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1465
1546
dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1466
1547
dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1467
1548
dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1468
dnl Solaris 11 2010-11 . . # # # . . # . . . # . . . . . . . .
1549
dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
1469
1550
dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1470
1551
dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1471
1552
dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #