diff options
Diffstat (limited to 'gl/m4/printf.m4')
| -rw-r--r-- | gl/m4/printf.m4 | 206 |
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 |
| 2 | dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -125,7 +125,8 @@ changequote([,])dnl | |||
| 125 | ]) | 125 | ]) |
| 126 | 126 | ||
| 127 | dnl Test whether the *printf family of functions supports infinite and NaN | 127 | dnl Test whether the *printf family of functions supports infinite and NaN |
| 128 | dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) | 128 | dnl 'double' arguments and negative zero arguments in the %f, %e, %g |
| 129 | dnl directives. (ISO C99, POSIX:2001) | ||
| 129 | dnl Result is gl_cv_func_printf_infinite. | 130 | dnl Result is gl_cv_func_printf_infinite. |
| 130 | 131 | ||
| 131 | AC_DEFUN([gl_PRINTF_INFINITE], | 132 | AC_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 | } |
| 160 | static int | ||
| 161 | have_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 | } | ||
| 159 | static char buf[10000]; | 167 | static char buf[10000]; |
| 160 | static double zero = 0.0; | 168 | static double zero = 0.0; |
| 161 | int main () | 169 | int 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 | ||
| 628 | dnl Test whether the *printf family of functions supports the %ls format | ||
| 629 | dnl directive and in particular, when a precision is specified, whether | ||
| 630 | dnl the functions stop converting the wide string argument when the number | ||
| 631 | dnl of bytes that have been produced by this conversion equals or exceeds | ||
| 632 | dnl the precision. | ||
| 633 | dnl Result is gl_cv_func_printf_directive_ls. | ||
| 634 | |||
| 635 | AC_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> | ||
| 652 | int 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 | [ | ||
| 692 | changequote(,)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 | ||
| 701 | changequote([,])dnl | ||
| 702 | ]) | ||
| 703 | ]) | ||
| 704 | ]) | ||
| 705 | |||
| 615 | dnl Test whether the *printf family of functions supports POSIX/XSI format | 706 | dnl Test whether the *printf family of functions supports POSIX/XSI format |
| 616 | dnl strings with positions. (POSIX:2001) | 707 | dnl strings with positions. (POSIX:2001) |
| 617 | dnl Result is gl_cv_func_printf_positions. | 708 | dnl Result is gl_cv_func_printf_positions. |
| @@ -1142,7 +1233,7 @@ AC_DEFUN([gl_SNPRINTF_SIZE1], | |||
| 1142 | #include <stdio.h> | 1233 | #include <stdio.h> |
| 1143 | int main() | 1234 | int 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 --------------------------------------------------------------------- | |||
| 1160 | dnl #include <stdio.h> | 1251 | dnl #include <stdio.h> |
| 1161 | dnl int main() | 1252 | dnl int main() |
| 1162 | dnl { | 1253 | dnl { |
| 1163 | dnl static char buf[8] = "DEADBEEF"; | 1254 | dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; |
| 1164 | dnl snprintf (buf, 0, "%d", 12345); | 1255 | dnl snprintf (buf, 0, "%d", 12345); |
| 1165 | dnl return buf[0] != 'D'; | 1256 | dnl return buf[0] != 'D'; |
| 1166 | dnl } | 1257 | dnl } |
| @@ -1181,7 +1272,7 @@ dnl return ret; | |||
| 1181 | dnl } | 1272 | dnl } |
| 1182 | dnl int main() | 1273 | dnl int main() |
| 1183 | dnl { | 1274 | dnl { |
| 1184 | dnl static char buf[8] = "DEADBEEF"; | 1275 | dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; |
| 1185 | dnl my_snprintf (buf, 0, "%d", 12345); | 1276 | dnl my_snprintf (buf, 0, "%d", 12345); |
| 1186 | dnl return buf[0] != 'D'; | 1277 | dnl return buf[0] != 'D'; |
| 1187 | dnl } | 1278 | dnl } |
| @@ -1209,7 +1300,7 @@ static int my_snprintf (char *buf, int size, const char *format, ...) | |||
| 1209 | } | 1300 | } |
| 1210 | int main() | 1301 | int 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 | |||
| 1261 | dnl 5 = gl_PRINTF_DIRECTIVE_A | 1352 | dnl 5 = gl_PRINTF_DIRECTIVE_A |
| 1262 | dnl 6 = gl_PRINTF_DIRECTIVE_F | 1353 | dnl 6 = gl_PRINTF_DIRECTIVE_F |
| 1263 | dnl 7 = gl_PRINTF_DIRECTIVE_N | 1354 | dnl 7 = gl_PRINTF_DIRECTIVE_N |
| 1264 | dnl 8 = gl_PRINTF_POSITIONS | 1355 | dnl 8 = gl_PRINTF_DIRECTIVE_LS |
| 1265 | dnl 9 = gl_PRINTF_FLAG_GROUPING | 1356 | dnl 9 = gl_PRINTF_POSITIONS |
| 1266 | dnl 10 = gl_PRINTF_FLAG_LEFTADJUST | 1357 | dnl 10 = gl_PRINTF_FLAG_GROUPING |
| 1267 | dnl 11 = gl_PRINTF_FLAG_ZERO | 1358 | dnl 11 = gl_PRINTF_FLAG_LEFTADJUST |
| 1268 | dnl 12 = gl_PRINTF_PRECISION | 1359 | dnl 12 = gl_PRINTF_FLAG_ZERO |
| 1269 | dnl 13 = gl_PRINTF_ENOMEM | 1360 | dnl 13 = gl_PRINTF_PRECISION |
| 1270 | dnl 14 = gl_SNPRINTF_PRESENCE | 1361 | dnl 14 = gl_PRINTF_ENOMEM |
| 1271 | dnl 15 = gl_SNPRINTF_TRUNCATION_C99 | 1362 | dnl 15 = gl_SNPRINTF_PRESENCE |
| 1272 | dnl 16 = gl_SNPRINTF_RETVAL_C99 | 1363 | dnl 16 = gl_SNPRINTF_TRUNCATION_C99 |
| 1273 | dnl 17 = gl_SNPRINTF_DIRECTIVE_N | 1364 | dnl 17 = gl_SNPRINTF_RETVAL_C99 |
| 1274 | dnl 18 = gl_SNPRINTF_SIZE1 | 1365 | dnl 18 = gl_SNPRINTF_DIRECTIVE_N |
| 1275 | dnl 19 = gl_VSNPRINTF_ZEROSIZE_C99 | 1366 | dnl 19 = gl_SNPRINTF_SIZE1 |
| 1367 | dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99 | ||
| 1276 | dnl | 1368 | dnl |
| 1277 | dnl 1 = checking whether printf supports size specifiers as in C99... | 1369 | dnl 1 = checking whether printf supports size specifiers as in C99... |
| 1278 | dnl 2 = checking whether printf supports 'long double' arguments... | 1370 | dnl 2 = checking whether printf supports 'long double' arguments... |
| @@ -1281,42 +1373,44 @@ dnl 4 = checking whether printf supports infinite 'long double' arguments... | |||
| 1281 | dnl 5 = checking whether printf supports the 'a' and 'A' directives... | 1373 | dnl 5 = checking whether printf supports the 'a' and 'A' directives... |
| 1282 | dnl 6 = checking whether printf supports the 'F' directive... | 1374 | dnl 6 = checking whether printf supports the 'F' directive... |
| 1283 | dnl 7 = checking whether printf supports the 'n' directive... | 1375 | dnl 7 = checking whether printf supports the 'n' directive... |
| 1284 | dnl 8 = checking whether printf supports POSIX/XSI format strings with positions... | 1376 | dnl 8 = checking whether printf supports the 'ls' directive... |
| 1285 | dnl 9 = checking whether printf supports the grouping flag... | 1377 | dnl 9 = checking whether printf supports POSIX/XSI format strings with positions... |
| 1286 | dnl 10 = checking whether printf supports the left-adjust flag correctly... | 1378 | dnl 10 = checking whether printf supports the grouping flag... |
| 1287 | dnl 11 = checking whether printf supports the zero flag correctly... | 1379 | dnl 11 = checking whether printf supports the left-adjust flag correctly... |
| 1288 | dnl 12 = checking whether printf supports large precisions... | 1380 | dnl 12 = checking whether printf supports the zero flag correctly... |
| 1289 | dnl 13 = checking whether printf survives out-of-memory conditions... | 1381 | dnl 13 = checking whether printf supports large precisions... |
| 1290 | dnl 14 = checking for snprintf... | 1382 | dnl 14 = checking whether printf survives out-of-memory conditions... |
| 1291 | dnl 15 = checking whether snprintf truncates the result as in C99... | 1383 | dnl 15 = checking for snprintf... |
| 1292 | dnl 16 = checking whether snprintf returns a byte count as in C99... | 1384 | dnl 16 = checking whether snprintf truncates the result as in C99... |
| 1293 | dnl 17 = checking whether snprintf fully supports the 'n' directive... | 1385 | dnl 17 = checking whether snprintf returns a byte count as in C99... |
| 1294 | dnl 18 = checking whether snprintf respects a size of 1... | 1386 | dnl 18 = checking whether snprintf fully supports the 'n' directive... |
| 1295 | dnl 19 = checking whether vsnprintf respects a zero size as in C99... | 1387 | dnl 19 = checking whether snprintf respects a size of 1... |
| 1388 | dnl 20 = checking whether vsnprintf respects a zero size as in C99... | ||
| 1296 | dnl | 1389 | dnl |
| 1297 | dnl . = yes, # = no. | 1390 | dnl . = yes, # = no. |
| 1298 | dnl | 1391 | dnl |
| 1299 | dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1392 | dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
| 1300 | dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . | 1393 | dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . . |
| 1301 | dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . | 1394 | dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . . |
| 1302 | dnl FreeBSD 5.4, 6.1 . . . . # . . . . . # . # . . . . . . | 1395 | dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . . |
| 1303 | dnl MacOS X 10.3.9 . . . . # . . . . . # . # . . . . . . | 1396 | dnl MacOS X 10.3.9 . . . . # . . . . . . # . # . . . . . . |
| 1304 | dnl OpenBSD 3.9, 4.0 . . # # # # . . # . # . # . . . . . . | 1397 | dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . . |
| 1305 | dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . ? # ? ? . . . . . . | 1398 | dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . |
| 1306 | dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . . # ? # ? ? . . . . . . | 1399 | dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . |
| 1307 | dnl Solaris 10 . . # # # . . . . . # . . . . . . . . | 1400 | dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . |
| 1308 | dnl Solaris 2.6 ... 9 # . # # # # . . . . # . . . . . . . . | 1401 | dnl Solaris 10 . . # # # . . # . . . # . . . . . . . . |
| 1309 | dnl Solaris 2.5.1 # . # # # # . . . . # . . # # # # # # | 1402 | dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . . . . . |
| 1310 | dnl AIX 5.2 . . # # # . . . . . # . . . . . . . . | 1403 | dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # |
| 1311 | dnl AIX 4.3.2, 5.1 # . # # # # . . . . # . . . . . . . . | 1404 | dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . . |
| 1312 | dnl HP-UX 11.31 . . . . # . . . . . # . . . . # # . . | 1405 | dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . . . . . |
| 1313 | dnl HP-UX 11.{00,11,23} # . . . # # . . . . # . . . . # # . # | 1406 | dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . . |
| 1314 | dnl HP-UX 10.20 # . . . # # . . . # # . . . . # # ? # | 1407 | dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . # |
| 1315 | dnl IRIX 6.5 # . # # # # . . . . # . . . . # . . . | 1408 | dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? # |
| 1316 | dnl OSF/1 5.1 # . # # # # . . . . # . . . . # . . # | 1409 | dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . . |
| 1317 | dnl OSF/1 4.0d # . # # # # . . . . # . . # # # # # # | 1410 | dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . # |
| 1318 | dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? ? ? ? . . . ? ? ? | 1411 | dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # # |
| 1319 | dnl NetBSD 3.0 . . . . # # . # # ? # . # . . . . . . | 1412 | dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ? |
| 1320 | dnl Haiku . . . # # # . . . . . . ? . . . . . . | 1413 | dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . . |
| 1321 | dnl BeOS # # . # # # . # . ? . # ? . . . . . . | 1414 | dnl Haiku . . . # # # . # . . . . . ? . . . . . . |
| 1322 | dnl mingw # # # # # # . # # . # # ? . # # # . . | 1415 | dnl BeOS # # . # # # . ? # . ? . # ? . . . . . . |
| 1416 | dnl mingw # # # # # # . . # # . # # ? . # # # . . | ||
