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 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178
|
/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* # CategoryStdinc
*
* SDL provides its own implementation of some of the most important C runtime
* functions.
*
* Using these functions allows an app to have access to common C
* functionality without depending on a specific C runtime (or a C runtime at
* all). More importantly, the SDL implementations work identically across
* platforms, so apps can avoid surprises like snprintf() behaving differently
* between Windows and Linux builds, or itoa() only existing on some
* platforms.
*
* For many of the most common functions, like SDL_memcpy, SDL might just call
* through to the usual C runtime behind the scenes, if it makes sense to do
* so (if it's faster and always available/reliable on a given platform),
* reducing library size and offering the most optimized option.
*
* SDL also offers other C-runtime-adjacent functionality in this header that
* either isn't, strictly speaking, part of any C runtime standards, like
* SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better
* options, like SDL_strlcpy(), which functions as a safer form of strcpy().
*/
#ifndef SDL_stdinc_h_
#define SDL_stdinc_h_
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <string.h>
#include <wchar.h>
/* Most everything except Visual Studio 2008 and earlier has stdint.h now */
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif
#endif
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
#endif
#endif
#else
#include <stdint.h>
#endif
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(SDL_INCLUDE_INTTYPES_H)
#include <inttypes.h>
#endif
#ifndef __cplusplus
#if defined(__has_include) && !defined(SDL_INCLUDE_STDBOOL_H)
#if __has_include(<stdbool.h>)
#define SDL_INCLUDE_STDBOOL_H
#endif
#endif
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \
defined(SDL_INCLUDE_STDBOOL_H)
#include <stdbool.h>
#elif !defined(__bool_true_false_are_defined) && !defined(bool)
#define bool unsigned char
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif
#endif /* !__cplusplus */
#ifndef SDL_DISABLE_ALLOCA
# ifndef alloca
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# elif defined(SDL_PLATFORM_NETBSD)
# if defined(__STRICT_ANSI__)
# define SDL_DISABLE_ALLOCA
# else
# include <stdlib.h>
# endif
# elif defined(__GNUC__)
# define alloca __builtin_alloca
# elif defined(_MSC_VER)
# include <malloc.h>
# define alloca _alloca
# elif defined(__WATCOMC__)
# include <malloc.h>
# elif defined(__BORLANDC__)
# include <malloc.h>
# elif defined(__DMC__)
# include <stdlib.h>
# elif defined(SDL_PLATFORM_AIX)
# pragma alloca
# elif defined(__MRC__)
void *alloca(unsigned);
# else
void *alloca(size_t);
# endif
# endif
#endif
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Don't let SDL use "long long" C types.
*
* SDL will define this if it believes the compiler doesn't understand the
* "long long" syntax for C datatypes. This can happen on older compilers.
*
* If _your_ compiler doesn't support "long long" but SDL doesn't know it, it
* is safe to define this yourself to build against the SDL headers.
*
* If this is defined, it will remove access to some C runtime support
* functions, like SDL_ulltoa and SDL_strtoll that refer to this datatype
* explicitly. The rest of SDL will still be available.
*
* SDL's own source code cannot be built with a compiler that has this
* defined, for various technical reasons.
*/
#define SDL_NOLONGLONG 1
#elif defined(_MSC_VER) && (_MSC_VER < 1310) /* long long introduced in Visual Studio.NET 2003 */
# define SDL_NOLONGLONG 1
#endif
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* The largest value that a `size_t` can hold for the target platform.
*
* `size_t` is generally the same size as a pointer in modern times, but this
* can get weird on very old and very esoteric machines. For example, on a
* 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment
* plus 16-bit offset), but `size_t` is 16 bits, because it can only deal with
* the offset into an individual segment.
*
* In modern times, it's generally expected to cover an entire linear address
* space. But be careful!
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SIZE_MAX SIZE_MAX
#elif defined(SIZE_MAX)
# define SDL_SIZE_MAX SIZE_MAX
#else
# define SDL_SIZE_MAX ((size_t) -1)
#endif
#ifndef SDL_COMPILE_TIME_ASSERT
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A compile-time assertion.
*
* This can check constant values _known to the compiler at build time_ for
* correctness, and end the compile with the error if they fail.
*
* Often times these are used to verify basic truths, like the size of a
* datatype is what is expected:
*
* ```c
* SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
* ```
*
* The `name` parameter must be a valid C symbol, and must be unique across
* all compile-time asserts in the same compilation unit (one run of the
* compiler), or the build might fail with cryptic errors on some targets.
* This is used with a C language trick that works on older compilers that
* don't support better assertion techniques.
*
* If you need an assertion that operates at runtime, on variable data, you
* should try SDL_assert instead.
*
* \param name a unique identifier for this assertion.
* \param x the value to test. Must be a boolean value.
*
* \threadsafety This macro doesn't generate any code to run.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_assert
*/
#define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
#elif defined(__cplusplus)
/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
#if (__cplusplus >= 201103L)
#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
#endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
#endif
#endif /* !SDL_COMPILE_TIME_ASSERT */
#ifndef SDL_COMPILE_TIME_ASSERT
/* universal, but may trigger -Wunused-local-typedefs */
#define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
#endif
/**
* The number of elements in a static array.
*
* This will compile but return incorrect results for a pointer to an array;
* it has to be an array the compiler knows the size of.
*
* This macro looks like it double-evaluates the argument, but it does so
* inside of `sizeof`, so there are no side-effects here, as expressions do
* not actually run any code in these cases.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
/**
* Macro useful for building other macros with strings in them.
*
* \param arg the text to turn into a string literal.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_STRINGIFY_ARG(arg) #arg
/**
* \name Cast operators
*
* Use proper C++ casts when compiled as C++ to be compatible with the option
* -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
*/
/* @{ */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Handle a Reinterpret Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_static_cast
* \sa SDL_const_cast
*/
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
/**
* Handle a Static Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ static_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_reinterpret_cast
* \sa SDL_const_cast
*/
#define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
/**
* Handle a Const Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ const_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_reinterpret_cast
* \sa SDL_static_cast
*/
#define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
#elif defined(__cplusplus)
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
#define SDL_static_cast(type, expression) static_cast<type>(expression)
#define SDL_const_cast(type, expression) const_cast<type>(expression)
#else
#define SDL_reinterpret_cast(type, expression) ((type)(expression))
#define SDL_static_cast(type, expression) ((type)(expression))
#define SDL_const_cast(type, expression) ((type)(expression))
#endif
/* @} *//* Cast operators */
/**
* Define a four character code as a Uint32.
*
* \param A the first ASCII character.
* \param B the second ASCII character.
* \param C the third ASCII character.
* \param D the fourth ASCII character.
* \returns the four characters converted into a Uint32, one character
* per-byte.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FOURCC(A, B, C, D) \
((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Append the 64 bit integer suffix to a signed integer literal.
*
* This helps compilers that might believe a integer literal larger than
* 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
* instead of `0xFFFFFFFF1` by itself.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_UINT64_C
*/
#define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
/**
* Append the 64 bit integer suffix to an unsigned integer literal.
*
* This helps compilers that might believe a integer literal larger than
* 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
* instead of `0xFFFFFFFF1` by itself.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SINT64_C
*/
#define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
#else /* !SDL_WIKI_DOCUMENTATION_SECTION */
#ifndef SDL_SINT64_C
#if defined(INT64_C)
#define SDL_SINT64_C(c) INT64_C(c)
#elif defined(_MSC_VER)
#define SDL_SINT64_C(c) c ## i64
#elif defined(__LP64__) || defined(_LP64)
#define SDL_SINT64_C(c) c ## L
#else
#define SDL_SINT64_C(c) c ## LL
#endif
#endif /* !SDL_SINT64_C */
#ifndef SDL_UINT64_C
#if defined(UINT64_C)
#define SDL_UINT64_C(c) UINT64_C(c)
#elif defined(_MSC_VER)
#define SDL_UINT64_C(c) c ## ui64
#elif defined(__LP64__) || defined(_LP64)
#define SDL_UINT64_C(c) c ## UL
#else
#define SDL_UINT64_C(c) c ## ULL
#endif
#endif /* !SDL_UINT64_C */
#endif /* !SDL_WIKI_DOCUMENTATION_SECTION */
/**
* \name Basic data types
*/
/* @{ */
/**
* A signed 8-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef int8_t Sint8;
#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
/**
* An unsigned 8-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef uint8_t Uint8;
#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
/**
* A signed 16-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef int16_t Sint16;
#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
/**
* An unsigned 16-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef uint16_t Uint16;
#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
/**
* A signed 32-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef int32_t Sint32;
#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
/**
* An unsigned 32-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*/
typedef uint32_t Uint32;
#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
/**
* A signed 64-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_SINT64_C
*/
typedef int64_t Sint64;
#define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
/**
* An unsigned 64-bit integer type.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_UINT64_C
*/
typedef uint64_t Uint64;
#define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
#define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
/**
* SDL times are signed, 64-bit integers representing nanoseconds since the
* Unix epoch (Jan 1, 1970).
*
* They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
* and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
* SDL_TimeToWindows() and SDL_TimeFromWindows().
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_MAX_SINT64
* \sa SDL_MIN_SINT64
*/
typedef Sint64 SDL_Time;
#define SDL_MAX_TIME SDL_MAX_SINT64
#define SDL_MIN_TIME SDL_MIN_SINT64
/* @} *//* Basic data types */
/**
* \name Floating-point constants
*/
/* @{ */
#ifdef FLT_EPSILON
#define SDL_FLT_EPSILON FLT_EPSILON
#else
/**
* Epsilon constant, used for comparing floating-point numbers.
*
* Equals by default to platform-defined `FLT_EPSILON`, or
* `1.1920928955078125e-07F` if that's not available.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
#endif
/* @} *//* Floating-point constants */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A printf-formatting string for an Sint64 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIs64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIs64 "lld"
/**
* A printf-formatting string for a Uint64 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIu64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIu64 "llu"
/**
* A printf-formatting string for a Uint64 value as lower-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIx64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIx64 "llx"
/**
* A printf-formatting string for a Uint64 value as upper-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIX64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIX64 "llX"
/**
* A printf-formatting string for an Sint32 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIs32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIs32 "d"
/**
* A printf-formatting string for a Uint32 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIu32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIu32 "u"
/**
* A printf-formatting string for a Uint32 value as lower-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIx32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIx32 "x"
/**
* A printf-formatting string for a Uint32 value as upper-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIX32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRIX32 "X"
/**
* A printf-formatting string prefix for a `long long` value.
*
* This is just the prefix! You probably actually want SDL_PRILLd, SDL_PRILLu,
* SDL_PRILLx, or SDL_PRILLX instead.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILL_PREFIX "d bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRILL_PREFIX "ll"
/**
* A printf-formatting string for a `long long` value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLd " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRILLd SDL_PRILL_PREFIX "d"
/**
* A printf-formatting string for a `unsigned long long` value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLu " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRILLu SDL_PRILL_PREFIX "u"
/**
* A printf-formatting string for an `unsigned long long` value as lower-case
* hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLx " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRILLx SDL_PRILL_PREFIX "x"
/**
* A printf-formatting string for an `unsigned long long` value as upper-case
* hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLX " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRILLX SDL_PRILL_PREFIX "X"
#endif /* SDL_WIKI_DOCUMENTATION_SECTION */
/* Make sure we have macros for printing width-based integers.
* <inttypes.h> should define these but this is not true all platforms.
* (for example win32) */
#ifndef SDL_PRIs64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIs64 "I64d"
#elif defined(PRId64)
#define SDL_PRIs64 PRId64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
#define SDL_PRIs64 "ld"
#else
#define SDL_PRIs64 "lld"
#endif
#endif
#ifndef SDL_PRIu64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIu64 "I64u"
#elif defined(PRIu64)
#define SDL_PRIu64 PRIu64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
#define SDL_PRIu64 "lu"
#else
#define SDL_PRIu64 "llu"
#endif
#endif
#ifndef SDL_PRIx64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIx64 "I64x"
#elif defined(PRIx64)
#define SDL_PRIx64 PRIx64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
#define SDL_PRIx64 "lx"
#else
#define SDL_PRIx64 "llx"
#endif
#endif
#ifndef SDL_PRIX64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIX64 "I64X"
#elif defined(PRIX64)
#define SDL_PRIX64 PRIX64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
#define SDL_PRIX64 "lX"
#else
#define SDL_PRIX64 "llX"
#endif
#endif
#ifndef SDL_PRIs32
#ifdef PRId32
#define SDL_PRIs32 PRId32
#else
#define SDL_PRIs32 "d"
#endif
#endif
#ifndef SDL_PRIu32
#ifdef PRIu32
#define SDL_PRIu32 PRIu32
#else
#define SDL_PRIu32 "u"
#endif
#endif
#ifndef SDL_PRIx32
#ifdef PRIx32
#define SDL_PRIx32 PRIx32
#else
#define SDL_PRIx32 "x"
#endif
#endif
#ifndef SDL_PRIX32
#ifdef PRIX32
#define SDL_PRIX32 PRIX32
#else
#define SDL_PRIX32 "X"
#endif
#endif
/* Specifically for the `long long` -- SDL-specific. */
#ifdef SDL_PLATFORM_WINDOWS
#ifndef SDL_NOLONGLONG
SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */
#endif
#define SDL_PRILL_PREFIX "I64"
#else
#define SDL_PRILL_PREFIX "ll"
#endif
#ifndef SDL_PRILLd
#define SDL_PRILLd SDL_PRILL_PREFIX "d"
#endif
#ifndef SDL_PRILLu
#define SDL_PRILLu SDL_PRILL_PREFIX "u"
#endif
#ifndef SDL_PRILLx
#define SDL_PRILLx SDL_PRILL_PREFIX "x"
#endif
#ifndef SDL_PRILLX
#define SDL_PRILLX SDL_PRILL_PREFIX "X"
#endif
/* Annotations to help code analysis tools */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Macro that annotates function params with input buffer size.
*
* If we were to annotate `memcpy`:
*
* ```c
* void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
* ```
*
* This notes that `src` should be `len` bytes in size and is only read by the
* function. The compiler or other analysis tools can warn when this doesn't
* appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
/**
* Macro that annotates function params with input/output string buffer size.
*
* If we were to annotate `strlcat`:
*
* ```c
* size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
* ```
*
* This notes that `dst` is a null-terminated C string, should be `maxlen`
* bytes in size, and is both read from and written to by the function. The
* compiler or other analysis tools can warn when this doesn't appear to be
* the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
/**
* Macro that annotates function params with output string buffer size.
*
* If we were to annotate `snprintf`:
*
* ```c
* int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...);
* ```
*
* This notes that `text` is a null-terminated C string, should be `maxlen`
* bytes in size, and is only written to by the function. The compiler or
* other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
/**
* Macro that annotates function params with output buffer size.
*
* If we were to annotate `wcsncpy`:
*
* ```c
* char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` wchar_t in size,
* and is only written to by the function. The compiler or other analysis
* tools can warn when this doesn't appear to be the case.
*
* This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for
* bytes.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_OUT_CAP(x) _Out_cap_(x)
/**
* Macro that annotates function params with output buffer size.
*
* If we were to annotate `memcpy`:
*
* ```c
* void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` bytes in size,
* and is only written to by the function. The compiler or other analysis
* tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
/**
* Macro that annotates function params with output buffer string size.
*
* If we were to annotate `strcpy`:
*
* ```c
* char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` bytes in size,
* and a zero-terminated string is written to it by the function. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
/**
* Macro that annotates function params as printf-style format strings.
*
* If we were to annotate `fprintf`:
*
* ```c
* int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
* ```
*
* This notes that `fmt` should be a printf-style format string. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
/**
* Macro that annotates function params as scanf-style format strings.
*
* If we were to annotate `fscanf`:
*
* ```c
* int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...);
* ```
*
* This notes that `fmt` should be a scanf-style format string. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
/**
* Macro that annotates a vararg function that operates like printf.
*
* If we were to annotate `fprintf`:
*
* ```c
* int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a printf-style format
* string, followed by `...`. The compiler or other analysis tools can warn
* when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
/**
* Macro that annotates a va_list function that operates like printf.
*
* If we were to annotate `vfprintf`:
*
* ```c
* int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a printf-style format
* string, followed by a va_list. The compiler or other analysis tools can
* warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
/**
* Macro that annotates a vararg function that operates like scanf.
*
* If we were to annotate `fscanf`:
*
* ```c
* int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a scanf-style format string,
* followed by `...`. The compiler or other analysis tools can warn when this
* doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
/**
* Macro that annotates a va_list function that operates like scanf.
*
* If we were to annotate `vfscanf`:
*
* ```c
* int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a scanf-style format string,
* followed by a va_list. The compiler or other analysis tools can warn when
* this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
/**
* Macro that annotates a vararg function that operates like wprintf.
*
* If we were to annotate `fwprintf`:
*
* ```c
* int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a wprintf-style format wide
* string, followed by `...`. The compiler or other analysis tools can warn
* when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
/**
* Macro that annotates a va_list function that operates like wprintf.
*
* If we were to annotate `vfwprintf`:
*
* ```c
* int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a wprintf-style format wide
* string, followed by a va_list. The compiler or other analysis tools can
* warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
#elif defined(SDL_DISABLE_ANALYZE_MACROS)
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
#else
#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
#include <sal.h>
#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
#define SDL_OUT_CAP(x) _Out_cap_(x)
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
#else
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#endif
#if defined(__GNUC__) || defined(__clang__)
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
#else
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
#endif
#endif /* SDL_DISABLE_ANALYZE_MACROS */
/** \cond */
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);
SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1);
SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1);
SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2);
SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2);
SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4);
SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8);
SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8);
#ifndef SDL_NOLONGLONG
SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long));
SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long));
#endif
typedef struct SDL_alignment_test
{
Uint8 a;
void *b;
} SDL_alignment_test;
SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
SDL_COMPILE_TIME_ASSERT(two_s_complement, SDL_static_cast(int, ~SDL_static_cast(int, 0)) == SDL_static_cast(int, -1));
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/** \endcond */
/* Check to make sure enums are the size of ints, for structure packing.
For both Watcom C/C++ and Borland C/C++ the compiler option that makes
enums having the size of an int must be enabled.
This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
*/
/** \cond */
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
typedef enum SDL_DUMMY_ENUM
{
DUMMY_ENUM_VALUE
} SDL_DUMMY_ENUM;
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/** \endcond */
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* A macro to initialize an SDL interface.
*
* This macro will initialize an SDL interface structure and should be called
* before you fill out the fields with your implementation.
*
* You can use it like this:
*
* ```c
* SDL_IOStreamInterface iface;
*
* SDL_INIT_INTERFACE(&iface);
*
* // Fill in the interface function pointers with your implementation
* iface.seek = ...
*
* stream = SDL_OpenIO(&iface, NULL);
* ```
*
* If you are using designated initializers, you can use the size of the
* interface as the version, e.g.
*
* ```c
* SDL_IOStreamInterface iface = {
* .version = sizeof(iface),
* .seek = ...
* };
* stream = SDL_OpenIO(&iface, NULL);
* ```
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_IOStreamInterface
* \sa SDL_StorageInterface
* \sa SDL_VirtualJoystickDesc
*/
#define SDL_INIT_INTERFACE(iface) \
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Allocate memory on the stack (maybe).
*
* If SDL knows how to access alloca() on the current platform, it will use it
* to stack-allocate memory here. If it doesn't, it will use SDL_malloc() to
* heap-allocate memory.
*
* Since this might not be stack memory at all, it's important that you check
* the returned pointer for NULL, and that you call SDL_stack_free on the
* memory when done with it. Since this might be stack memory, it's important
* that you don't allocate large amounts of it, or allocate in a loop without
* returning from the function, so the stack doesn't overflow.
*
* \param type the datatype of the memory to allocate.
* \param count the number of `type` objects to allocate.
* \returns newly-allocated memory, or NULL on failure.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_stack_free
*/
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
/**
* Free memory previously allocated with SDL_stack_alloc.
*
* If SDL used alloca() to allocate this memory, this macro does nothing and
* the allocated memory will be automatically released when the function that
* called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will
* SDL_free the memory immediately.
*
* \param data the pointer, from SDL_stack_alloc(), to free.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_stack_alloc
*/
#define SDL_stack_free(data)
#elif !defined(SDL_DISABLE_ALLOCA)
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
#define SDL_stack_free(data)
#else
#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
#define SDL_stack_free(data) SDL_free(data)
#endif
/**
* Allocate uninitialized memory.
*
* The allocated memory returned by this function must be freed with
* SDL_free().
*
* If `size` is 0, it will be set to 1.
*
* If the allocation is successful, the returned pointer is guaranteed to be
* aligned to either the *fundamental alignment* (`alignof(max_align_t)` in
* C11 and later) or `2 * sizeof(void *)`, whichever is smaller. Use
* SDL_aligned_alloc() if you need to allocate memory aligned to an alignment
* greater than this guarantee.
*
* \param size the size to allocate.
* \returns a pointer to the allocated memory, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_free
* \sa SDL_calloc
* \sa SDL_realloc
* \sa SDL_aligned_alloc
*/
extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
/**
* Allocate a zero-initialized array.
*
* The memory returned by this function must be freed with SDL_free().
*
* If either of `nmemb` or `size` is 0, they will both be set to 1.
*
* If the allocation is successful, the returned pointer is guaranteed to be
* aligned to either the *fundamental alignment* (`alignof(max_align_t)` in
* C11 and later) or `2 * sizeof(void *)`, whichever is smaller.
*
* \param nmemb the number of elements in the array.
* \param size the size of each element of the array.
* \returns a pointer to the allocated array, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_free
* \sa SDL_malloc
* \sa SDL_realloc
*/
extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
/**
* Change the size of allocated memory.
*
* The memory returned by this function must be freed with SDL_free().
*
* If `size` is 0, it will be set to 1. Note that this is unlike some other C
* runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
* same way as `free(mem)`.
*
* If `mem` is NULL, the behavior of this function is equivalent to
* SDL_malloc(). Otherwise, the function can have one of three possible
* outcomes:
*
* - If it returns the same pointer as `mem`, it means that `mem` was resized
* in place without freeing.
* - If it returns a different non-NULL pointer, it means that `mem` was freed
* and cannot be dereferenced anymore.
* - If it returns NULL (indicating failure), then `mem` will remain valid and
* must still be freed with SDL_free().
*
* If the allocation is successfully resized, the returned pointer is
* guaranteed to be aligned to either the *fundamental alignment*
* (`alignof(max_align_t)` in C11 and later) or `2 * sizeof(void *)`,
* whichever is smaller.
*
* \param mem a pointer to allocated memory to reallocate, or NULL.
* \param size the new size of the memory.
* \returns a pointer to the newly allocated memory, or NULL if allocation
* failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_free
* \sa SDL_malloc
* \sa SDL_calloc
*/
extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
/**
* Free allocated memory.
*
* The pointer is no longer valid after this call and cannot be dereferenced
* anymore.
*
* If `mem` is NULL, this function does nothing.
*
* \param mem a pointer to allocated memory, or NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_malloc
* \sa SDL_calloc
* \sa SDL_realloc
*/
extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
/**
* A callback used to implement SDL_malloc().
*
* SDL will always ensure that the passed `size` is greater than 0.
*
* \param size the size to allocate.
* \returns a pointer to the allocated memory, or NULL if allocation failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_malloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
/**
* A callback used to implement SDL_calloc().
*
* SDL will always ensure that the passed `nmemb` and `size` are both greater
* than 0.
*
* \param nmemb the number of elements in the array.
* \param size the size of each element of the array.
* \returns a pointer to the allocated array, or NULL if allocation failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_calloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
/**
* A callback used to implement SDL_realloc().
*
* SDL will always ensure that the passed `size` is greater than 0.
*
* \param mem a pointer to allocated memory to reallocate, or NULL.
* \param size the new size of the memory.
* \returns a pointer to the newly allocated memory, or NULL if allocation
* failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_realloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
/**
* A callback used to implement SDL_free().
*
* SDL will always ensure that the passed `mem` is a non-NULL pointer.
*
* \param mem a pointer to allocated memory.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_free
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void (SDLCALL *SDL_free_func)(void *mem);
/**
* Get the original set of SDL memory functions.
*
* This is what SDL_malloc and friends will use by default, if there has been
* no call to SDL_SetMemoryFunctions. This is not necessarily using the C
* runtime's `malloc` functions behind the scenes! Different platforms and
* build configurations might do any number of unexpected things.
*
* \param malloc_func filled with malloc function.
* \param calloc_func filled with calloc function.
* \param realloc_func filled with realloc function.
* \param free_func filled with free function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
SDL_calloc_func *calloc_func,
SDL_realloc_func *realloc_func,
SDL_free_func *free_func);
/**
* Get the current set of SDL memory functions.
*
* \param malloc_func filled with malloc function.
* \param calloc_func filled with calloc function.
* \param realloc_func filled with realloc function.
* \param free_func filled with free function.
*
* \threadsafety This does not hold a lock, so do not call this in the
* unlikely event of a background thread calling
* SDL_SetMemoryFunctions simultaneously.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetMemoryFunctions
* \sa SDL_GetOriginalMemoryFunctions
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
SDL_calloc_func *calloc_func,
SDL_realloc_func *realloc_func,
SDL_free_func *free_func);
/**
* Replace SDL's memory allocation functions with a custom set.
*
* It is not safe to call this function once any allocations have been made,
* as future calls to SDL_free will use the new allocator, even if they came
* from an SDL_malloc made with the old one!
*
* If used, usually this needs to be the first call made into the SDL library,
* if not the very first thing done at program startup time.
*
* \param malloc_func custom malloc function.
* \param calloc_func custom calloc function.
* \param realloc_func custom realloc function.
* \param free_func custom free function.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread, but one
* should not replace the memory functions once any allocations
* are made!
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetMemoryFunctions
* \sa SDL_GetOriginalMemoryFunctions
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func);
/**
* Allocate memory aligned to a specific alignment.
*
* The memory returned by this function must be freed with SDL_aligned_free(),
* _not_ SDL_free().
*
* If `alignment` is less than the size of `void *`, it will be increased to
* match that.
*
* The returned memory address will be a multiple of the alignment value, and
* the size of the memory allocated will be a multiple of the alignment value.
*
* \param alignment the alignment of the memory.
* \param size the size to allocate.
* \returns a pointer to the aligned memory, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_aligned_free
*/
extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
/**
* Free memory allocated by SDL_aligned_alloc().
*
* The pointer is no longer valid after this call and cannot be dereferenced
* anymore.
*
* If `mem` is NULL, this function does nothing.
*
* \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_aligned_alloc
*/
extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
/**
* Get the number of outstanding (unfreed) allocations.
*
* \returns the number of allocations or -1 if allocation counting is
* disabled.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
/**
* A thread-safe set of environment variables
*
* \since This struct is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
* \sa SDL_DestroyEnvironment
*/
typedef struct SDL_Environment SDL_Environment;
/**
* Get the process environment.
*
* This is initialized at application start and is not affected by setenv()
* and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
* SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
* SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
* in the C runtime environment after SDL_Quit().
*
* \returns a pointer to the environment for the process or NULL on failure;
* call SDL_GetError() for more information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
/**
* Create a set of environment variables
*
* \param populated true to initialize it from the C runtime environment,
* false to create an empty environment.
* \returns a pointer to the new environment or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety If `populated` is false, it is safe to call this function
* from any thread, otherwise it is safe if no other threads are
* calling setenv() or unsetenv()
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
* \sa SDL_DestroyEnvironment
*/
extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
/**
* Get the value of a variable in the environment.
*
* \param env the environment to query.
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
/**
* Get all variables in the environment.
*
* \param env the environment to query.
* \returns a NULL terminated array of pointers to environment variables in
* the form "variable=value" or NULL on failure; call SDL_GetError()
* for more information. This is a single allocation that should be
* freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
/**
* Set the value of a variable in the environment.
*
* \param env the environment to modify.
* \param name the name of the variable to set.
* \param value the value of the variable to set.
* \param overwrite true to overwrite the variable if it exists, false to
* return success without setting the variable if it already
* exists.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
/**
* Clear a variable from the environment.
*
* \param env the environment to modify.
* \param name the name of the variable to unset.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
/**
* Destroy a set of environment variables.
*
* \param env the environment to destroy.
*
* \threadsafety It is safe to call this function from any thread, as long as
* the environment is no longer in use.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_CreateEnvironment
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
/**
* Get the value of a variable in the environment.
*
* This function uses SDL's cached copy of the environment and is thread-safe.
*
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
/**
* Get the value of a variable in the environment.
*
* This function bypasses SDL's cached copy of the environment and is not
* thread-safe.
*
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety This function is not thread safe, consider using SDL_getenv()
* instead.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_getenv
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
/**
* Set the value of a variable in the environment.
*
* \param name the name of the variable to set.
* \param value the value of the variable to set.
* \param overwrite 1 to overwrite the variable if it exists, 0 to return
* success without setting the variable if it already exists.
* \returns 0 on success, -1 on error.
*
* \threadsafety This function is not thread safe, consider using
* SDL_SetEnvironmentVariable() instead.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SetEnvironmentVariable
*/
extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
/**
* Clear a variable from the environment.
*
* \param name the name of the variable to unset.
* \returns 0 on success, -1 on error.
*
* \threadsafety This function is not thread safe, consider using
* SDL_UnsetEnvironmentVariable() instead.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
/**
* A callback used with SDL sorting and binary search functions.
*
* \param a a pointer to the first element being compared.
* \param b a pointer to the second element being compared.
* \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
* before `a`, 0 if they are equal. If two elements are equal, their
* order in the sorted array is undefined.
*
* \since This callback is available since SDL 3.2.0.
*
* \sa SDL_bsearch
* \sa SDL_qsort
*/
typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
/**
* Sort an array.
*
* For example:
*
* ```c
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *a, const void *b)
* {
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->n < B->n) {
* return -1;
* } else if (B->n < A->n) {
* return 1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 3, "third" }, { 1, "first" }, { 2, "second" }
* };
*
* SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
* ```
*
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_bsearch
* \sa SDL_qsort_r
*/
extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
/**
* Perform a binary search on a previously sorted array.
*
* For example:
*
* ```c
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *a, const void *b)
* {
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->n < B->n) {
* return -1;
* } else if (B->n < A->n) {
* return 1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 1, "first" }, { 2, "second" }, { 3, "third" }
* };
* data key = { 2, NULL };
*
* data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
* ```
*
* \param key a pointer to a key equal to the element being searched for.
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \returns a pointer to the matching element in the array, or NULL if not
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_bsearch_r
* \sa SDL_qsort
*/
extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
/**
* A callback used with SDL sorting and binary search functions.
*
* \param userdata the `userdata` pointer passed to the sort function.
* \param a a pointer to the first element being compared.
* \param b a pointer to the second element being compared.
* \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
* before `a`, 0 if they are equal. If two elements are equal, their
* order in the sorted array is undefined.
*
* \since This callback is available since SDL 3.2.0.
*
* \sa SDL_qsort_r
* \sa SDL_bsearch_r
*/
typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
/**
* Sort an array, passing a userdata pointer to the compare function.
*
* For example:
*
* ```c
* typedef enum {
* sort_increasing,
* sort_decreasing,
* } sort_method;
*
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *userdata, const void *a, const void *b)
* {
* sort_method method = (sort_method)(uintptr_t)userdata;
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->key < B->key) {
* return (method == sort_increasing) ? -1 : 1;
* } else if (B->key < A->key) {
* return (method == sort_increasing) ? 1 : -1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 3, "third" }, { 1, "first" }, { 2, "second" }
* };
*
* SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
* ```
*
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \param userdata a pointer to pass to the compare function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_bsearch_r
* \sa SDL_qsort
*/
extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
/**
* Perform a binary search on a previously sorted array, passing a userdata
* pointer to the compare function.
*
* For example:
*
* ```c
* typedef enum {
* sort_increasing,
* sort_decreasing,
* } sort_method;
*
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *userdata, const void *a, const void *b)
* {
* sort_method method = (sort_method)(uintptr_t)userdata;
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->key < B->key) {
* return (method == sort_increasing) ? -1 : 1;
* } else if (B->key < A->key) {
* return (method == sort_increasing) ? 1 : -1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 1, "first" }, { 2, "second" }, { 3, "third" }
* };
* data key = { 2, NULL };
*
* data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
* ```
*
* \param key a pointer to a key equal to the element being searched for.
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \param userdata a pointer to pass to the compare function.
* \returns a pointer to the matching element in the array, or NULL if not
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_bsearch
* \sa SDL_qsort_r
*/
extern SDL_DECLSPEC void * SDLCALL SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
/**
* Compute the absolute value of `x`.
*
* \param x an integer value.
* \returns the absolute value of x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
/**
* Return the lesser of two values.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `<` operator. However, it double-evaluates both its parameters, so do not
* use expressions with side-effects here.
*
* \param x the first value to compare.
* \param y the second value to compare.
* \returns the lesser of `x` and `y`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
/**
* Return the greater of two values.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `>` operator. However, it double-evaluates both its parameters, so do not
* use expressions with side-effects here.
*
* \param x the first value to compare.
* \param y the second value to compare.
* \returns the greater of `x` and `y`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
/**
* Return a value clamped to a range.
*
* If `x` is outside the range a values between `a` and `b`, the returned
* value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
*
* This macro will produce incorrect results if `b` is less than `a`.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `<` and `>` operators. However, it double-evaluates all its parameters, so
* do not use expressions with side-effects here.
*
* \param x the value to compare.
* \param a the low end value.
* \param b the high end value.
* \returns x, clamped between a and b.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
/**
* Query if a character is alphabetic (a letter).
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* for English 'a-z' and 'A-Z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
/**
* Query if a character is alphabetic (a letter) or a number.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* for English 'a-z', 'A-Z', and '0-9' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
/**
* Report if a character is blank (a space or tab).
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 0x20 (space) or 0x9 (tab) as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
/**
* Report if a character is a control character.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 0 through 0x1F, and 0x7F, as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
/**
* Report if a character is a numeric digit.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* '0' (0x30) through '9' (0x39), as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
/**
* Report if a character is a hexadecimal digit.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
/**
* Report if a character is a punctuation mark.
*
* **WARNING**: Regardless of system locale, this is equivalent to
* `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isgraph
* \sa SDL_isalnum
*/
extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
/**
* Report if a character is whitespace.
*
* **WARNING**: Regardless of system locale, this will only treat the
* following ASCII values as true:
*
* - space (0x20)
* - tab (0x09)
* - newline (0x0A)
* - vertical tab (0x0B)
* - form feed (0x0C)
* - return (0x0D)
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
/**
* Report if a character is upper case.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'A' through 'Z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
/**
* Report if a character is lower case.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'a' through 'z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
/**
* Report if a character is "printable".
*
* Be advised that "printable" has a definition that goes back to text
* terminals from the dawn of computing, making this a sort of special case
* function that is not suitable for Unicode (or most any) text management.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* ' ' (0x20) through '~' (0x7E) as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
/**
* Report if a character is any "printable" except space.
*
* Be advised that "printable" has a definition that goes back to text
* terminals from the dawn of computing, making this a sort of special case
* function that is not suitable for Unicode (or most any) text management.
*
* **WARNING**: Regardless of system locale, this is equivalent to
* `(SDL_isprint(x)) && ((x) != ' ')`.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isprint
*/
extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
/**
* Convert low-ASCII English letters to uppercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'a' through 'z' to uppercase.
*
* This function returns the uppercase equivalent of `x`. If a character
* cannot be converted, or is already uppercase, this function returns `x`.
*
* \param x character value to check.
* \returns capitalized version of x, or x if no conversion available.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
/**
* Convert low-ASCII English letters to lowercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to lowercase.
*
* This function returns the lowercase equivalent of `x`. If a character
* cannot be converted, or is already lowercase, this function returns `x`.
*
* \param x character value to check.
* \returns lowercase version of x, or x if no conversion available.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
/**
* Calculate a CRC-16 value.
*
* https://en.wikipedia.org/wiki/Cyclic_redundancy_check
*
* This function can be called multiple times, to stream data to be
* checksummed in blocks. Each call must provide the previous CRC-16 return
* value to be updated with the next block. The first call to this function
* for a set of blocks should pass in a zero CRC value.
*
* \param crc the current checksum for this data set, or 0 for a new data set.
* \param data a new block of data to add to the checksum.
* \param len the size, in bytes, of the new block of data.
* \returns a CRC-16 checksum value of all blocks in the data set.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
/**
* Calculate a CRC-32 value.
*
* https://en.wikipedia.org/wiki/Cyclic_redundancy_check
*
* This function can be called multiple times, to stream data to be
* checksummed in blocks. Each call must provide the previous CRC-32 return
* value to be updated with the next block. The first call to this function
* for a set of blocks should pass in a zero CRC value.
*
* \param crc the current checksum for this data set, or 0 for a new data set.
* \param data a new block of data to add to the checksum.
* \param len the size, in bytes, of the new block of data.
* \returns a CRC-32 checksum value of all blocks in the data set.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
/**
* Calculate a 32-bit MurmurHash3 value for a block of data.
*
* https://en.wikipedia.org/wiki/MurmurHash
*
* A seed may be specified, which changes the final results consistently, but
* this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
* result from this function back into itself as the next seed value to
* calculate a hash in chunks; it won't produce the same hash as it would if
* the same data was provided in a single call.
*
* If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
* cryptographically secure, so it shouldn't be used for hashing top-secret
* data.
*
* \param data the data to be hashed.
* \param len the size of data, in bytes.
* \param seed a value that alters the final hash value.
* \returns a Murmur3 32-bit hash value.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
/**
* Copy non-overlapping memory.
*
* The memory regions must not overlap. If they do, use SDL_memmove() instead.
*
* \param dst The destination memory region. Must not be NULL, and must not
* overlap with `src`.
* \param src The source memory region. Must not be NULL, and must not overlap
* with `dst`.
* \param len The length in bytes of both `dst` and `src`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_memmove
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
/* Take advantage of compiler optimizations for memcpy */
#ifndef SDL_SLOW_MEMCPY
#ifdef SDL_memcpy
#undef SDL_memcpy
#endif
#define SDL_memcpy memcpy
#endif
/**
* A macro to copy memory between objects, with basic type checking.
*
* SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
* which can lead to bugs. This macro aims to avoid most of those bugs by
* making sure that the source and destination are both pointers to objects
* that are the same size. It does not check that the objects are the same
* _type_, just that the copy will not overflow either object.
*
* The size check happens at compile time, and the compiler will throw an
* error if the objects are different sizes.
*
* Generally this is intended to copy a single object, not an array.
*
* This macro looks like it double-evaluates its parameters, but the extras
* them are in `sizeof` sections, which generate no code nor side-effects.
*
* \param dst a pointer to the destination object. Must not be NULL.
* \param src a pointer to the source object. Must not be NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
#define SDL_copyp(dst, src) \
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))
/**
* Copy memory ranges that might overlap.
*
* It is okay for the memory regions to overlap. If you are confident that the
* regions never overlap, using SDL_memcpy() may improve performance.
*
* \param dst The destination memory region. Must not be NULL.
* \param src The source memory region. Must not be NULL.
* \param len The length in bytes of both `dst` and `src`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_memcpy
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
/* Take advantage of compiler optimizations for memmove */
#ifndef SDL_SLOW_MEMMOVE
#ifdef SDL_memmove
#undef SDL_memmove
#endif
#define SDL_memmove memmove
#endif
/**
* Initialize all bytes of buffer of memory to a specific value.
*
* This function will set `len` bytes, pointed to by `dst`, to the value
* specified in `c`.
*
* Despite `c` being an `int` instead of a `char`, this only operates on
* bytes; `c` must be a value between 0 and 255, inclusive.
*
* \param dst the destination memory region. Must not be NULL.
* \param c the byte value to set.
* \param len the length, in bytes, to set in `dst`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
/**
* Initialize all 32-bit words of buffer of memory to a specific value.
*
* This function will set a buffer of `dwords` Uint32 values, pointed to by
* `dst`, to the value specified in `val`.
*
* Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
* to a range of 0-255.
*
* \param dst the destination memory region. Must not be NULL.
* \param val the Uint32 value to set.
* \param dwords the number of Uint32 values to set in `dst`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
/* Take advantage of compiler optimizations for memset */
#ifndef SDL_SLOW_MEMSET
#ifdef SDL_memset
#undef SDL_memset
#endif
#define SDL_memset memset
#endif
/**
* Clear an object's memory to zero.
*
* This is wrapper over SDL_memset that handles calculating the object size,
* so there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires an object, not a pointer to an object, nor an array.
*
* \param x the object to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_zerop
* \sa SDL_zeroa
*/
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
/**
* Clear an object's memory to zero, using a pointer.
*
* This is wrapper over SDL_memset that handles calculating the object size,
* so there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires a pointer to an object, not an object itself, nor an array.
*
* \param x a pointer to the object to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_zero
* \sa SDL_zeroa
*/
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
/**
* Clear an array's memory to zero.
*
* This is wrapper over SDL_memset that handles calculating the array size, so
* there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires an array, not an object, nor a pointer to an object.
*
* \param x an array to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_zero
* \sa SDL_zerop
*/
#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
/**
* Compare two buffers of memory.
*
* \param s1 the first buffer to compare. NULL is not permitted!
* \param s2 the second buffer to compare. NULL is not permitted!
* \param len the number of bytes to compare between the buffers.
* \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
* "greater than" s2, and zero if the buffers match exactly for `len`
* bytes.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
/**
* This works exactly like wcslen() but doesn't require access to a C runtime.
*
* Counts the number of wchar_t values in `wstr`, excluding the null
* terminator.
*
* Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
* this counts wchar_t values in a string, even if the string's encoding is of
* variable width, like UTF-16.
*
* Also be aware that wchar_t is different sizes on different platforms (4
* bytes on Linux, 2 on Windows, etc).
*
* \param wstr The null-terminated wide string to read. Must not be NULL.
* \returns the length (in wchar_t values, excluding the null terminator) of
* `wstr`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_wcsnlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
/**
* This works exactly like wcsnlen() but doesn't require access to a C
* runtime.
*
* Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
* null terminator.
*
* Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
* this counts wchar_t values in a string, even if the string's encoding is of
* variable width, like UTF-16.
*
* Also be aware that wchar_t is different sizes on different platforms (4
* bytes on Linux, 2 on Windows, etc).
*
* Also, `maxlen` is a count of wide characters, not bytes!
*
* \param wstr The null-terminated wide string to read. Must not be NULL.
* \param maxlen The maximum amount of wide characters to count.
* \returns the length (in wide characters, excluding the null terminator) of
* `wstr` but never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_wcslen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
/**
* Copy a wide string.
*
* This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
* appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` is 0, no wide characters are copied and no null terminator is
* written.
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated wide string to copy. Must not be NULL, and
* must not overlap with `dst`.
* \param maxlen The length (in wide characters) of the destination buffer.
* \returns the length (in wide characters, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_wcslcat
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
/**
* Concatenate wide strings.
*
* This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
* from `src` to the end of the wide string in `dst`, then appends a null
* terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
* unmodified.
*
* \param dst The destination buffer already containing the first
* null-terminated wide string. Must not be NULL and must not
* overlap with `src`.
* \param src The second null-terminated wide string. Must not be NULL, and
* must not overlap with `dst`.
* \param maxlen The length (in wide characters) of the destination buffer.
* \returns the length (in wide characters, excluding the null terminator) of
* the string in `dst` plus the length of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_wcslcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
/**
* Allocate a copy of a wide string.
*
* This allocates enough space for a null-terminated copy of `wstr`, using
* SDL_malloc, and then makes a copy of the string into this space.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param wstr the string to copy.
* \returns a pointer to the newly-allocated wide string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
/**
* Search a wide string for the first instance of a specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string.
*
* Note that this looks for strings of _wide characters_, not _codepoints_, so
* it's legal to search for malformed and incomplete UTF-16 sequences.
*
* \param haystack the wide string to search. Must not be NULL.
* \param needle the wide string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
/**
* Search a wide string, up to n wide chars, for the first instance of a
* specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* value to end the string, or `maxlen` wide character have been examined. It
* is possible to use this function on a wide string without a null
* terminator.
*
* Note that this looks for strings of _wide characters_, not _codepoints_, so
* it's legal to search for malformed and incomplete UTF-16 sequences.
*
* \param haystack the wide string to search. Must not be NULL.
* \param needle the wide string to search for. Must not be NULL.
* \param maxlen the maximum number of wide characters to search in
* `haystack`.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
/**
* Compare two null-terminated wide strings.
*
* This only compares wchar_t values until it hits a null-terminating
* character; it does not care if the string is well-formed UTF-16 (or UTF-32,
* depending on your platform's wchar_t size), or uses valid Unicode values.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
/**
* Compare two wide strings up to a number of wchar_t values.
*
* This only compares wchar_t values; it does not care if the string is
* well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
* or uses valid Unicode values.
*
* Note that while this function is intended to be used with UTF-16 (or
* UTF-32, depending on your platform's definition of wchar_t), it is
* comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
* a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
* sequence, it will only compare a portion of the final character.
*
* `maxlen` specifies a maximum number of wchar_t to compare; if the strings
* match to this number of wide chars (or both have matched to a
* null-terminator character before this count), they will be considered
* equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of wchar_t to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
/**
* Compare two null-terminated wide strings, case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
* UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
* handles Unicode, it expects the string to be well-formed and not a
* null-terminated string of arbitrary bytes. Characters that are not valid
* UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
/**
* Compare two wide strings, case-insensitively, up to a number of wchar_t.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
* UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
* handles Unicode, it expects the string to be well-formed and not a
* null-terminated string of arbitrary bytes. Characters that are not valid
* UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* Note that while this function might deal with variable-sized characters,
* `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
* multi-byte UTF-16 sequence, it may convert a portion of the final character
* to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
* to overflow a buffer.
*
* `maxlen` specifies a maximum number of wchar_t values to compare; if the
* strings match to this number of wchar_t (or both have matched to a
* null-terminator character before this number of bytes), they will be
* considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of wchar_t values to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
/**
* Parse a `long` from a wide string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long`, the result is clamped to
* the minimum and maximum representable `long` values.
*
* \param str The null-terminated wide string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid wide character
* (i.e. the next character after the parsed number) will be
* written to this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strtol
*/
extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
/**
* This works exactly like strlen() but doesn't require access to a C runtime.
*
* Counts the bytes in `str`, excluding the null terminator.
*
* If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the length (in bytes, excluding the null terminator) of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strnlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
/**
* This works exactly like strnlen() but doesn't require access to a C
* runtime.
*
* Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
* terminator.
*
* If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
*
* \param str The null-terminated string to read. Must not be NULL.
* \param maxlen The maximum amount of bytes to count.
* \returns the length (in bytes, excluding the null terminator) of `src` but
* never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
/**
* Copy a string.
*
* This function copies up to `maxlen` - 1 characters from `src` to `dst`,
* then appends a null terminator.
*
* If `maxlen` is 0, no characters are copied and no null terminator is
* written.
*
* If you want to copy an UTF-8 string but need to ensure that multi-byte
* sequences are not truncated, consider using SDL_utf8strlcpy().
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated string to copy. Must not be NULL, and must
* not overlap with `dst`.
* \param maxlen The length (in characters) of the destination buffer.
* \returns the length (in characters, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strlcat
* \sa SDL_utf8strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
/**
* Copy an UTF-8 string.
*
* This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
* also ensuring that the string written to `dst` does not end in a truncated
* multi-byte sequence. Finally, it appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* Note that unlike SDL_strlcpy(), this function returns the number of bytes
* written, not the length of `src`.
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
* must not overlap with `dst`.
* \param dst_bytes The length (in bytes) of the destination buffer. Must not
* be 0.
* \returns the number of bytes written, excluding the null terminator.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
/**
* Concatenate strings.
*
* This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
* `src` to the end of the string in `dst`, then appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
* unmodified.
*
* \param dst The destination buffer already containing the first
* null-terminated string. Must not be NULL and must not overlap
* with `src`.
* \param src The second null-terminated string. Must not be NULL, and must
* not overlap with `dst`.
* \param maxlen The length (in characters) of the destination buffer.
* \returns the length (in characters, excluding the null terminator) of the
* string in `dst` plus the length of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
/**
* Allocate a copy of a string.
*
* This allocates enough space for a null-terminated copy of `str`, using
* SDL_malloc, and then makes a copy of the string into this space.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param str the string to copy.
* \returns a pointer to the newly-allocated string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
/**
* Allocate a copy of a string, up to n characters.
*
* This allocates enough space for a null-terminated copy of `str`, up to
* `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
* this space.
*
* If the string is longer than `maxlen` bytes, the returned string will be
* `maxlen` bytes long, plus a null-terminator character that isn't included
* in the count.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param str the string to copy.
* \param maxlen the maximum length of the copied string, not counting the
* null-terminator character.
* \returns a pointer to the newly-allocated string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
/**
* Reverse a string's contents.
*
* This reverses a null-terminated string in-place. Only the content of the
* string is reversed; the null-terminator character remains at the end of the
* reversed string.
*
* **WARNING**: This function reverses the _bytes_ of the string, not the
* codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
* will ruin the string data. You should only use this function on strings
* that are completely comprised of low ASCII characters.
*
* \param str the string to reverse.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
/**
* Convert a string to uppercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to uppercase.
*
* This function operates on a null-terminated string of bytes--even if it is
* malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
* uppercase equivalents in-place, returning the original `str` pointer.
*
* \param str the string to convert in-place. Can not be NULL.
* \returns the `str` pointer passed into this function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strlwr
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
/**
* Convert a string to lowercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to lowercase.
*
* This function operates on a null-terminated string of bytes--even if it is
* malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
* lowercase equivalents in-place, returning the original `str` pointer.
*
* \param str the string to convert in-place. Can not be NULL.
* \returns the `str` pointer passed into this function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_strupr
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
/**
* Search a string for the first instance of a specific byte.
*
* The search ends once it finds the requested byte value, or a null
* terminator byte to end the string.
*
* Note that this looks for _bytes_, not _characters_, so you cannot match
* against a Unicode codepoint > 255, regardless of character encoding.
*
* \param str the string to search. Must not be NULL.
* \param c the byte value to search for.
* \returns a pointer to the first instance of `c` in the string, or NULL if
* not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
/**
* Search a string for the last instance of a specific byte.
*
* The search must go until it finds a null terminator byte to end the string.
*
* Note that this looks for _bytes_, not _characters_, so you cannot match
* against a Unicode codepoint > 255, regardless of character encoding.
*
* \param str the string to search. Must not be NULL.
* \param c the byte value to search for.
* \returns a pointer to the last instance of `c` in the string, or NULL if
* not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
/**
* Search a string for the first instance of a specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string.
*
* Note that this looks for strings of _bytes_, not _characters_, so it's
* legal to search for malformed and incomplete UTF-8 sequences.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
/**
* Search a string, up to n bytes, for the first instance of a specific
* substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string, or `maxlen` bytes have been examined. It is
* possible to use this function on a string without a null terminator.
*
* Note that this looks for strings of _bytes_, not _characters_, so it's
* legal to search for malformed and incomplete UTF-8 sequences.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \param maxlen the maximum number of bytes to search in `haystack`.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
/**
* Search a UTF-8 string for the first instance of a specific substring,
* case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
/**
* This works exactly like strtok_r() but doesn't require access to a C
* runtime.
*
* Break a string up into a series of tokens.
*
* To start tokenizing a new string, `str` should be the non-NULL address of
* the string to start tokenizing. Future calls to get the next token from the
* same string should specify a NULL.
*
* Note that this function will overwrite pieces of `str` with null chars to
* split it into tokens. This function cannot be used with const/read-only
* strings!
*
* `saveptr` just needs to point to a `char *` that can be overwritten; SDL
* will use this to save tokenizing state between calls. It is initialized if
* `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
*
* \param str the string to tokenize, or NULL to continue tokenizing.
* \param delim the delimiter string that separates tokens.
* \param saveptr pointer to a char *, used for ongoing state.
* \returns A pointer to the next token, or NULL if no tokens remain.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
/**
* Count the number of codepoints in a UTF-8 string.
*
* Counts the _codepoints_, not _bytes_, in `str`, excluding the null
* terminator.
*
* If you need to count the bytes in a string instead, consider using
* SDL_strlen().
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
* count by several replacement characters.
*
* \param str The null-terminated UTF-8 string to read. Must not be NULL.
* \returns The length (in codepoints, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_utf8strnlen
* \sa SDL_strlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
/**
* Count the number of codepoints in a UTF-8 string, up to n bytes.
*
* Counts the _codepoints_, not _bytes_, in `str`, excluding the null
* terminator.
*
* If you need to count the bytes in a string instead, consider using
* SDL_strnlen().
*
* The counting stops at `bytes` bytes (not codepoints!). This seems
* counterintuitive, but makes it easy to express the total size of the
* string's buffer.
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
* count by several replacement characters.
*
* \param str The null-terminated UTF-8 string to read. Must not be NULL.
* \param bytes The maximum amount of bytes to count.
* \returns The length (in codepoints, excluding the null terminator) of `src`
* but never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_utf8strlen
* \sa SDL_strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
/**
* Convert an integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_uitoa
* \sa SDL_ltoa
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
/**
* Convert an unsigned integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_itoa
* \sa SDL_ultoa
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
/**
* Convert a long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ultoa
* \sa SDL_itoa
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
/**
* Convert an unsigned long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ltoa
* \sa SDL_uitoa
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
#ifndef SDL_NOLONGLONG
/**
* Convert a long long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the long long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ulltoa
* \sa SDL_itoa
* \sa SDL_ltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
/**
* Convert an unsigned long long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned long long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_lltoa
* \sa SDL_uitoa
* \sa SDL_ultoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
#endif
/**
* Parse an `int` from a string.
*
* The result of calling `SDL_atoi(str)` is equivalent to
* `(int)SDL_strtol(str, NULL, 10)`.
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the parsed `int`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_itoa
*/
extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
/**
* Parse a `double` from a string.
*
* The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
* NULL)`.
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the parsed `double`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
*/
extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
/**
* Parse a `long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long`, the result is clamped to
* the minimum and maximum representable `long` values.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_ltoa
* \sa SDL_wcstol
*/
extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
/**
* Parse an `unsigned long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside an `unsigned long`, the result is
* clamped to the maximum representable `unsigned long` value.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `unsigned long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_ultoa
*/
extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
#ifndef SDL_NOLONGLONG
/**
* Parse a `long long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long long`, the result is
* clamped to the minimum and maximum representable `long long` values.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
/**
* Parse an `unsigned long long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside an `unsigned long long`, the
* result is clamped to the maximum representable `unsigned long long` value.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `unsigned long long`, or 0 if no number could be
* parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoul
* \sa SDL_strtod
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
#endif
/**
* Parse a `double` from a string.
*
* This function makes fewer guarantees than the C runtime `strtod`:
*
* - Only decimal notation is guaranteed to be supported. The handling of
* scientific and hexadecimal notation is unspecified.
* - Whether or not INF and NAN can be parsed is unspecified.
* - The precision of the result is unspecified.
*
* \param str the null-terminated string to read. Must not be NULL.
* \param endp if not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \returns the parsed `double`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoul
* \sa SDL_strtoull
*/
extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
/**
* Compare two null-terminated UTF-8 strings.
*
* Due to the nature of UTF-8 encoding, this will work with Unicode strings,
* since effectively this function just compares bytes until it hits a
* null-terminating character. Also due to the nature of UTF-8, this can be
* used with SDL_qsort() to put strings in (roughly) alphabetical order.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
/**
* Compare two UTF-8 strings up to a number of bytes.
*
* Due to the nature of UTF-8 encoding, this will work with Unicode strings,
* since effectively this function just compares bytes until it hits a
* null-terminating character. Also due to the nature of UTF-8, this can be
* used with SDL_qsort() to put strings in (roughly) alphabetical order.
*
* Note that while this function is intended to be used with UTF-8, it is
* doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
* limit lands in the middle of a multi-byte UTF-8 sequence, it will only
* compare a portion of the final character.
*
* `maxlen` specifies a maximum number of bytes to compare; if the strings
* match to this number of bytes (or both have matched to a null-terminator
* character before this number of bytes), they will be considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of _bytes_ to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
/**
* Compare two null-terminated UTF-8 strings, case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the string to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
/**
* Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the string to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* Note that while this function is intended to be used with UTF-8, `maxlen`
* specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
* UTF-8 sequence, it may convert a portion of the final character to one or
* more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
* a buffer.
*
* `maxlen` specifies a maximum number of bytes to compare; if the strings
* match to this number of bytes (or both have matched to a null-terminator
* character before this number of bytes), they will be considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of bytes to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
/**
* Searches a string for the first occurrence of any character contained in a
* breakset, and returns a pointer from the string to that character.
*
* \param str The null-terminated string to be searched. Must not be NULL, and
* must not overlap with `breakset`.
* \param breakset A null-terminated string containing the list of characters
* to look for. Must not be NULL, and must not overlap with
* `str`.
* \returns A pointer to the location, in str, of the first occurrence of a
* character present in the breakset, or NULL if none is found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
/**
* The Unicode REPLACEMENT CHARACTER codepoint.
*
* SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
* encounter a UTF-8 string with encoding errors.
*
* This tends to render as something like a question mark in most places.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_StepBackUTF8
* \sa SDL_StepUTF8
*/
#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
/**
* Decode a UTF-8 string, one Unicode codepoint at a time.
*
* This will return the first Unicode codepoint in the UTF-8 encoded string in
* `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
*
* It will not access more than `*pslen` bytes from the string. `*pslen` will
* be adjusted, as well, subtracting the number of bytes consumed.
*
* `pslen` is allowed to be NULL, in which case the string _must_ be
* NULL-terminated, as the function will blindly read until it sees the NULL
* char.
*
* if `*pslen` is zero, it assumes the end of string is reached and returns a
* zero codepoint regardless of the contents of the string buffer.
*
* If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
* zero, it will not advance `*pstr` or `*pslen` at all.
*
* Generally this function is called in a loop until it returns zero,
* adjusting its parameters each iteration.
*
* If an invalid UTF-8 sequence is encountered, this function returns
* SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
* (which is to say, a multibyte sequence might produce several
* SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
* UTF-8 sequence).
*
* Several things can generate invalid UTF-8 sequences, including overlong
* encodings, the use of UTF-16 surrogate values, and truncated data. Please
* refer to
* [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
* for details.
*
* \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
* \param pslen a pointer to the number of bytes in the string, to be read and
* adjusted. NULL is allowed.
* \returns the first Unicode codepoint in the string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
/**
* Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
*
* This will go to the start of the previous Unicode codepoint in the string,
* move `*pstr` to that location and return that codepoint.
*
* If `*pstr` is already at the start of the string), it will not advance
* `*pstr` at all.
*
* Generally this function is called in a loop until it returns zero,
* adjusting its parameter each iteration.
*
* If an invalid UTF-8 sequence is encountered, this function returns
* SDL_INVALID_UNICODE_CODEPOINT.
*
* Several things can generate invalid UTF-8 sequences, including overlong
* encodings, the use of UTF-16 surrogate values, and truncated data. Please
* refer to
* [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
* for details.
*
* \param start a pointer to the beginning of the UTF-8 string.
* \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
* \returns the previous Unicode codepoint in the string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
/**
* Convert a single Unicode codepoint to UTF-8.
*
* The buffer pointed to by `dst` must be at least 4 bytes long, as this
* function may generate between 1 and 4 bytes of output.
*
* This function returns the first byte _after_ the newly-written UTF-8
* sequence, which is useful for encoding multiple codepoints in a loop, or
* knowing where to write a NULL-terminator character to end the string (in
* either case, plan to have a buffer of _more_ than 4 bytes!).
*
* If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
* surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
* codepoint instead, and not set an error.
*
* If `dst` is NULL, this returns NULL immediately without writing to the
* pointer and without setting an error.
*
* \param codepoint a Unicode codepoint to convert to UTF-8.
* \param dst the location to write the encoded UTF-8. Must point to at least
* 4 bytes!
* \returns the first byte past the newly-written UTF-8 sequence.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
/**
* This works exactly like sscanf() but doesn't require access to a C runtime.
*
* Scan a string, matching a format string, converting each '%' item and
* storing it to pointers provided through variable arguments.
*
* \param text the string to scan. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of pointers to values to be filled in with scanned items.
* \returns the number of items that matched the format string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
/**
* This works exactly like vsscanf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_sscanf(), except it takes a `va_list` instead
* of using `...` variable arguments.
*
* \param text the string to scan. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` of pointers to values to be filled in with scanned
* items.
* \returns the number of items that matched the format string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
/**
* This works exactly like snprintf() but doesn't require access to a C
* runtime.
*
* Format a string of up to `maxlen`-1 bytes, converting each '%' item with
* values provided through variable arguments.
*
* While some C runtimes differ on how to deal with too-large strings, this
* function null-terminates the output, by treating the null-terminator as
* part of the `maxlen` count. Note that if `maxlen` is zero, however, no
* bytes will be written at all.
*
* This function returns the number of _bytes_ (not _characters_) that should
* be written, excluding the null-terminator character. If this returns a
* number >= `maxlen`, it means the output string was truncated. A negative
* return value means an error occurred.
*
* Referencing the output string's pointer with a format item is undefined
* behavior.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum bytes to write, including the null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of bytes that should be written, not counting the
* null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
/**
* This works exactly like swprintf() but doesn't require access to a C
* runtime.
*
* Format a wide string of up to `maxlen`-1 wchar_t values, converting each
* '%' item with values provided through variable arguments.
*
* While some C runtimes differ on how to deal with too-large strings, this
* function null-terminates the output, by treating the null-terminator as
* part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
* characters will be written at all.
*
* This function returns the number of _wide characters_ (not _codepoints_)
* that should be written, excluding the null-terminator character. If this
* returns a number >= `maxlen`, it means the output string was truncated. A
* negative return value means an error occurred.
*
* Referencing the output string's pointer with a format item is undefined
* behavior.
*
* \param text the buffer to write the wide string into. Must not be NULL.
* \param maxlen the maximum wchar_t values to write, including the
* null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of wide characters that should be written, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(3);
/**
* This works exactly like vsnprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_snprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum bytes to write, including the null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of bytes that should be written, not counting the
* null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
/**
* This works exactly like vswprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_swprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum wide characters to write, including the
* null-terminator.
* \param fmt a printf-style format wide string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of wide characters that should be written, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3);
/**
* This works exactly like asprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_snprintf(), except it allocates a buffer large
* enough to hold the output string on behalf of the caller.
*
* On success, this function returns the number of bytes (not characters)
* comprising the output string, not counting the null-terminator character,
* and sets `*strp` to the newly-allocated string.
*
* On error, this function returns a negative number, and the value of `*strp`
* is undefined.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param strp on output, is set to the new string. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of bytes in the newly-allocated string, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/**
* This works exactly like vasprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_asprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param strp on output, is set to the new string. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of bytes in the newly-allocated string, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
/**
* Seeds the pseudo-random number generator.
*
* Reusing the seed number will cause SDL_rand() to repeat the same stream of
* 'random' numbers.
*
* \param seed the value to use as a random number seed, or 0 to use
* SDL_GetPerformanceCounter().
*
* \threadsafety This should be called on the same thread that calls
* SDL_rand()
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_rand
* \sa SDL_rand_bits
* \sa SDL_randf
*/
extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
/**
* Generate a pseudo-random number less than n for positive n
*
* The method used is faster and of better quality than `rand() % n`. Odds are
* roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
* much worse as n gets bigger.
*
* Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
* 1..6
*
* If you want to generate a pseudo-random number in the full range of Sint32,
* you should use: (Sint32)SDL_rand_bits()
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param n the number of possible outcomes. n must be positive.
* \returns a random value in the range of [0 .. n-1].
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_srand
* \sa SDL_randf
*/
extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
/**
* Generate a uniform pseudo-random floating point number less than 1.0
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \returns a random value in the range of [0.0, 1.0).
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_srand
* \sa SDL_rand
*/
extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
/**
* Generate 32 pseudo-random bits.
*
* You likely want to use SDL_rand() to get a psuedo-random number instead.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \returns a random value in the range of [0-SDL_MAX_UINT32].
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_rand
* \sa SDL_randf
* \sa SDL_srand
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
/**
* Generate a pseudo-random number less than n for positive n
*
* The method used is faster and of better quality than `rand() % n`. Odds are
* roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
* much worse as n gets bigger.
*
* Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
* 0..5 to 1..6
*
* If you want to generate a pseudo-random number in the full range of Sint32,
* you should use: (Sint32)SDL_rand_bits_r(state)
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \param n the number of possible outcomes. n must be positive.
* \returns a random value in the range of [0 .. n-1].
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_rand
* \sa SDL_rand_bits_r
* \sa SDL_randf_r
*/
extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
/**
* Generate a uniform pseudo-random floating point number less than 1.0
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \returns a random value in the range of [0.0, 1.0).
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_rand_bits_r
* \sa SDL_rand_r
* \sa SDL_randf
*/
extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
/**
* Generate 32 pseudo-random bits.
*
* You likely want to use SDL_rand_r() to get a psuedo-random number instead.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \returns a random value in the range of [0-SDL_MAX_UINT32].
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_rand_r
* \sa SDL_randf_r
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
#ifndef SDL_PI_D
/**
* The value of Pi, as a double-precision floating point literal.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PI_F
*/
#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
#endif
#ifndef SDL_PI_F
/**
* The value of Pi, as a single-precision floating point literal.
*
* \since This macro is available since SDL 3.2.0.
*
* \sa SDL_PI_D
*/
#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
#endif
/**
* Compute the arc cosine of `x`.
*
* The definition of `y = acos(x)` is `x = cos(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `0 <= y <= Pi`
*
* This function operates on double-precision floating point values, use
* SDL_acosf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc cosine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_acosf
* \sa SDL_asin
* \sa SDL_cos
*/
extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
/**
* Compute the arc cosine of `x`.
*
* The definition of `y = acos(x)` is `x = cos(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `0 <= y <= Pi`
*
* This function operates on single-precision floating point values, use
* SDL_acos for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc cosine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_acos
* \sa SDL_asinf
* \sa SDL_cosf
*/
extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
/**
* Compute the arc sine of `x`.
*
* The definition of `y = asin(x)` is `x = sin(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on double-precision floating point values, use
* SDL_asinf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc sine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_asinf
* \sa SDL_acos
* \sa SDL_sin
*/
extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
/**
* Compute the arc sine of `x`.
*
* The definition of `y = asin(x)` is `x = sin(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on single-precision floating point values, use
* SDL_asin for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc sine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_asin
* \sa SDL_acosf
* \sa SDL_sinf
*/
extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
/**
* Compute the arc tangent of `x`.
*
* The definition of `y = atan(x)` is `x = tan(y)`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on double-precision floating point values, use
* SDL_atanf for single-precision floats.
*
* To calculate the arc tangent of y / x, use SDL_atan2.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atanf
* \sa SDL_atan2
* \sa SDL_tan
*/
extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
/**
* Compute the arc tangent of `x`.
*
* The definition of `y = atan(x)` is `x = tan(y)`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on single-precision floating point values, use
* SDL_atan for dboule-precision floats.
*
* To calculate the arc tangent of y / x, use SDL_atan2f.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atan
* \sa SDL_atan2f
* \sa SDL_tanf
*/
extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
/**
* Compute the arc tangent of `y / x`, using the signs of x and y to adjust
* the result's quadrant.
*
* The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
* of z is determined based on the signs of x and y.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-Pi <= y <= Pi`
*
* This function operates on double-precision floating point values, use
* SDL_atan2f for single-precision floats.
*
* To calculate the arc tangent of a single value, use SDL_atan.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param y floating point value of the numerator (y coordinate).
* \param x floating point value of the denominator (x coordinate).
* \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
* `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atan2f
* \sa SDL_atan
* \sa SDL_tan
*/
extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
/**
* Compute the arc tangent of `y / x`, using the signs of x and y to adjust
* the result's quadrant.
*
* The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
* of z is determined based on the signs of x and y.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-Pi <= y <= Pi`
*
* This function operates on single-precision floating point values, use
* SDL_atan2 for double-precision floats.
*
* To calculate the arc tangent of a single value, use SDL_atanf.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param y floating point value of the numerator (y coordinate).
* \param x floating point value of the denominator (x coordinate).
* \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
* `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_atan2
* \sa SDL_atan
* \sa SDL_tan
*/
extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
/**
* Compute the ceiling of `x`.
*
* The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_ceilf for single-precision floats.
*
* \param x floating point value.
* \returns the ceiling of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ceilf
* \sa SDL_floor
* \sa SDL_trunc
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
/**
* Compute the ceiling of `x`.
*
* The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_ceil for double-precision floats.
*
* \param x floating point value.
* \returns the ceiling of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_ceil
* \sa SDL_floorf
* \sa SDL_truncf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
/**
* Copy the sign of one floating-point value to another.
*
* The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
*
* Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
*
* Range: `-INF <= z <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_copysignf for single-precision floats.
*
* \param x floating point value to use as the magnitude.
* \param y floating point value to use as the sign.
* \returns the floating point value with the sign of y and the magnitude of
* x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_copysignf
* \sa SDL_fabs
*/
extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
/**
* Copy the sign of one floating-point value to another.
*
* The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
*
* Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
*
* Range: `-INF <= z <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_copysign for double-precision floats.
*
* \param x floating point value to use as the magnitude.
* \param y floating point value to use as the sign.
* \returns the floating point value with the sign of y and the magnitude of
* x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_copysign
* \sa SDL_fabsf
*/
extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
/**
* Compute the cosine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on double-precision floating point values, use
* SDL_cosf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns cosine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_cosf
* \sa SDL_acos
* \sa SDL_sin
*/
extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
/**
* Compute the cosine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on single-precision floating point values, use
* SDL_cos for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns cosine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_cos
* \sa SDL_acosf
* \sa SDL_sinf
*/
extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
/**
* Compute the exponential of `x`.
*
* The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
* natural logarithm. The inverse is the natural logarithm, SDL_log.
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* The output will overflow if `exp(x)` is too large to be represented.
*
* This function operates on double-precision floating point values, use
* SDL_expf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns value of `e^x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_expf
* \sa SDL_log
*/
extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
/**
* Compute the exponential of `x`.
*
* The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
* natural logarithm. The inverse is the natural logarithm, SDL_logf.
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* The output will overflow if `exp(x)` is too large to be represented.
*
* This function operates on single-precision floating point values, use
* SDL_exp for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns value of `e^x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_exp
* \sa SDL_logf
*/
extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
/**
* Compute the absolute value of `x`
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_fabsf for single-precision floats.
*
* \param x floating point value to use as the magnitude.
* \returns the absolute value of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_fabsf
*/
extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
/**
* Compute the absolute value of `x`
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_fabs for double-precision floats.
*
* \param x floating point value to use as the magnitude.
* \returns the absolute value of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_fabs
*/
extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
/**
* Compute the floor of `x`.
*
* The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_floorf for single-precision floats.
*
* \param x floating point value.
* \returns the floor of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_floorf
* \sa SDL_ceil
* \sa SDL_trunc
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
/**
* Compute the floor of `x`.
*
* The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_floor for double-precision floats.
*
* \param x floating point value.
* \returns the floor of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_floor
* \sa SDL_ceilf
* \sa SDL_truncf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
/**
* Truncate `x` to an integer.
*
* Rounds `x` to the next closest integer to 0. This is equivalent to removing
* the fractional part of `x`, leaving only the integer part.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_truncf for single-precision floats.
*
* \param x floating point value.
* \returns `x` truncated to an integer.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_truncf
* \sa SDL_fmod
* \sa SDL_ceil
* \sa SDL_floor
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
/**
* Truncate `x` to an integer.
*
* Rounds `x` to the next closest integer to 0. This is equivalent to removing
* the fractional part of `x`, leaving only the integer part.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_trunc for double-precision floats.
*
* \param x floating point value.
* \returns `x` truncated to an integer.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_trunc
* \sa SDL_fmodf
* \sa SDL_ceilf
* \sa SDL_floorf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
/**
* Return the floating-point remainder of `x / y`
*
* Divides `x` by `y`, and returns the remainder.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
*
* Range: `-y <= z <= y`
*
* This function operates on double-precision floating point values, use
* SDL_fmodf for single-precision floats.
*
* \param x the numerator.
* \param y the denominator. Must not be 0.
* \returns the remainder of `x / y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_fmodf
* \sa SDL_modf
* \sa SDL_trunc
* \sa SDL_ceil
* \sa SDL_floor
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
/**
* Return the floating-point remainder of `x / y`
*
* Divides `x` by `y`, and returns the remainder.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
*
* Range: `-y <= z <= y`
*
* This function operates on single-precision floating point values, use
* SDL_fmod for double-precision floats.
*
* \param x the numerator.
* \param y the denominator. Must not be 0.
* \returns the remainder of `x / y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_fmod
* \sa SDL_truncf
* \sa SDL_modff
* \sa SDL_ceilf
* \sa SDL_floorf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
/**
* Return whether the value is infinity.
*
* \param x double-precision floating point value.
* \returns non-zero if the value is infinity, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isinff
*/
extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
/**
* Return whether the value is infinity.
*
* \param x floating point value.
* \returns non-zero if the value is infinity, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isinf
*/
extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
/**
* Return whether the value is NaN.
*
* \param x double-precision floating point value.
* \returns non-zero if the value is NaN, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isnanf
*/
extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
/**
* Return whether the value is NaN.
*
* \param x floating point value.
* \returns non-zero if the value is NaN, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_isnan
*/
extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
/**
* Compute the natural logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on double-precision floating point values, use
* SDL_logf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the natural logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_logf
* \sa SDL_log10
* \sa SDL_exp
*/
extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
/**
* Compute the natural logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on single-precision floating point values, use
* SDL_log for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the natural logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_log
* \sa SDL_expf
*/
extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
/**
* Compute the base-10 logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on double-precision floating point values, use
* SDL_log10f for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_log10f
* \sa SDL_log
* \sa SDL_pow
*/
extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
/**
* Compute the base-10 logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on single-precision floating point values, use
* SDL_log10 for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_log10
* \sa SDL_logf
* \sa SDL_powf
*/
extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
/**
* Split `x` into integer and fractional parts
*
* This function operates on double-precision floating point values, use
* SDL_modff for single-precision floats.
*
* \param x floating point value.
* \param y output pointer to store the integer part of `x`.
* \returns the fractional part of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_modff
* \sa SDL_trunc
* \sa SDL_fmod
*/
extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
/**
* Split `x` into integer and fractional parts
*
* This function operates on single-precision floating point values, use
* SDL_modf for double-precision floats.
*
* \param x floating point value.
* \param y output pointer to store the integer part of `x`.
* \returns the fractional part of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_modf
* \sa SDL_truncf
* \sa SDL_fmodf
*/
extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
/**
* Raise `x` to the power `y`
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-INF <= z <= INF`
*
* If `y` is the base of the natural logarithm (e), consider using SDL_exp
* instead.
*
* This function operates on double-precision floating point values, use
* SDL_powf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x the base.
* \param y the exponent.
* \returns `x` raised to the power `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_powf
* \sa SDL_exp
* \sa SDL_log
*/
extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
/**
* Raise `x` to the power `y`
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-INF <= z <= INF`
*
* If `y` is the base of the natural logarithm (e), consider using SDL_exp
* instead.
*
* This function operates on single-precision floating point values, use
* SDL_pow for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x the base.
* \param y the exponent.
* \returns `x` raised to the power `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_pow
* \sa SDL_expf
* \sa SDL_logf
*/
extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
/**
* Round `x` to the nearest integer.
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_roundf for single-precision floats. To get the result as an integer
* type, use SDL_lround.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_roundf
* \sa SDL_lround
* \sa SDL_floor
* \sa SDL_ceil
* \sa SDL_trunc
*/
extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
/**
* Round `x` to the nearest integer.
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_round for double-precision floats. To get the result as an integer
* type, use SDL_lroundf.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_round
* \sa SDL_lroundf
* \sa SDL_floorf
* \sa SDL_ceilf
* \sa SDL_truncf
*/
extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
/**
* Round `x` to the nearest integer representable as a long
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `MIN_LONG <= y <= MAX_LONG`
*
* This function operates on double-precision floating point values, use
* SDL_lroundf for single-precision floats. To get the result as a
* floating-point type, use SDL_round.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_lroundf
* \sa SDL_round
* \sa SDL_floor
* \sa SDL_ceil
* \sa SDL_trunc
*/
extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
/**
* Round `x` to the nearest integer representable as a long
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `MIN_LONG <= y <= MAX_LONG`
*
* This function operates on single-precision floating point values, use
* SDL_lround for double-precision floats. To get the result as a
* floating-point type, use SDL_roundf.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_lround
* \sa SDL_roundf
* \sa SDL_floorf
* \sa SDL_ceilf
* \sa SDL_truncf
*/
extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
/**
* Scale `x` by an integer power of two.
*
* Multiplies `x` by the `n`th power of the floating point radix (always 2).
*
* Domain: `-INF <= x <= INF`, `n` integer
*
* Range: `-INF <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_scalbnf for single-precision floats.
*
* \param x floating point value to be scaled.
* \param n integer exponent.
* \returns `x * 2^n`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_scalbnf
* \sa SDL_pow
*/
extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
/**
* Scale `x` by an integer power of two.
*
* Multiplies `x` by the `n`th power of the floating point radix (always 2).
*
* Domain: `-INF <= x <= INF`, `n` integer
*
* Range: `-INF <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_scalbn for double-precision floats.
*
* \param x floating point value to be scaled.
* \param n integer exponent.
* \returns `x * 2^n`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_scalbn
* \sa SDL_powf
*/
extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
/**
* Compute the sine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on double-precision floating point values, use
* SDL_sinf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns sine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_sinf
* \sa SDL_asin
* \sa SDL_cos
*/
extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
/**
* Compute the sine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on single-precision floating point values, use
* SDL_sin for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns sine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_sin
* \sa SDL_asinf
* \sa SDL_cosf
*/
extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
/**
* Compute the square root of `x`.
*
* Domain: `0 <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_sqrtf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than or equal to 0.
* \returns square root of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_sqrtf
*/
extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
/**
* Compute the square root of `x`.
*
* Domain: `0 <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_sqrt for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than or equal to 0.
* \returns square root of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_sqrt
*/
extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
/**
* Compute the tangent of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_tanf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns tangent of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_tanf
* \sa SDL_sin
* \sa SDL_cos
* \sa SDL_atan
* \sa SDL_atan2
*/
extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
/**
* Compute the tangent of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_tan for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns tangent of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_tan
* \sa SDL_sinf
* \sa SDL_cosf
* \sa SDL_atanf
* \sa SDL_atan2f
*/
extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
/**
* An opaque handle representing string encoding conversion state.
*
* \since This datatype is available since SDL 3.2.0.
*
* \sa SDL_iconv_open
*/
typedef struct SDL_iconv_data_t *SDL_iconv_t;
/**
* This function allocates a context for the specified character set
* conversion.
*
* \param tocode The target character encoding, must not be NULL.
* \param fromcode The source character encoding, must not be NULL.
* \returns a handle that must be freed with SDL_iconv_close, or
* SDL_ICONV_ERROR on failure.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv
* \sa SDL_iconv_close
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
const char *fromcode);
/**
* This function frees a context used for character set conversion.
*
* \param cd The character set conversion handle.
* \returns 0 on success, or -1 on failure.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv
* \sa SDL_iconv_open
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
/**
* This function converts text between encodings, reading from and writing to
* a buffer.
*
* It returns the number of successful conversions on success. On error,
* SDL_ICONV_E2BIG is returned when the output buffer is too small, or
* SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
* or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
* encountered.
*
* On exit:
*
* - inbuf will point to the beginning of the next multibyte sequence. On
* error, this is the location of the problematic input sequence. On
* success, this is the end of the input sequence.
* - inbytesleft will be set to the number of bytes left to convert, which
* will be 0 on success.
* - outbuf will point to the location where to store the next output byte.
* - outbytesleft will be set to the number of bytes left in the output
* buffer.
*
* \param cd The character set conversion context, created in
* SDL_iconv_open().
* \param inbuf Address of variable that points to the first character of the
* input sequence.
* \param inbytesleft The number of bytes in the input buffer.
* \param outbuf Address of variable that points to the output buffer.
* \param outbytesleft The number of bytes in the output buffer.
* \returns the number of conversions on success, or a negative error code.
*
* \threadsafety Do not use the same SDL_iconv_t from two threads at once.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv_open
* \sa SDL_iconv_close
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
size_t *inbytesleft, char **outbuf,
size_t *outbytesleft);
#define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
#define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
#define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
#define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
/**
* Helper function to convert a string's encoding in one call.
*
* This function converts a buffer or string between encodings in one pass.
*
* The string does not need to be NULL-terminated; this function operates on
* the number of bytes specified in `inbytesleft` whether there is a NULL
* character anywhere in the buffer.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param tocode the character encoding of the output string. Examples are
* "UTF-8", "UCS-4", etc.
* \param fromcode the character encoding of data in `inbuf`.
* \param inbuf the string to convert to a different encoding.
* \param inbytesleft the size of the input string _in bytes_.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_iconv_open
* \sa SDL_iconv_close
* \sa SDL_iconv
*/
extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
const char *fromcode,
const char *inbuf,
size_t inbytesleft);
/* Some helper macros for common SDL_iconv_string cases... */
/**
* Convert a UTF-8 string to the current locale's character encoding.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
/**
* Convert a UTF-8 string to UCS-2.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_ucs2(S) SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
/**
* Convert a UTF-8 string to UCS-4.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_utf8_ucs4(S) SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
/**
* Convert a wchar_t string to UTF-8.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.2.0.
*/
#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", SDL_reinterpret_cast(const char *, S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
/* force builds using Clang's static analysis tools to use literal C runtime
here, since there are possibly tests that are ineffective otherwise. */
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
/* The analyzer knows about strlcpy even when the system doesn't provide it */
#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
size_t strlcpy(char *dst, const char *src, size_t size);
#endif
/* The analyzer knows about strlcat even when the system doesn't provide it */
#if !defined(HAVE_STRLCAT) && !defined(strlcat)
size_t strlcat(char *dst, const char *src, size_t size);
#endif
#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
#endif
#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
#endif
#if !defined(HAVE_STRTOK_R) && !defined(strtok_r)
char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
#ifndef _WIN32
/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
/* not for windows: might conflict with string.h where strdup may have
* dllimport attribute: https://github.com/libsdl-org/SDL/issues/12948 */
char *strdup(const char *str);
#endif
/* Starting LLVM 16, the analyser errors out if these functions do not have
their prototype defined (clang-diagnostic-implicit-function-declaration) */
#include <stdio.h>
#include <stdlib.h>
#define SDL_malloc malloc
#define SDL_calloc calloc
#define SDL_realloc realloc
#define SDL_free free
#ifndef SDL_memcpy
#define SDL_memcpy memcpy
#endif
#ifndef SDL_memmove
#define SDL_memmove memmove
#endif
#ifndef SDL_memset
#define SDL_memset memset
#endif
#define SDL_memcmp memcmp
#define SDL_strlcpy strlcpy
#define SDL_strlcat strlcat
#define SDL_strlen strlen
#define SDL_wcslen wcslen
#define SDL_wcslcpy wcslcpy
#define SDL_wcslcat wcslcat
#define SDL_strdup strdup
#define SDL_wcsdup wcsdup
#define SDL_strchr strchr
#define SDL_strrchr strrchr
#define SDL_strstr strstr
#define SDL_wcsstr wcsstr
#define SDL_strtok_r strtok_r
#define SDL_strcmp strcmp
#define SDL_wcscmp wcscmp
#define SDL_strncmp strncmp
#define SDL_wcsncmp wcsncmp
#define SDL_strcasecmp strcasecmp
#define SDL_strncasecmp strncasecmp
#define SDL_strpbrk strpbrk
#define SDL_sscanf sscanf
#define SDL_vsscanf vsscanf
#define SDL_snprintf snprintf
#define SDL_vsnprintf vsnprintf
#endif
/**
* Multiply two integers, checking for overflow.
*
* If `a * b` would overflow, return false.
*
* Otherwise store `a * b` via ret and return true.
*
* \param a the multiplicand.
* \param b the multiplier.
* \param ret on non-overflow output, stores the multiplication result, may
* not be NULL.
* \returns false on overflow, true if result is multiplied without overflow.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
{
if (a != 0 && b > SDL_SIZE_MAX / a) {
return false;
}
*ret = a * b;
return true;
}
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
/* This needs to be wrapped in an inline rather than being a direct #define,
* because __builtin_mul_overflow() is type-generic, but we want to be
* consistent about interpreting a and b as size_t. */
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
{
return (__builtin_mul_overflow(a, b, ret) == 0);
}
#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
#endif
#endif
/**
* Add two integers, checking for overflow.
*
* If `a + b` would overflow, return false.
*
* Otherwise store `a + b` via ret and return true.
*
* \param a the first addend.
* \param b the second addend.
* \param ret on non-overflow output, stores the addition result, may not be
* NULL.
* \returns false on overflow, true if result is added without overflow.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
{
if (b > SDL_SIZE_MAX - a) {
return false;
}
*ret = a + b;
return true;
}
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if SDL_HAS_BUILTIN(__builtin_add_overflow)
/* This needs to be wrapped in an inline rather than being a direct #define,
* the same as the call to __builtin_mul_overflow() above. */
SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
{
return (__builtin_add_overflow(a, b, ret) == 0);
}
#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
#endif
#endif
/* This is a generic function pointer which should be cast to the type you expect */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A generic function pointer.
*
* In theory, generic function pointers should use this, instead of `void *`,
* since some platforms could treat code addresses differently than data
* addresses. Although in current times no popular platforms make this
* distinction, it is more correct and portable to use the correct type for a
* generic pointer.
*
* If for some reason you need to force this typedef to be an actual `void *`,
* perhaps to work around a compiler or existing code, you can define
* `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
*
* \since This datatype is available since SDL 3.2.0.
*/
typedef void (*SDL_FunctionPointer)(void);
#elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
typedef void *SDL_FunctionPointer;
#else
typedef void (*SDL_FunctionPointer)(void);
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_stdinc_h_ */
|