1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
|
# printf.m4
# serial 94
dnl Copyright (C) 2003, 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
dnl 'L' size specifiers. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_sizes_c99.
AC_DEFUN([gl_PRINTF_SIZES_C99],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gl_AC_HEADER_STDINT_H])
AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
[gl_cv_func_printf_sizes_c99],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#if HAVE_STDINT_H_WITH_UINTMAX
# include <stdint.h>
#endif
#if HAVE_INTTYPES_H_WITH_UINTMAX
# include <inttypes.h>
#endif
static char buf[100];
int main ()
{
int result = 0;
#if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
buf[0] = '\0';
if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
|| strcmp (buf, "12345671 33") != 0)
result |= 1;
#else
result |= 1;
#endif
buf[0] = '\0';
if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
|| strcmp (buf, "12345672 33") != 0)
result |= 2;
buf[0] = '\0';
if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
|| strcmp (buf, "12345673 33") != 0)
result |= 4;
buf[0] = '\0';
if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
|| strcmp (buf, "1.5 33") != 0)
result |= 8;
return result;
}]])],
[gl_cv_func_printf_sizes_c99=yes],
[gl_cv_func_printf_sizes_c99=no],
[
case "$host_os" in
changequote(,)dnl
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on FreeBSD >= 5.
freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
midnightbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on OpenBSD >= 3.9.
openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
gl_cv_func_printf_sizes_c99="guessing no";;
openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on Solaris >= 2.10.
solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_printf_sizes_c99="guessing no";;
netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
# Guess yes on Android.
linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
changequote([,])dnl
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_printf_sizes_c99="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_printf_sizes_c99="guessing yes"],
[gl_cv_func_printf_sizes_c99="guessing no"])
;;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the 'w8', 'w16',
dnl 'w32', 'w64', 'wf8', 'wf16', 'wf32', 'wf64' size specifiers. (ISO C23)
dnl Result is gl_cv_func_printf_sizes_c23.
AC_DEFUN([gl_PRINTF_SIZES_C23],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gl_AC_HEADER_STDINT_H])
AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports size specifiers as in C23],
[gl_cv_func_printf_sizes_c23],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#if HAVE_STDINT_H_WITH_UINTMAX
# include <stdint.h>
#endif
#if HAVE_INTTYPES_H_WITH_UINTMAX
# include <inttypes.h>
#endif
static char buf[100];
int main ()
{
int result = 0;
buf[0] = '\0';
if (sprintf (buf, "%w8u %d", (uint8_t) 123, 33, 44, 55) < 0
|| strcmp (buf, "123 33") != 0)
result |= 1;
buf[0] = '\0';
if (sprintf (buf, "%wf8u %d", (uint_fast8_t) 123, 33, 44, 55) < 0
|| strcmp (buf, "123 33") != 0)
result |= 1;
buf[0] = '\0';
if (sprintf (buf, "%w16u %d", (uint16_t) 12345, 33, 44, 55) < 0
|| strcmp (buf, "12345 33") != 0)
result |= 2;
buf[0] = '\0';
if (sprintf (buf, "%wf16u %d", (uint_fast16_t) 12345, 33, 44, 55) < 0
|| strcmp (buf, "12345 33") != 0)
result |= 2;
buf[0] = '\0';
if (sprintf (buf, "%w32u %d", (uint32_t) 12345671, 33, 44, 55) < 0
|| strcmp (buf, "12345671 33") != 0)
result |= 4;
buf[0] = '\0';
if (sprintf (buf, "%wf32u %d", (uint_fast32_t) 12345671, 33, 44, 55) < 0
|| strcmp (buf, "12345671 33") != 0)
result |= 4;
#if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
buf[0] = '\0';
if (sprintf (buf, "%w64u %d", (uint64_t) 12345671, 33, 44, 55) < 0
|| strcmp (buf, "12345671 33") != 0)
result |= 8;
buf[0] = '\0';
if (sprintf (buf, "%wf64u %d", (uint_fast64_t) 12345671, 33, 44, 55) < 0
|| strcmp (buf, "12345671 33") != 0)
result |= 8;
#else
result |= 8;
#endif
return result;
}]])],
[gl_cv_func_printf_sizes_c23=yes],
[gl_cv_func_printf_sizes_c23=no],
[
case "$host_os" in
# Guess no on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_sizes_c23="guessing no";;
# Guess no on musl systems.
*-musl* | midipix*) gl_cv_func_printf_sizes_c23="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_sizes_c23="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_sizes_c23="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_sizes_c23="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports 'long double'
dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_long_double.
AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports 'long double' arguments],
[gl_cv_func_printf_long_double],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[10000];
int main ()
{
int result = 0;
buf[0] = '\0';
if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
|| strcmp (buf, "1.750000 33") != 0)
result |= 1;
buf[0] = '\0';
if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
|| strcmp (buf, "1.750000e+00 33") != 0)
result |= 2;
buf[0] = '\0';
if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
|| strcmp (buf, "1.75 33") != 0)
result |= 4;
return result;
}]])],
[gl_cv_func_printf_long_double=yes],
[gl_cv_func_printf_long_double=no],
[case "$host_os" in
# Guess no on BeOS.
beos*) gl_cv_func_printf_long_double="guessing no";;
# Guess yes on Android.
linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_printf_long_double="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_printf_long_double="guessing yes"],
[gl_cv_func_printf_long_double="guessing no"])
;;
*) gl_cv_func_printf_long_double="guessing yes";;
esac
])
])
])
dnl Test whether the *printf family of functions supports infinite and NaN
dnl 'double' arguments and negative zero arguments in the %f, %e, %g
dnl directives. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_infinite.
AC_DEFUN([gl_PRINTF_INFINITE],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
[gl_cv_func_printf_infinite],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static int
strisnan (const char *string, size_t start_index, size_t end_index)
{
if (start_index < end_index)
{
if (string[start_index] == '-')
start_index++;
if (start_index + 3 <= end_index
&& memcmp (string + start_index, "nan", 3) == 0)
{
start_index += 3;
if (start_index == end_index
|| (string[start_index] == '(' && string[end_index - 1] == ')'))
return 1;
}
}
return 0;
}
static int
have_minus_zero ()
{
static double plus_zero = 0.0;
double minus_zero = - plus_zero;
return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
}
static char buf[10000];
static double zero = 0.0;
int main ()
{
int result = 0;
if (sprintf (buf, "%f", 1.0 / zero) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%f", -1.0 / zero) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%f", zero / zero) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%e", 1.0 / zero) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 4;
if (sprintf (buf, "%e", -1.0 / zero) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 4;
if (sprintf (buf, "%e", zero / zero) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 8;
if (sprintf (buf, "%g", 1.0 / zero) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 16;
if (sprintf (buf, "%g", -1.0 / zero) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 16;
if (sprintf (buf, "%g", zero / zero) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 32;
/* This test fails on HP-UX 10.20. */
if (have_minus_zero ())
if (sprintf (buf, "%g", - zero) < 0
|| strcmp (buf, "-0") != 0)
result |= 64;
return result;
}]])],
[gl_cv_func_printf_infinite=yes],
[gl_cv_func_printf_infinite=no],
[
case "$host_os" in
changequote(,)dnl
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on FreeBSD >= 6.
freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
midnightbsd*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
darwin*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on HP-UX >= 11.
hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
hpux*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_printf_infinite="guessing no";;
netbsd*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on OpenBSD >= 6.0.
openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
openbsd*) gl_cv_func_printf_infinite="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_printf_infinite="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_infinite="guessing no";;
changequote([,])dnl
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_printf_infinite="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_printf_infinite="guessing yes"],
[gl_cv_func_printf_infinite="guessing no"])
;;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports infinite and NaN
dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_infinite_long_double.
AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
[
AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gl_BIGENDIAN])
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
dnl The user can set or unset the variable gl_printf_safe to indicate
dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
if test -n "$gl_printf_safe"; then
AC_DEFINE([CHECK_PRINTF_SAFE], [1],
[Define if you wish *printf() functions that have a safe handling of
non-IEEE-754 'long double' values.])
fi
case "$gl_cv_func_printf_long_double" in
*yes)
AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
[gl_cv_func_printf_infinite_long_double],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
]GL_NOCRASH[
#include <float.h>
#include <stdio.h>
#include <string.h>
static int
strisnan (const char *string, size_t start_index, size_t end_index)
{
if (start_index < end_index)
{
if (string[start_index] == '-')
start_index++;
if (start_index + 3 <= end_index
&& memcmp (string + start_index, "nan", 3) == 0)
{
start_index += 3;
if (start_index == end_index
|| (string[start_index] == '(' && string[end_index - 1] == ')'))
return 1;
}
}
return 0;
}
static char buf[10000];
static long double zeroL = 0.0L;
int main ()
{
int result = 0;
nocrash_init();
if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Le", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
#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
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
# define LDBL80_WORDS(exponent,manthi,mantlo) \
{ ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
(unsigned int) (mantlo) << 16 \
}
# else
# define LDBL80_WORDS(exponent,manthi,mantlo) \
{ mantlo, manthi, exponent }
# endif
{ /* Quiet NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
}
{
/* Signalling NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
}
{ /* Pseudo-NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) <= 0)
result |= 4;
if (sprintf (buf, "%Le", x.value) <= 0)
result |= 4;
if (sprintf (buf, "%Lg", x.value) <= 0)
result |= 4;
}
{ /* Pseudo-Infinity. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) <= 0)
result |= 8;
if (sprintf (buf, "%Le", x.value) <= 0)
result |= 8;
if (sprintf (buf, "%Lg", x.value) <= 0)
result |= 8;
}
{ /* Pseudo-Zero. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) <= 0)
result |= 16;
if (sprintf (buf, "%Le", x.value) <= 0)
result |= 16;
if (sprintf (buf, "%Lg", x.value) <= 0)
result |= 16;
}
{ /* Unnormalized number. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) <= 0)
result |= 32;
if (sprintf (buf, "%Le", x.value) <= 0)
result |= 32;
if (sprintf (buf, "%Lg", x.value) <= 0)
result |= 32;
}
{ /* Pseudo-Denormal. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) <= 0)
result |= 64;
if (sprintf (buf, "%Le", x.value) <= 0)
result |= 64;
if (sprintf (buf, "%Lg", x.value) <= 0)
result |= 64;
}
#endif
return result;
}]])],
[gl_cv_func_printf_infinite_long_double=yes],
[gl_cv_func_printf_infinite_long_double=no],
[case "$host_cpu" in
# Guess no on ia64, x86_64, i386.
ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
*)
case "$host_os" in
changequote(,)dnl
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_infinite_long_double="guessing yes";;
# Guess yes on FreeBSD >= 6.
freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
midnightbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
# Guess yes on HP-UX >= 11.
hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
# Guess yes on OpenBSD >= 6.0.
openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
changequote([,])dnl
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_printf_infinite_long_double="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_printf_infinite_long_double="guessing yes"],
[gl_cv_func_printf_infinite_long_double="guessing no"])
;;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
esac
;;
esac
])
])
;;
*)
gl_cv_func_printf_infinite_long_double="irrelevant"
;;
esac
])
dnl Test whether the *printf family of functions supports the 'a' and 'A'
dnl conversion specifier for hexadecimal output of floating-point numbers.
dnl (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_directive_a.
AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
[gl_cv_func_printf_directive_a],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
static double zero = 0.0;
int main ()
{
int result = 0;
/* This fails on FreeBSD 5.2.1, Solaris 11.4. */
if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
|| (strcmp (buf, "0x1.922p+1 33") != 0
&& strcmp (buf, "0x3.244p+0 33") != 0
&& strcmp (buf, "0x6.488p-1 33") != 0
&& strcmp (buf, "0xc.91p-2 33") != 0))
result |= 1;
if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
|| (strcmp (buf, "-0X1.922P+1 33") != 0
&& strcmp (buf, "-0X3.244P+0 33") != 0
&& strcmp (buf, "-0X6.488P-1 33") != 0
&& strcmp (buf, "-0XC.91P-2 33") != 0))
result |= 1;
/* This catches a Mac OS X 10.5, FreeBSD 6.4, NetBSD 10.0 bug:
it doesn't round. */
if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
|| (strcmp (buf, "0x1.83p+0 33") != 0
&& strcmp (buf, "0x3.05p-1 33") != 0
&& strcmp (buf, "0x6.0ap-2 33") != 0
&& strcmp (buf, "0xc.14p-3 33") != 0))
result |= 2;
/* This catches a macOS 14 (Darwin 23), FreeBSD 14.0, OpenBSD 7.5, AIX 7.3,
Solaris 11.4 bug: it doesn't round. */
if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
|| (strcmp (buf, "0x2p+0 33") != 0
&& strcmp (buf, "0x3p-1 33") != 0
&& strcmp (buf, "0x6p-2 33") != 0
&& strcmp (buf, "0xcp-3 33") != 0))
result |= 4;
/* This catches a Mac OS X 10.5, FreeBSD 6.4 bug. See
<https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
|| buf[0] == '0')
result |= 8;
/* This catches a Mac OS X 10.3.9 (Darwin 7.9), FreeBSD 6.4 bug. */
if (sprintf (buf, "%.1a", 1.999) < 0
|| (strcmp (buf, "0x1.0p+1") != 0
&& strcmp (buf, "0x2.0p+0") != 0
&& strcmp (buf, "0x4.0p-1") != 0
&& strcmp (buf, "0x8.0p-2") != 0))
result |= 16;
/* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>
and a FreeBSD 6.4, NetBSD 10.0 bug. */
if (sprintf (buf, "%.1La", 1.999L) < 0
|| (strcmp (buf, "0x1.0p+1") != 0
&& strcmp (buf, "0x2.0p+0") != 0
&& strcmp (buf, "0x4.0p-1") != 0
&& strcmp (buf, "0x8.0p-2") != 0))
result |= 32;
return result;
}]])],
[gl_cv_func_printf_directive_a=yes],
[gl_cv_func_printf_directive_a=no],
[
case "$host_os" in
# Guess yes on glibc >= 2.5 systems.
*-gnu* | gnu*)
AC_EGREP_CPP([BZ2908], [
#include <features.h>
#ifdef __GNU_LIBRARY__
#if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
BZ2908
#endif
#endif
],
[gl_cv_func_printf_directive_a="guessing yes"],
[gl_cv_func_printf_directive_a="guessing no"])
;;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_directive_a="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_directive_a="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the 'b' conversion
dnl specifier for binary output of integers.
dnl (ISO C23)
dnl Result is gl_cv_func_printf_directive_b.
AC_DEFUN([gl_PRINTF_DIRECTIVE_B],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'b' directive],
[gl_cv_func_printf_directive_b],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
int main ()
{
int result = 0;
if (sprintf (buf, "%b %d", 12345, 33, 44, 55) < 0
|| strcmp (buf, "11000000111001 33") != 0)
result |= 1;
return result;
}]])],
[gl_cv_func_printf_directive_b=yes],
[gl_cv_func_printf_directive_b=no],
[
case "$host_os" in
# Guess yes on glibc >= 2.35 systems.
*-gnu* | gnu*)
AC_EGREP_CPP([Lucky], [
#include <features.h>
#ifdef __GNU_LIBRARY__
#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
Lucky user
#endif
#endif
],
[gl_cv_func_printf_directive_uppercase_b="guessing yes"],
[gl_cv_func_printf_directive_uppercase_b="guessing no"])
;;
# Guess no on musl systems.
*-musl* | midipix*) gl_cv_func_printf_directive_b="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_b="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_directive_b="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_directive_b="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the 'B' conversion
dnl specifier for binary output of integers.
dnl (GNU, encouraged by ISO C23 § 7.23.6.1)
dnl Result is gl_cv_func_printf_directive_uppercase_b.
AC_DEFUN([gl_PRINTF_DIRECTIVE_UPPERCASE_B],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'B' directive],
[gl_cv_func_printf_directive_uppercase_b],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
int main ()
{
int result = 0;
if (sprintf (buf, "%#B %d", 12345, 33, 44, 55) < 0
|| strcmp (buf, "0B11000000111001 33") != 0)
result |= 1;
return result;
}]])],
[gl_cv_func_printf_directive_uppercase_b=yes],
[gl_cv_func_printf_directive_uppercase_b=no],
[
case "$host_os" in
# Guess yes on glibc >= 2.35 systems.
*-gnu* | gnu*)
AC_EGREP_CPP([Lucky], [
#include <features.h>
#ifdef __GNU_LIBRARY__
#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
Lucky user
#endif
#endif
],
[gl_cv_func_printf_directive_uppercase_b="guessing yes"],
[gl_cv_func_printf_directive_uppercase_b="guessing no"])
;;
# Guess no on musl systems.
*-musl* | midipix*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_directive_uppercase_b="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the %F format
dnl directive. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_directive_f.
AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'F' directive],
[gl_cv_func_printf_directive_f],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
static double zero = 0.0;
int main ()
{
int result = 0;
if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
|| strcmp (buf, "1234567.000000 33") != 0)
result |= 1;
if (sprintf (buf, "%F", 1.0 / zero) < 0
|| (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
result |= 2;
/* This catches a Cygwin 1.5.x bug. */
if (sprintf (buf, "%.F", 1234.0) < 0
|| strcmp (buf, "1234") != 0)
result |= 4;
return result;
}]])],
[gl_cv_func_printf_directive_f=yes],
[gl_cv_func_printf_directive_f=no],
[
case "$host_os" in
changequote(,)dnl
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_directive_f="guessing yes";;
# Guess yes on FreeBSD >= 6.
freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
midnightbsd*) gl_cv_func_printf_directive_f="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
darwin*) gl_cv_func_printf_directive_f="guessing yes";;
# Guess yes on OpenBSD >= 6.0.
openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
openbsd*) gl_cv_func_printf_directive_f="guessing yes";;
# Guess yes on Solaris >= 2.10.
solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
solaris*) gl_cv_func_printf_directive_f="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
changequote([,])dnl
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_printf_directive_f="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_printf_directive_f="guessing yes"],
[gl_cv_func_printf_directive_f="guessing no"])
;;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the %n format
dnl directive. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_printf_directive_n.
AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'n' directive],
[gl_cv_func_printf_directive_n],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <crtdbg.h>
#include <inttypes.h>
/* See page about "Parameter Validation" on msdn.microsoft.com.
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */
static void cdecl
invalid_parameter_handler (const wchar_t *expression,
const wchar_t *function,
const wchar_t *file, unsigned int line,
uintptr_t dummy)
{
exit (1);
}
#endif
static void
abort_handler (int sig)
{
(void) sig;
_exit (1);
}
static char fmtstring[10];
static char buf[100];
int main ()
{
int count = -1;
#ifdef _MSC_VER
_set_invalid_parameter_handler (invalid_parameter_handler);
/* Also avoid an Abort/Retry/Ignore dialog in debug builds.
<https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode> */
_CrtSetReportMode (_CRT_ASSERT, 0);
#endif
signal (SIGABRT, abort_handler);
/* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
support %n in format strings in read-only memory but not in writable
memory. */
strcpy (fmtstring, "%d %n");
if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
|| strcmp (buf, "123 ") != 0
|| count != 4)
return 1;
return 0;
}]])],
[gl_cv_func_printf_directive_n=yes],
[gl_cv_func_printf_directive_n=no],
[case "$host_os" in
# Guess no on glibc when _FORTIFY_SOURCE >= 2.
*-gnu* | gnu*) AC_COMPILE_IFELSE(
[AC_LANG_SOURCE(
[[#if _FORTIFY_SOURCE >= 2
error fail
#endif
]])],
[gl_cv_func_printf_directive_n="guessing yes"],
[gl_cv_func_printf_directive_n="guessing no"])
;;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_directive_n="guessing no";;
*) gl_cv_func_printf_directive_n="guessing yes";;
esac
])
])
])
dnl Test whether the *printf family of functions supports the %ls format
dnl directive and in particular, when a precision is specified, whether
dnl the functions stop converting the wide string argument when the number
dnl of bytes that have been produced by this conversion equals or exceeds
dnl the precision.
dnl Result is gl_cv_func_printf_directive_ls.
AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'ls' directive],
[gl_cv_func_printf_directive_ls],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <wchar.h>
#include <string.h>
int main ()
{
int result = 0;
char buf[100];
/* Test whether %ls works at all.
This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
Cygwin 1.5. */
{
static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
buf[0] = '\0';
if (sprintf (buf, "%ls", wstring) < 0
|| strcmp (buf, "abc") != 0)
result |= 1;
}
/* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
assertion failure inside libc), but not on OpenBSD 4.0. */
{
static const wchar_t wstring[] = { 'a', 0 };
buf[0] = '\0';
if (sprintf (buf, "%ls", wstring) < 0
|| strcmp (buf, "a") != 0)
result |= 2;
}
/* Test whether precisions in %ls are supported as specified in ISO C 99
section 7.19.6.1:
"If a precision is specified, no more than that many bytes are written
(including shift sequences, if any), and the array shall contain a
null wide character if, to equal the multibyte character sequence
length given by the precision, the function would need to access a
wide character one past the end of the array."
This test fails on Solaris 10. */
{
static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
buf[0] = '\0';
if (sprintf (buf, "%.2ls", wstring) < 0
|| strcmp (buf, "ab") != 0)
result |= 8;
}
return result;
}]])],
[gl_cv_func_printf_directive_ls=yes],
[gl_cv_func_printf_directive_ls=no],
[
changequote(,)dnl
case "$host_os" in
# Guess yes on OpenBSD >= 6.0.
openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";;
openbsd*) gl_cv_func_printf_directive_ls="guessing yes";;
irix*) gl_cv_func_printf_directive_ls="guessing no";;
solaris*) gl_cv_func_printf_directive_ls="guessing no";;
cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
# Guess yes on native Windows.
mingw* | windows*) gl_cv_func_printf_directive_ls="guessing yes";;
*) gl_cv_func_printf_directive_ls="guessing yes";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports the %lc format
dnl directive and in particular, when the argument is a null wide character,
dnl whether the functions produce a NUL byte, as specified in ISO C 23
dnl after the issue GB-141 was fixed.
dnl Result is gl_cv_func_printf_directive_lc.
AC_DEFUN([gl_PRINTF_DIRECTIVE_LC],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the 'lc' directive correctly],
[gl_cv_func_printf_directive_lc],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <wchar.h>
#include <string.h>
int main ()
{
int result = 0;
char buf[100];
/* This test fails on musl libc 1.2.4. */
{
buf[0] = '\0';
if (sprintf (buf, "%lc%lc%lc", (wint_t) 'a', (wint_t) 0, (wint_t) 'z') < 0
|| memcmp (buf, "a\0z", 4) != 0)
result |= 1;
}
return result;
}]])],
[gl_cv_func_printf_directive_lc=yes],
[gl_cv_func_printf_directive_lc=no],
[
changequote(,)dnl
case "$host_os" in
# Guess no on musl libc.
*-musl* | midipix*) gl_cv_func_printf_directive_lc="guessing no";;
# Guess yes otherwise.
*) gl_cv_func_printf_directive_lc="guessing yes";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports POSIX/XSI format
dnl strings with positions. (POSIX:2001)
dnl Result is gl_cv_func_printf_positions.
AC_DEFUN_ONCE([gl_PRINTF_POSITIONS],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
[gl_cv_func_printf_positions],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
/* The string "%2$d %1$d", with dollar characters protected from the shell's
dollar expansion (possibly an autoconf bug). */
static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
static char buf[100];
int main ()
{
sprintf (buf, format, 33, 55);
return (strcmp (buf, "55 33") != 0);
}]])],
[gl_cv_func_printf_positions=yes],
[gl_cv_func_printf_positions=no],
[
changequote(,)dnl
case "$host_os" in
netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
gl_cv_func_printf_positions="guessing no";;
beos*)
gl_cv_func_printf_positions="guessing no";;
# Guess yes on Android.
linux*-android*)
gl_cv_func_printf_positions="guessing yes";;
# Guess no on native Windows.
mingw* | windows* | pw*)
gl_cv_func_printf_positions="guessing no";;
*)
gl_cv_func_printf_positions="guessing yes";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports POSIX/XSI format
dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
dnl Result is gl_cv_func_printf_flag_grouping.
AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the grouping flag],
[gl_cv_func_printf_flag_grouping],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
int main ()
{
if (sprintf (buf, "%'d %d", 1234567, 99) < 0
|| buf[strlen (buf) - 1] != '9')
return 1;
return 0;
}]])],
[gl_cv_func_printf_flag_grouping=yes],
[gl_cv_func_printf_flag_grouping=no],
[
changequote(,)dnl
case "$host_os" in
cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
# Guess no on native Windows.
mingw* | windows* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
*) gl_cv_func_printf_flag_grouping="guessing yes";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports the - flag correctly.
dnl (ISO C99.) See
dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
dnl Result is gl_cv_func_printf_flag_leftadjust.
AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
[gl_cv_func_printf_flag_leftadjust],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
int main ()
{
/* Check that a '-' flag is not annihilated by a negative width. */
if (sprintf (buf, "a%-*sc", -3, "b") < 0
|| strcmp (buf, "ab c") != 0)
return 1;
return 0;
}]])],
[gl_cv_func_printf_flag_leftadjust=yes],
[gl_cv_func_printf_flag_leftadjust=no],
[
changequote(,)dnl
case "$host_os" in
# Guess yes on HP-UX 11.
hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
# Guess no on HP-UX 10 and older.
hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
# Guess yes on Android.
linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
# Guess yes on native Windows.
mingw* | windows*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
# Guess yes otherwise.
*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports padding of non-finite
dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
dnl Result is gl_cv_func_printf_flag_zero.
AC_DEFUN([gl_PRINTF_FLAG_ZERO],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the zero flag correctly],
[gl_cv_func_printf_flag_zero],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[100];
static double zero = 0.0;
int main ()
{
if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
|| (strcmp (buf, " inf") != 0
&& strcmp (buf, " infinity") != 0))
return 1;
return 0;
}]])],
[gl_cv_func_printf_flag_zero=yes],
[gl_cv_func_printf_flag_zero=no],
[
changequote(,)dnl
case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_printf_flag_zero="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_printf_flag_zero="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_printf_flag_zero="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports the # flag with a
dnl zero precision and a zero value in the 'x' and 'X' directives correctly.
dnl ISO C and POSIX specify that for the 'd', 'i', 'b', 'o', 'u', 'x', 'X'
dnl directives: "The result of converting a zero value with a precision of
dnl zero is no characters." But on Mac OS X 10.5, for the 'x', 'X' directives,
dnl when a # flag is present, the output is "0" instead of "".
dnl Result is gl_cv_func_printf_flag_alt_precision_zero.
AC_DEFUN([gl_PRINTF_FLAG_ALT_PRECISION_ZERO],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports the alternative flag with a zero precision],
[gl_cv_func_printf_flag_alt_precision_zero],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
static char buf[10];
int main ()
{
int result = 0;
if (sprintf (buf, "%#.0x %d", 0, 33, 44) > 0 + 3)
result |= 1;
return result;
}]])],
[gl_cv_func_printf_flag_alt_precision_zero=yes],
[gl_cv_func_printf_flag_alt_precision_zero=no],
[
changequote(,)dnl
case "$host_os" in
# Guess no only on macOS 10..12 systems.
darwin[0-9] | darwin[0-9].* | \
darwin1[0-9] | darwin1[0-9].* | \
darwin2[0-1] | darwin2[0-1].*)
gl_cv_func_printf_flag_alt_precision_zero="guessing no" ;;
darwin*) gl_cv_func_printf_flag_alt_precision_zero="guessing yes" ;;
*) gl_cv_func_printf_flag_alt_precision_zero="guessing yes" ;;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions supports large precisions.
dnl On mingw, precisions larger than 512 are treated like 512, in integer,
dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
dnl precisions larger than 510 in floating-point output yield wrong results.
dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
dnl Result is gl_cv_func_printf_precision.
AC_DEFUN([gl_PRINTF_PRECISION],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf supports large precisions],
[gl_cv_func_printf_precision],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
static char buf[5000];
int main ()
{
int result = 0;
#ifdef __BEOS__
/* On BeOS, this would crash and show a dialog box. Avoid the crash. */
return 1;
#endif
if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
result |= 1;
if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
result |= 2;
if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
|| buf[0] != '1')
result |= 4;
if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
|| buf[0] != '1')
result |= 4;
return result;
}]])],
[gl_cv_func_printf_precision=yes],
[gl_cv_func_printf_precision=no],
[
changequote(,)dnl
case "$host_os" in
# Guess no only on Solaris, native Windows, and BeOS systems.
solaris*) gl_cv_func_printf_precision="guessing no" ;;
mingw* | windows* | pw*) gl_cv_func_printf_precision="guessing no" ;;
beos*) gl_cv_func_printf_precision="guessing no" ;;
# Guess yes on Android.
linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
*) gl_cv_func_printf_precision="guessing yes" ;;
esac
changequote([,])dnl
])
])
])
dnl Test whether the *printf family of functions recovers gracefully in case
dnl of an out-of-memory condition, or whether it crashes the entire program.
dnl Result is gl_cv_func_printf_enomem.
AC_DEFUN([gl_PRINTF_ENOMEM],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gl_MULTIARCH])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
[gl_cv_func_printf_enomem],
[
gl_cv_func_printf_enomem="guessing no"
if test "$cross_compiling" = no; then
if test $APPLE_UNIVERSAL_BUILD = 0; then
AC_LANG_CONFTEST([AC_LANG_SOURCE([[
]GL_NOCRASH[
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
int main()
{
struct rlimit limit;
int ret;
nocrash_init ();
/* Some printf implementations allocate temporary space with malloc. */
/* On BSD systems, malloc() is limited by RLIMIT_DATA. */
#ifdef RLIMIT_DATA
if (getrlimit (RLIMIT_DATA, &limit) < 0)
return 77;
if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
limit.rlim_max = 5000000;
limit.rlim_cur = limit.rlim_max;
if (setrlimit (RLIMIT_DATA, &limit) < 0)
return 77;
#endif
/* On Linux systems, malloc() is limited by RLIMIT_AS. */
#ifdef RLIMIT_AS
if (getrlimit (RLIMIT_AS, &limit) < 0)
return 77;
if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
limit.rlim_max = 5000000;
limit.rlim_cur = limit.rlim_max;
if (setrlimit (RLIMIT_AS, &limit) < 0)
return 77;
#endif
/* Some printf implementations allocate temporary space on the stack. */
#ifdef RLIMIT_STACK
if (getrlimit (RLIMIT_STACK, &limit) < 0)
return 77;
if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
limit.rlim_max = 5000000;
limit.rlim_cur = limit.rlim_max;
if (setrlimit (RLIMIT_STACK, &limit) < 0)
return 77;
#endif
ret = printf ("%.5000000f", 1.0);
return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
}
]])])
if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
(./conftest 2>&AS_MESSAGE_LOG_FD
result=$?
_AS_ECHO_LOG([\$? = $result])
if test $result != 0 && test $result != 77; then result=1; fi
exit $result
) >/dev/null 2>/dev/null
case $? in
0) gl_cv_func_printf_enomem="yes" ;;
77) gl_cv_func_printf_enomem="guessing no" ;;
*) gl_cv_func_printf_enomem="no" ;;
esac
else
gl_cv_func_printf_enomem="guessing no"
fi
rm -fr conftest*
else
dnl A universal build on Apple Mac OS X platforms.
dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
dnl But we need a configuration result that is valid in both modes.
gl_cv_func_printf_enomem="guessing no"
fi
fi
if test "$gl_cv_func_printf_enomem" = "guessing no"; then
changequote(,)dnl
case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on Solaris.
solaris*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on AIX.
aix*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on HP-UX/hppa.
hpux*) case "$host_cpu" in
hppa*) gl_cv_func_printf_enomem="guessing yes";;
*) gl_cv_func_printf_enomem="guessing no";;
esac
;;
# Guess yes on IRIX.
irix*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on OSF/1.
osf*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_printf_enomem="guessing yes";;
# Guess yes on Haiku.
haiku*) gl_cv_func_printf_enomem="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_printf_enomem="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
esac
changequote([,])dnl
fi
])
])
dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
dnl Result is ac_cv_func_snprintf.
AC_DEFUN([gl_SNPRINTF_PRESENCE],
[
AC_CHECK_FUNCS_ONCE([snprintf])
])
dnl Test whether the string produced by the snprintf function is always NUL
dnl terminated. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_snprintf_truncation_c99.
AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_REQUIRE([gl_SNPRINTF_PRESENCE])
AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
[gl_cv_func_snprintf_truncation_c99],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
#if HAVE_SNPRINTF
# define my_snprintf snprintf
#else
# include <stdarg.h>
static int my_snprintf (char *buf, int size, const char *format, ...)
{
va_list args;
int ret;
va_start (args, format);
ret = vsnprintf (buf, size, format, args);
va_end (args);
return ret;
}
#endif
static char buf[100];
int main ()
{
strcpy (buf, "ABCDEF");
my_snprintf (buf, 3, "%d %d", 4567, 89);
if (memcmp (buf, "45\0DEF", 6) != 0)
return 1;
return 0;
}]])],
[gl_cv_func_snprintf_truncation_c99=yes],
[gl_cv_func_snprintf_truncation_c99=no],
[
changequote(,)dnl
case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on FreeBSD >= 5.
freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
midnightbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on OpenBSD >= 3.9.
openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
gl_cv_func_snprintf_truncation_c99="guessing no";;
openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on Solaris >= 2.6.
solaris2.[0-5] | solaris2.[0-5].*)
gl_cv_func_snprintf_truncation_c99="guessing no";;
solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on AIX >= 4.
aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on HP-UX >= 11.
hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on IRIX >= 6.5.
irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on OSF/1 >= 5.
osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_snprintf_truncation_c99="guessing no";;
netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess yes on Android.
linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_snprintf_truncation_c99="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the return value of the snprintf function is the number
dnl of bytes (excluding the terminating NUL) that would have been produced
dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
dnl For example, this test program fails on IRIX 6.5:
dnl ---------------------------------------------------------------------
dnl #include <stdio.h>
dnl int main()
dnl {
dnl static char buf[8];
dnl int retval = snprintf (buf, 3, "%d", 12345);
dnl return retval >= 0 && retval < 3;
dnl }
dnl ---------------------------------------------------------------------
dnl Result is gl_cv_func_snprintf_retval_c99.
AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_REQUIRE([gl_SNPRINTF_PRESENCE])
AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
[gl_cv_func_snprintf_retval_c99],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
#if HAVE_SNPRINTF
# define my_snprintf snprintf
#else
# include <stdarg.h>
static int my_snprintf (char *buf, int size, const char *format, ...)
{
va_list args;
int ret;
va_start (args, format);
ret = vsnprintf (buf, size, format, args);
va_end (args);
return ret;
}
#endif
static char buf[100];
int main ()
{
strcpy (buf, "ABCDEF");
if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
return 1;
if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
return 2;
if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
return 3;
return 0;
}]])],
[gl_cv_func_snprintf_retval_c99=yes],
[gl_cv_func_snprintf_retval_c99=no],
[case "$host_os" in
changequote(,)dnl
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on FreeBSD >= 5.
freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
midnightbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on OpenBSD >= 3.9.
openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
gl_cv_func_snprintf_retval_c99="guessing no";;
openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on Solaris >= 2.10.
solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
# Guess yes on AIX >= 4.
aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_snprintf_retval_c99="guessing no";;
netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
# Guess yes on Android.
linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
changequote([,])dnl
# Guess yes on MSVC, no on mingw.
windows*-msvc*) gl_cv_func_snprintf_retval_c99="guessing yes" ;;
mingw* | windows*) AC_EGREP_CPP([Known], [
#ifdef _MSC_VER
Known
#endif
],
[gl_cv_func_snprintf_retval_c99="guessing yes"],
[gl_cv_func_snprintf_retval_c99="guessing no"])
;;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the snprintf function supports the %n format directive
dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_snprintf_directive_n.
AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_REQUIRE([gl_SNPRINTF_PRESENCE])
AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
[gl_cv_func_snprintf_directive_n],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <signal.h>
#include <stdio.h>
#include <string.h>
#if HAVE_SNPRINTF
# define my_snprintf snprintf
#else
# include <stdarg.h>
static int my_snprintf (char *buf, int size, const char *format, ...)
{
va_list args;
int ret;
va_start (args, format);
ret = vsnprintf (buf, size, format, args);
va_end (args);
return ret;
}
#endif
static void
abort_handler (int sig)
{
(void) sig;
_exit (1);
}
static char fmtstring[10];
static char buf[100];
int main ()
{
int count = -1;
signal (SIGABRT, abort_handler);
/* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
support %n in format strings in read-only memory but not in writable
memory. */
strcpy (fmtstring, "%d %n");
my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
if (count != 6)
return 1;
return 0;
}]])],
[gl_cv_func_snprintf_directive_n=yes],
[gl_cv_func_snprintf_directive_n=no],
[
case "$host_os" in
# Guess no on glibc when _FORTIFY_SOURCE >= 2.
*-gnu* | gnu*) AC_COMPILE_IFELSE(
[AC_LANG_SOURCE(
[[#if _FORTIFY_SOURCE >= 2
error fail
#endif
]])],
[gl_cv_func_snprintf_directive_n="guessing yes"],
[gl_cv_func_snprintf_directive_n="guessing no"])
;;
changequote(,)dnl
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on FreeBSD >= 5.
freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
midnightbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on Solaris >= 2.6.
solaris2.[0-5] | solaris2.[0-5].*)
gl_cv_func_snprintf_directive_n="guessing no";;
solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on AIX >= 4.
aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on IRIX >= 6.5.
irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on OSF/1 >= 5.
osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_snprintf_directive_n="guessing no";;
netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
# Guess no on Android.
linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_snprintf_directive_n="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
changequote([,])dnl
esac
])
])
])
dnl Test whether the snprintf function, when passed a size = 1, writes any
dnl output without bounds in this case, behaving like sprintf. This is the
dnl case on Linux libc5.
dnl Result is gl_cv_func_snprintf_size1.
AC_DEFUN([gl_SNPRINTF_SIZE1],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_REQUIRE([gl_SNPRINTF_PRESENCE])
AC_CACHE_CHECK([whether snprintf respects a size of 1],
[gl_cv_func_snprintf_size1],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#if HAVE_SNPRINTF
# define my_snprintf snprintf
#else
# include <stdarg.h>
static int my_snprintf (char *buf, int size, const char *format, ...)
{
va_list args;
int ret;
va_start (args, format);
ret = vsnprintf (buf, size, format, args);
va_end (args);
return ret;
}
#endif
int main()
{
static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
my_snprintf (buf, 1, "%d", 12345);
return buf[1] != 'E';
}]])],
[gl_cv_func_snprintf_size1=yes],
[gl_cv_func_snprintf_size1=no],
[case "$host_os" in
# Guess yes on Android.
linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
# Guess yes on native Windows.
mingw* | windows*) gl_cv_func_snprintf_size1="guessing yes" ;;
*) gl_cv_func_snprintf_size1="guessing yes" ;;
esac
])
])
])
dnl Test whether the vsnprintf function, when passed a zero size, produces no
dnl output. (ISO C99, POSIX:2001)
dnl For example, snprintf nevertheless writes a NUL byte in this case
dnl on OSF/1 5.1:
dnl ---------------------------------------------------------------------
dnl #include <stdio.h>
dnl int main()
dnl {
dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
dnl snprintf (buf, 0, "%d", 12345);
dnl return buf[0] != 'D';
dnl }
dnl ---------------------------------------------------------------------
dnl And vsnprintf writes any output without bounds in this case, behaving like
dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
dnl ---------------------------------------------------------------------
dnl #include <stdarg.h>
dnl #include <stdio.h>
dnl static int my_snprintf (char *buf, int size, const char *format, ...)
dnl {
dnl va_list args;
dnl int ret;
dnl va_start (args, format);
dnl ret = vsnprintf (buf, size, format, args);
dnl va_end (args);
dnl return ret;
dnl }
dnl int main()
dnl {
dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
dnl my_snprintf (buf, 0, "%d", 12345);
dnl return buf[0] != 'D';
dnl }
dnl ---------------------------------------------------------------------
dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
[gl_cv_func_vsnprintf_zerosize_c99],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdarg.h>
#include <stdio.h>
static int my_snprintf (char *buf, int size, const char *format, ...)
{
va_list args;
int ret;
va_start (args, format);
ret = vsnprintf (buf, size, format, args);
va_end (args);
return ret;
}
int main()
{
static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
my_snprintf (buf, 0, "%d", 12345);
return buf[0] != 'D';
}]])],
[gl_cv_func_vsnprintf_zerosize_c99=yes],
[gl_cv_func_vsnprintf_zerosize_c99=no],
[
changequote(,)dnl
case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on FreeBSD >= 5.
freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
midnightbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on Mac OS X >= 10.3.
darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on Cygwin.
cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on Solaris >= 2.6.
solaris2.[0-5] | solaris2.[0-5].*)
gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on AIX >= 4.
aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on IRIX >= 6.5.
irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on NetBSD >= 3.
netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on BeOS.
beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on Android.
linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# Guess yes on native Windows.
mingw* | windows* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
esac
changequote([,])dnl
])
])
])
dnl Test whether the swprintf function works correctly when it produces output
dnl that contains null wide characters.
dnl Result is gl_cv_func_swprintf_works.
AC_DEFUN([gl_SWPRINTF_WORKS],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CHECK_FUNCS_ONCE([swprintf])
AC_CACHE_CHECK([whether swprintf works],
[gl_cv_func_swprintf_works],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#ifndef __USE_MINGW_ANSI_STDIO
# define __USE_MINGW_ANSI_STDIO 1
#endif
#include <stdio.h>
#include <wchar.h>
int main()
{
int result = 0;
{ /* This test fails on musl libc 1.2.3, FreeBSD, NetBSD, OpenBSD, macOS, AIX. */
wchar_t buf[5] = { 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF };
int ret = swprintf (buf, 4, L"%cz", '\0');
/* Expected result:
ret = 2, buf[0] = 0x0, buf[1] = 0x7a, buf[2] = 0x0, buf[3] = 0xbeef
musl libc 1.2.3:
ret = 2, buf[0] = 0x0, buf[1] = 0x0, buf[2] = 0x0, buf[3] = 0x0
Reported at <https://www.openwall.com/lists/musl/2023/03/22/9>.
FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2:
ret = 2, buf[0] = 0x0, buf[1] = 0xbeef, buf[2] = 0xbeef, buf[3] = 0xbeef
*/
if (ret < 0 || buf[1] != 'z')
result |= 1;
}
{ /* This test fails on mingw. */
wchar_t buf[2];
int ret = swprintf (buf, 2, L"%lc", (wint_t)0);
/* Expected: ret = 1
mingw: ret = 0
*/
if (ret != 1)
result |= 2;
}
return result;
}]])],
[gl_cv_func_swprintf_works=yes],
[gl_cv_func_swprintf_works=no],
[case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_swprintf_works="guessing yes";;
# Guess no on musl systems.
*-musl* | midipix*) gl_cv_func_swprintf_works="guessing no";;
# Guess no on FreeBSD, NetBSD, OpenBSD, macOS, AIX.
freebsd* | midnightbsd* | netbsd* | openbsd* | darwin* | aix*)
gl_cv_func_swprintf_works="guessing no";;
# Guess no on native Windows.
mingw* | windows* | pw*) gl_cv_func_swprintf_works="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_swprintf_works="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *wprintf family of functions supports the 'a' and 'A'
dnl conversion specifier for hexadecimal output of 'long double' numbers.
dnl (ISO C99, POSIX:2001)
dnl Result is gl_cv_func_swprintf_directive_la.
AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LA],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether swprintf supports the 'La' and 'LA' directives],
[gl_cv_func_swprintf_directive_la],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <wchar.h>
static wchar_t buf[100];
int main ()
{
int result = 0;
/* This catches a glibc 2.15, Haiku 2022, NetBSD 10.0 bug. */
if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
L"%La %d", 3.1416015625L, 33, 44, 55) < 0
|| (wcscmp (buf, L"0x1.922p+1 33") != 0
&& wcscmp (buf, L"0x3.244p+0 33") != 0
&& wcscmp (buf, L"0x6.488p-1 33") != 0
&& wcscmp (buf, L"0xc.91p-2 33") != 0))
result |= 1;
return result;
}]])],
[gl_cv_func_swprintf_directive_la=yes],
[gl_cv_func_swprintf_directive_la=no],
[case "$host_os" in
# Guess yes on glibc >= 2.17 systems.
*-gnu* | gnu*)
AC_EGREP_CPP([Unlucky], [
#include <features.h>
#ifdef __GNU_LIBRARY__
#if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) || (__GLIBC__ > 2)) && !defined __UCLIBC__
Unlucky
#endif
#endif
],
[gl_cv_func_swprintf_directive_la="guessing yes"],
[gl_cv_func_swprintf_directive_la="guessing no"])
;;
# Guess yes on musl systems.
*-musl* | midipix*) gl_cv_func_swprintf_directive_la="guessing yes";;
# Guess yes on Android.
linux*-android*) gl_cv_func_swprintf_directive_la="guessing yes";;
# Guess no on NetBSD.
netbsd*) gl_cv_func_swprintf_directive_la="guessing no";;
# Guess no on native Windows.
mingw* | windows*) gl_cv_func_swprintf_directive_la="guessing no";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_swprintf_directive_la="$gl_cross_guess_normal";;
esac
])
])
])
dnl Test whether the *wprintf family of functions supports the 'lc' conversion
dnl specifier for all wide characters.
dnl (ISO C11, POSIX:2001)
dnl Result is gl_cv_func_swprintf_directive_lc.
AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LC],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether swprintf supports the 'lc' directive],
[gl_cv_func_swprintf_directive_lc],
[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#include <wchar.h>
static wchar_t buf[100];
static wint_t L_invalid = (wchar_t) 0x76543210;
int main ()
{
int result = 0;
/* This catches a musl libc 1.2.4, Android bug.
Reported at <https://www.openwall.com/lists/musl/2023/06/12/3>. */
if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
L"%lc %d", L_invalid, 33, 44, 55) < 0)
result |= 1;
return result;
}]])],
[gl_cv_func_swprintf_directive_lc=yes],
[gl_cv_func_swprintf_directive_lc=no],
[case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_swprintf_directive_lc="guessing yes";;
# Guess no on musl systems.
*-musl* | midipix*) gl_cv_func_swprintf_directive_lc="guessing no";;
# Guess no on Android.
linux*-android*) gl_cv_func_swprintf_directive_lc="guessing no";;
# Guess yes on native Windows.
mingw* | windows*) gl_cv_func_swprintf_directive_lc="guessing yes";;
# If we don't know, obey --enable-cross-guesses.
*) gl_cv_func_swprintf_directive_lc="$gl_cross_guess_normal";;
esac
])
])
])
dnl The results of these tests on various platforms are:
dnl
dnl 1 = gl_PRINTF_SIZES_C99
dnl 2 = gl_PRINTF_SIZES_C23
dnl 3 = gl_PRINTF_LONG_DOUBLE
dnl 4 = gl_PRINTF_INFINITE
dnl 5 = gl_PRINTF_INFINITE_LONG_DOUBLE
dnl 6 = gl_PRINTF_DIRECTIVE_A
dnl 7 = gl_PRINTF_DIRECTIVE_B
dnl 8 = gl_PRINTF_DIRECTIVE_UPPERCASE_B
dnl 9 = gl_PRINTF_DIRECTIVE_F
dnl 10 = gl_PRINTF_DIRECTIVE_N
dnl 11 = gl_PRINTF_DIRECTIVE_LS
dnl 12 = gl_PRINTF_DIRECTIVE_LC
dnl 13 = gl_PRINTF_POSITIONS
dnl 14 = gl_PRINTF_FLAG_GROUPING
dnl 15 = gl_PRINTF_FLAG_LEFTADJUST
dnl 16 = gl_PRINTF_FLAG_ZERO
dnl 17 = gl_PRINTF_FLAG_ALT_PRECISION_ZERO
dnl 18 = gl_PRINTF_PRECISION
dnl 19 = gl_PRINTF_ENOMEM
dnl 20 = gl_SNPRINTF_PRESENCE
dnl 21 = gl_SNPRINTF_TRUNCATION_C99
dnl 22 = gl_SNPRINTF_RETVAL_C99
dnl 23 = gl_SNPRINTF_DIRECTIVE_N
dnl 24 = gl_SNPRINTF_SIZE1
dnl 25 = gl_VSNPRINTF_ZEROSIZE_C99
dnl 26 = gl_SWPRINTF_WORKS
dnl 27 = gl_SWPRINTF_DIRECTIVE_LA
dnl 28 = gl_SWPRINTF_DIRECTIVE_LC
dnl
dnl 1 = checking whether printf supports size specifiers as in C99...
dnl 2 = checking whether printf supports size specifiers as in C23...
dnl 3 = checking whether printf supports 'long double' arguments...
dnl 4 = checking whether printf supports infinite 'double' arguments...
dnl 5 = checking whether printf supports infinite 'long double' arguments...
dnl 6 = checking whether printf supports the 'a' and 'A' directives...
dnl 7 = checking whether printf supports the 'b' directive...
dnl 8 = checking whether printf supports the 'B' directive...
dnl 9 = checking whether printf supports the 'F' directive...
dnl 10 = checking whether printf supports the 'n' directive...
dnl 11 = checking whether printf supports the 'ls' directive...
dnl 12 = checking whether printf supports the 'lc' directive correctly...
dnl 13 = checking whether printf supports POSIX/XSI format strings with positions...
dnl 14 = checking whether printf supports the grouping flag...
dnl 15 = checking whether printf supports the left-adjust flag correctly...
dnl 16 = checking whether printf supports the zero flag correctly...
dnl 17 = checking whether printf supports the alternative flag with a zero precision...
dnl 18 = checking whether printf supports large precisions...
dnl 19 = checking whether printf survives out-of-memory conditions...
dnl 20 = checking for snprintf...
dnl 21 = checking whether snprintf truncates the result as in C99...
dnl 22 = checking whether snprintf returns a byte count as in C99...
dnl 23 = checking whether snprintf fully supports the 'n' directive...
dnl 24 = checking whether snprintf respects a size of 1...
dnl 25 = checking whether vsnprintf respects a zero size as in C99...
dnl 26 = checking whether swprintf works...
dnl 27 = checking whether swprintf supports the 'La' and 'LA' directives...
dnl 28 = checking whether swprintf supports the 'lc' directive...
dnl
dnl . = yes, # = no.
dnl
dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
dnl musl libc 1.2.3 . # . . . . # # . . . # . . . . ? . . . . . . . . # . #
dnl glibc 2.35 . # . . . . . . . . . . . . . . . . . . . . . . . . . .
dnl glibc 2.5 . # . . . . # # . . . . . . . . . . . . . . . . . . # .
dnl glibc 2.3.6 . # . . . # # # . . . . . . . . . . . . . . . . . . # .
dnl FreeBSD 14.0 . . . . . # . . . . . . . . . . . . # . . . . . . # . #
dnl FreeBSD 13.0 . # . . . # # # . . . . . . . . . . # . . . . . . # . #
dnl FreeBSD 5.4, 6.1 . # . . . # # # . . . . . . . # ? . # . . . . . . # ? ?
dnl Mac OS X 10.13.5 . # . . # # # # . # . . . . . . . . . . . . # . . # ? ?
dnl Mac OS X 10.5.8 . # . . # # # # . . . . . . . # # . . . . . . . . # ? ?
dnl Mac OS X 10.3.9 . # . . . # # # . . . . . . . # # . # . . . . . . # ? ?
dnl OpenBSD 6.0, 6.7 . # . . . # # # . . . . . . . . . . # . . . . . . # . #
dnl OpenBSD 3.9, 4.0 . # . # # # # # # . # . . # . # ? . # . . . . . . # ? ?
dnl Cygwin 1.7.0 (2009) . # . . # . # # . . ? ? . . . . ? . ? . . . . . . ? ? ?
dnl Cygwin 1.5.25 (2008) . # . . # # # # . . # ? . . . . ? . # . . . . . . ? ? ?
dnl Cygwin 1.5.19 (2006) # # . . # # # # # . # ? . # . # ? # # . . . . . . ? ? ?
dnl Solaris 11.4 . # . # # # # # . . # . . . . # . . . . . . . . . . # .
dnl Solaris 11.3 . # . . . # # # . . # . . . . . . . . . . . . . . . # .
dnl Solaris 11.0 . # . # # # # # . . # . . . . # . . . . . . . . . ? ? ?
dnl Solaris 10 . # . # # # # # . . # . . . . # . # . . . . . . . . # .
dnl Solaris 2.6 ... 9 # # . # # # # # # . # . . . . # ? # . . . # . . . ? ? ?
dnl Solaris 2.5.1 # # . # # # # # # . # . . . . # ? . . # # # # # # ? ? ?
dnl AIX 7.1 . # . # # # # # . . . . . . . # . # . . . . . . . # . .
dnl AIX 5.2 . # . # # # # # . . . . . . . # ? . . . . . . . . # ? ?
dnl AIX 4.3.2, 5.1 # # . # # # # # # . . . . . . # ? . . . . # . . . # ? ?
dnl HP-UX 11.31 . # . . . # # # . . . ? . . . # ? . . . . # # . . ? ? ?
dnl HP-UX 11.{00,11,23} # # . . . # # # # . . ? . . . # ? . . . . # # . # ? ? ?
dnl HP-UX 10.20 # # . # . # # # # . ? ? . . # # ? . . . . # # ? # ? ? ?
dnl IRIX 6.5 # # . # # # # # # . # . . . . # ? . . . . # . . . # ? ?
dnl OSF/1 5.1 # # . # # # # # # . . ? . . . # ? . . . . # . . # ? ? ?
dnl OSF/1 4.0d # # . # # # # # # . . ? . . . # ? . . # # # # # # ? ? ?
dnl NetBSD 9.0 . # . . . # # # . . . . . . . . . . . . . . . . . # . #
dnl NetBSD 5.0 . # . . # # # # . . . . . . . # ? . # . . . . . . # ? ?
dnl NetBSD 4.0 . # ? ? ? ? # # ? . ? . . ? ? ? ? ? ? . . . ? ? ? # ? ?
dnl NetBSD 3.0 . # . . . # # # # . ? . # # ? # ? . # . . . . . . # ? ?
dnl Haiku . # . . # # # # # . # ? . . . . ? . ? . . ? . . . . # .
dnl BeOS # # # . # # # # # . ? ? # . ? . ? # ? . . ? . . . ? ? ?
dnl Android 4.3 . # . # # # # # # # # ? . # . # ? . # . . . # . . ? ? ?
dnl old mingw / msvcrt # # # # # # # # # . . ? # # . # ? # ? . # # # . . # ? ?
dnl MSVC 9 # # # # # # # # # # . ? # # . # ? # ? # # # # . . # ? ?
dnl mingw 2009-2011 . # # . # . # # . . . ? # # . . ? . ? . . . . . . # ? ?
dnl mingw-w64 2011 # # # # # # # # # . . ? # # . # ? # ? . # # # . . # ? ?
|