summaryrefslogtreecommitdiffstats
path: root/gl/m4/printf.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/printf.m4')
-rw-r--r--gl/m4/printf.m4206
1 files changed, 150 insertions, 56 deletions
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4
index 4d109935..87aa45c5 100644
--- a/gl/m4/printf.m4
+++ b/gl/m4/printf.m4
@@ -1,4 +1,4 @@
1# printf.m4 serial 26 1# printf.m4 serial 33
2dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -125,7 +125,8 @@ changequote([,])dnl
125]) 125])
126 126
127dnl Test whether the *printf family of functions supports infinite and NaN 127dnl Test whether the *printf family of functions supports infinite and NaN
128dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) 128dnl 'double' arguments and negative zero arguments in the %f, %e, %g
129dnl directives. (ISO C99, POSIX:2001)
129dnl Result is gl_cv_func_printf_infinite. 130dnl Result is gl_cv_func_printf_infinite.
130 131
131AC_DEFUN([gl_PRINTF_INFINITE], 132AC_DEFUN([gl_PRINTF_INFINITE],
@@ -156,6 +157,13 @@ strisnan (const char *string, size_t start_index, size_t end_index)
156 } 157 }
157 return 0; 158 return 0;
158} 159}
160static int
161have_minus_zero ()
162{
163 static double plus_zero = 0.0;
164 double minus_zero = - plus_zero;
165 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
166}
159static char buf[10000]; 167static char buf[10000];
160static double zero = 0.0; 168static double zero = 0.0;
161int main () 169int main ()
@@ -187,6 +195,11 @@ int main ()
187 if (sprintf (buf, "%g", zero / zero) < 0 195 if (sprintf (buf, "%g", zero / zero) < 0
188 || !strisnan (buf, 0, strlen (buf))) 196 || !strisnan (buf, 0, strlen (buf)))
189 return 1; 197 return 1;
198 /* This test fails on HP-UX 10.20. */
199 if (have_minus_zero ())
200 if (sprintf (buf, "%g", - zero) < 0
201 || strcmp (buf, "-0") != 0)
202 return 1;
190 return 0; 203 return 0;
191}], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no], 204}], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
192 [ 205 [
@@ -225,7 +238,7 @@ AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
225[ 238[
226 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) 239 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
227 AC_REQUIRE([AC_PROG_CC]) 240 AC_REQUIRE([AC_PROG_CC])
228 AC_REQUIRE([AC_C_BIGENDIAN]) 241 AC_REQUIRE([gl_BIGENDIAN])
229 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 242 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
230 dnl The user can set or unset the variable gl_printf_safe to indicate 243 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. 244 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
@@ -545,7 +558,7 @@ int main ()
545 if (sprintf (buf, "%F", 1.0 / 0.0) < 0 558 if (sprintf (buf, "%F", 1.0 / 0.0) < 0
546 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0)) 559 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
547 return 1; 560 return 1;
548 /* This catches a Cygwin 2007 bug. */ 561 /* This catches a Cygwin 1.5.x bug. */
549 if (sprintf (buf, "%.F", 1234.0) < 0 562 if (sprintf (buf, "%.F", 1234.0) < 0
550 || strcmp (buf, "1234") != 0) 563 || strcmp (buf, "1234") != 0)
551 return 1; 564 return 1;
@@ -612,6 +625,84 @@ changequote([,])dnl
612 ]) 625 ])
613]) 626])
614 627
628dnl Test whether the *printf family of functions supports the %ls format
629dnl directive and in particular, when a precision is specified, whether
630dnl the functions stop converting the wide string argument when the number
631dnl of bytes that have been produced by this conversion equals or exceeds
632dnl the precision.
633dnl Result is gl_cv_func_printf_directive_ls.
634
635AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
636[
637 AC_REQUIRE([AC_PROG_CC])
638 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
639 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
640 [gl_cv_func_printf_directive_ls],
641 [
642 AC_TRY_RUN([
643/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
644 <wchar.h>.
645 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
646 included before <wchar.h>. */
647#include <stddef.h>
648#include <stdio.h>
649#include <time.h>
650#include <wchar.h>
651#include <string.h>
652int main ()
653{
654 char buf[100];
655 /* Test whether %ls works at all.
656 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
657 Cygwin 1.5. */
658 {
659 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
660 buf[0] = '\0';
661 if (sprintf (buf, "%ls", wstring) < 0
662 || strcmp (buf, "abc") != 0)
663 return 1;
664 }
665 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
666 assertion failure inside libc), but not on OpenBSD 4.0. */
667 {
668 static const wchar_t wstring[] = { 'a', 0 };
669 buf[0] = '\0';
670 if (sprintf (buf, "%ls", wstring) < 0
671 || strcmp (buf, "a") != 0)
672 return 1;
673 }
674 /* Test whether precisions in %ls are supported as specified in ISO C 99
675 section 7.19.6.1:
676 "If a precision is specified, no more than that many bytes are written
677 (including shift sequences, if any), and the array shall contain a
678 null wide character if, to equal the multibyte character sequence
679 length given by the precision, the function would need to access a
680 wide character one past the end of the array."
681 This test fails on Solaris 10. */
682 {
683 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
684 buf[0] = '\0';
685 if (sprintf (buf, "%.2ls", wstring) < 0
686 || strcmp (buf, "ab") != 0)
687 return 1;
688 }
689 return 0;
690}], [gl_cv_func_printf_directive_ls=yes], [gl_cv_func_printf_directive_ls=no],
691 [
692changequote(,)dnl
693 case "$host_os" in
694 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
695 irix*) gl_cv_func_printf_directive_ls="guessing no";;
696 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
697 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
698 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
699 *) gl_cv_func_printf_directive_ls="guessing yes";;
700 esac
701changequote([,])dnl
702 ])
703 ])
704])
705
615dnl Test whether the *printf family of functions supports POSIX/XSI format 706dnl Test whether the *printf family of functions supports POSIX/XSI format
616dnl strings with positions. (POSIX:2001) 707dnl strings with positions. (POSIX:2001)
617dnl Result is gl_cv_func_printf_positions. 708dnl Result is gl_cv_func_printf_positions.
@@ -1142,7 +1233,7 @@ AC_DEFUN([gl_SNPRINTF_SIZE1],
1142#include <stdio.h> 1233#include <stdio.h>
1143int main() 1234int main()
1144{ 1235{
1145 static char buf[8] = "DEADBEEF"; 1236 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1146 snprintf (buf, 1, "%d", 12345); 1237 snprintf (buf, 1, "%d", 12345);
1147 return buf[1] != 'E'; 1238 return buf[1] != 'E';
1148}], 1239}],
@@ -1160,7 +1251,7 @@ dnl ---------------------------------------------------------------------
1160dnl #include <stdio.h> 1251dnl #include <stdio.h>
1161dnl int main() 1252dnl int main()
1162dnl { 1253dnl {
1163dnl static char buf[8] = "DEADBEEF"; 1254dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1164dnl snprintf (buf, 0, "%d", 12345); 1255dnl snprintf (buf, 0, "%d", 12345);
1165dnl return buf[0] != 'D'; 1256dnl return buf[0] != 'D';
1166dnl } 1257dnl }
@@ -1181,7 +1272,7 @@ dnl return ret;
1181dnl } 1272dnl }
1182dnl int main() 1273dnl int main()
1183dnl { 1274dnl {
1184dnl static char buf[8] = "DEADBEEF"; 1275dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1185dnl my_snprintf (buf, 0, "%d", 12345); 1276dnl my_snprintf (buf, 0, "%d", 12345);
1186dnl return buf[0] != 'D'; 1277dnl return buf[0] != 'D';
1187dnl } 1278dnl }
@@ -1209,7 +1300,7 @@ static int my_snprintf (char *buf, int size, const char *format, ...)
1209} 1300}
1210int main() 1301int main()
1211{ 1302{
1212 static char buf[8] = "DEADBEEF"; 1303 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1213 my_snprintf (buf, 0, "%d", 12345); 1304 my_snprintf (buf, 0, "%d", 12345);
1214 return buf[0] != 'D'; 1305 return buf[0] != 'D';
1215}], 1306}],
@@ -1261,18 +1352,19 @@ dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1261dnl 5 = gl_PRINTF_DIRECTIVE_A 1352dnl 5 = gl_PRINTF_DIRECTIVE_A
1262dnl 6 = gl_PRINTF_DIRECTIVE_F 1353dnl 6 = gl_PRINTF_DIRECTIVE_F
1263dnl 7 = gl_PRINTF_DIRECTIVE_N 1354dnl 7 = gl_PRINTF_DIRECTIVE_N
1264dnl 8 = gl_PRINTF_POSITIONS 1355dnl 8 = gl_PRINTF_DIRECTIVE_LS
1265dnl 9 = gl_PRINTF_FLAG_GROUPING 1356dnl 9 = gl_PRINTF_POSITIONS
1266dnl 10 = gl_PRINTF_FLAG_LEFTADJUST 1357dnl 10 = gl_PRINTF_FLAG_GROUPING
1267dnl 11 = gl_PRINTF_FLAG_ZERO 1358dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1268dnl 12 = gl_PRINTF_PRECISION 1359dnl 12 = gl_PRINTF_FLAG_ZERO
1269dnl 13 = gl_PRINTF_ENOMEM 1360dnl 13 = gl_PRINTF_PRECISION
1270dnl 14 = gl_SNPRINTF_PRESENCE 1361dnl 14 = gl_PRINTF_ENOMEM
1271dnl 15 = gl_SNPRINTF_TRUNCATION_C99 1362dnl 15 = gl_SNPRINTF_PRESENCE
1272dnl 16 = gl_SNPRINTF_RETVAL_C99 1363dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1273dnl 17 = gl_SNPRINTF_DIRECTIVE_N 1364dnl 17 = gl_SNPRINTF_RETVAL_C99
1274dnl 18 = gl_SNPRINTF_SIZE1 1365dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1275dnl 19 = gl_VSNPRINTF_ZEROSIZE_C99 1366dnl 19 = gl_SNPRINTF_SIZE1
1367dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1276dnl 1368dnl
1277dnl 1 = checking whether printf supports size specifiers as in C99... 1369dnl 1 = checking whether printf supports size specifiers as in C99...
1278dnl 2 = checking whether printf supports 'long double' arguments... 1370dnl 2 = checking whether printf supports 'long double' arguments...
@@ -1281,42 +1373,44 @@ dnl 4 = checking whether printf supports infinite 'long double' arguments...
1281dnl 5 = checking whether printf supports the 'a' and 'A' directives... 1373dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1282dnl 6 = checking whether printf supports the 'F' directive... 1374dnl 6 = checking whether printf supports the 'F' directive...
1283dnl 7 = checking whether printf supports the 'n' directive... 1375dnl 7 = checking whether printf supports the 'n' directive...
1284dnl 8 = checking whether printf supports POSIX/XSI format strings with positions... 1376dnl 8 = checking whether printf supports the 'ls' directive...
1285dnl 9 = checking whether printf supports the grouping flag... 1377dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1286dnl 10 = checking whether printf supports the left-adjust flag correctly... 1378dnl 10 = checking whether printf supports the grouping flag...
1287dnl 11 = checking whether printf supports the zero flag correctly... 1379dnl 11 = checking whether printf supports the left-adjust flag correctly...
1288dnl 12 = checking whether printf supports large precisions... 1380dnl 12 = checking whether printf supports the zero flag correctly...
1289dnl 13 = checking whether printf survives out-of-memory conditions... 1381dnl 13 = checking whether printf supports large precisions...
1290dnl 14 = checking for snprintf... 1382dnl 14 = checking whether printf survives out-of-memory conditions...
1291dnl 15 = checking whether snprintf truncates the result as in C99... 1383dnl 15 = checking for snprintf...
1292dnl 16 = checking whether snprintf returns a byte count as in C99... 1384dnl 16 = checking whether snprintf truncates the result as in C99...
1293dnl 17 = checking whether snprintf fully supports the 'n' directive... 1385dnl 17 = checking whether snprintf returns a byte count as in C99...
1294dnl 18 = checking whether snprintf respects a size of 1... 1386dnl 18 = checking whether snprintf fully supports the 'n' directive...
1295dnl 19 = checking whether vsnprintf respects a zero size as in C99... 1387dnl 19 = checking whether snprintf respects a size of 1...
1388dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1296dnl 1389dnl
1297dnl . = yes, # = no. 1390dnl . = yes, # = no.
1298dnl 1391dnl
1299dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1392dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1300dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . 1393dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1301dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . 1394dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1302dnl FreeBSD 5.4, 6.1 . . . . # . . . . . # . # . . . . . . 1395dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1303dnl MacOS X 10.3.9 . . . . # . . . . . # . # . . . . . . 1396dnl MacOS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1304dnl OpenBSD 3.9, 4.0 . . # # # # . . # . # . # . . . . . . 1397dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1305dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . ? # ? ? . . . . . . 1398dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1306dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . . # ? # ? ? . . . . . . 1399dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1307dnl Solaris 10 . . # # # . . . . . # . . . . . . . . 1400dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1308dnl Solaris 2.6 ... 9 # . # # # # . . . . # . . . . . . . . 1401dnl Solaris 10 . . # # # . . # . . . # . . . . . . . .
1309dnl Solaris 2.5.1 # . # # # # . . . . # . . # # # # # # 1402dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . . . . .
1310dnl AIX 5.2 . . # # # . . . . . # . . . . . . . . 1403dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1311dnl AIX 4.3.2, 5.1 # . # # # # . . . . # . . . . . . . . 1404dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1312dnl HP-UX 11.31 . . . . # . . . . . # . . . . # # . . 1405dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . . . . .
1313dnl HP-UX 11.{00,11,23} # . . . # # . . . . # . . . . # # . # 1406dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1314dnl HP-UX 10.20 # . . . # # . . . # # . . . . # # ? # 1407dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1315dnl IRIX 6.5 # . # # # # . . . . # . . . . # . . . 1408dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1316dnl OSF/1 5.1 # . # # # # . . . . # . . . . # . . # 1409dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1317dnl OSF/1 4.0d # . # # # # . . . . # . . # # # # # # 1410dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1318dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? ? ? ? . . . ? ? ? 1411dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1319dnl NetBSD 3.0 . . . . # # . # # ? # . # . . . . . . 1412dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1320dnl Haiku . . . # # # . . . . . . ? . . . . . . 1413dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1321dnl BeOS # # . # # # . # . ? . # ? . . . . . . 1414dnl Haiku . . . # # # . # . . . . . ? . . . . . .
1322dnl mingw # # # # # # . # # . # # ? . # # # . . 1415dnl BeOS # # . # # # . ? # . ? . # ? . . . . . .
1416dnl mingw # # # # # # . . # # . # # ? . # # # . .