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
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by Michael Van Canneyt,
BSD parts (c) 2000 by Marco van de Voort
members of the Free Pascal development team.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit oldlinux deprecated 'Use Baseunix/Unix';
Interface
Const
{ Things for LSEEK call }
Seek_set = 0;
Seek_Cur = 1;
Seek_End = 2;
{ Things for OPEN call - after linux/fcntl.h }
Open_Accmode = 3;
Open_RdOnly = 0;
Open_WrOnly = 1;
Open_RdWr = 2;
Open_Creat = 1 shl 6;
Open_Excl = 2 shl 6;
Open_NoCtty = 4 shl 6;
Open_Trunc = 1 shl 9;
Open_Append = 2 shl 9;
Open_NonBlock = 4 shl 9;
Open_NDelay = Open_NonBlock;
Open_Sync = 1 shl 12;
Open_Direct = 4 shl 12;
Open_LargeFile = 1 shl 15;
Open_Directory = 2 shl 15;
Open_NoFollow = 4 shl 15;
{ The waitpid uses the following options:}
Wait_NoHang = 1;
Wait_UnTraced = 2;
Wait_Any = -1;
Wait_MyPGRP = 0;
Wait_Clone = $80000000;
{ Constants to check stat.mode }
STAT_IFMT = $f000; {00170000}
STAT_IFSOCK = $c000; {0140000}
STAT_IFLNK = $a000; {0120000}
STAT_IFREG = $8000; {0100000}
STAT_IFBLK = $6000; {0060000}
STAT_IFDIR = $4000; {0040000}
STAT_IFCHR = $2000; {0020000}
STAT_IFIFO = $1000; {0010000}
STAT_ISUID = $0800; {0004000}
STAT_ISGID = $0400; {0002000}
STAT_ISVTX = $0200; {0001000}
{ Constants to check permissions }
STAT_IRWXO = $7;
STAT_IROTH = $4;
STAT_IWOTH = $2;
STAT_IXOTH = $1;
STAT_IRWXG = STAT_IRWXO shl 3;
STAT_IRGRP = STAT_IROTH shl 3;
STAT_IWGRP = STAT_IWOTH shl 3;
STAT_IXGRP = STAT_IXOTH shl 3;
STAT_IRWXU = STAT_IRWXO shl 6;
STAT_IRUSR = STAT_IROTH shl 6;
STAT_IWUSR = STAT_IWOTH shl 6;
STAT_IXUSR = STAT_IXOTH shl 6;
{ Constants to test the type of filesystem }
fs_old_ext2 = $ef51;
fs_ext2 = $ef53;
fs_ext = $137d;
fs_iso = $9660;
fs_minix = $137f;
fs_minix_30 = $138f;
fs_minux_V2 = $2468;
fs_msdos = $4d44;
fs_nfs = $6969;
fs_proc = $9fa0;
fs_xia = $012FD16D;
{ Constansts for MMAP }
MAP_PRIVATE =2;
{$if defined(cpumips) or defined(cpumipsel)}
MAP_ANONYMOUS =$800;
{$else cpumips}
MAP_ANONYMOUS =$20;
{$endif cpumips}
{Constansts Termios/Ioctl (used in Do_IsDevice) }
IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
type
{
Linux system calls take arguments as follows :
cpui386/m68k:
%eax/%d0 : System call number
%ebx/%d1 : first argument
%ecx/%d2 : second argument
%edx/%d3 : third argumens
%esi/%d3 : fourth argument
%edi/%d4 : fifth argument
That is why we define a special type, with only these arguments
To make it processor independent, we don't give any system dependent
names, but the rather abstract reg1,reg2 etc;
}
SysCallRegs=record
reg1,reg2,reg3,reg4,reg5,reg6 : longint;
end;
PSysCallRegs=^SysCallRegs;
TSysCallRegs=SysCallRegs;
{ The following are records for system calls }
dirent = packed record
ino,
off : longint;
reclen : word;
name : array [0..255] of char;
end;
pdirent =^dirent;
TDirEnt = dirent;
TDir = packed record
fd : integer;
loc : longint;
size : integer;
buf : pdirent;
{The following are used in libc, but NOT in the linux kernel sources ??}
nextoff: longint;
dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
lock : pointer;
end;
PDir =^TDir;
dev_t = word;
Stat = packed record
dev : dev_t;
pad1 : word;
ino : longint;
mode,
nlink,
uid,
gid : word;
rdev : dev_t;
pad2 : word;
size,
blksize,
blocks,
atime,
unused1,
mtime,
unused2,
ctime,
unused3,
unused4,
unused5 : longint;
end;
PStat=^Stat;
TStat=Stat;
Statfs = packed record
fstype, { File system type }
bsize, { Optimal block trensfer size }
blocks, { Data blocks in system }
bfree, { free blocks in system }
bavail, { Available free blocks to non-root users }
files, { File nodes in system }
ffree, { Free file nodes in system }
fsid, { File system ID }
namelen : longint; { Maximum name length in system }
spare : array [0..6] of longint; { For later use }
end;
PStatFS=^StatFS;
TStatFS=StatFS;
fdSet=array[0..7] of longint;{=256 bits}
pfdset=^fdset;
TFDSet=fdset;
timeval = packed record
sec,usec:longint
end;
ptimeval=^timeval;
TTimeVal=timeval;
timespec = packed record
tv_sec,tv_nsec:longint;
end;
timezone = packed record
minuteswest,dsttime:longint;
end;
ptimezone =^timezone;
TTimeZone = timezone;
utsname = packed record
sysname,
nodename,
release,
version,
machine,
domainname : Array[0..64] of char;
end;
PUTSName=^UTSName;
TUTSName=UTSName;
{ Get System call numbers and error-numbers}
const
syscall_nr_setup = 0;
syscall_nr_exit = 1;
syscall_nr_fork = 2;
syscall_nr_read = 3;
syscall_nr_write = 4;
syscall_nr_open = 5;
syscall_nr_close = 6;
syscall_nr_waitpid = 7;
syscall_nr_creat = 8;
syscall_nr_link = 9;
syscall_nr_unlink = 10;
syscall_nr_execve = 11;
syscall_nr_chdir = 12;
syscall_nr_time = 13;
syscall_nr_mknod = 14;
syscall_nr_chmod = 15;
syscall_nr_chown = 16;
syscall_nr_break = 17;
syscall_nr_oldstat = 18;
syscall_nr_lseek = 19;
syscall_nr_getpid = 20;
syscall_nr_mount = 21;
syscall_nr_umount = 22;
syscall_nr_setuid = 23;
syscall_nr_getuid = 24;
syscall_nr_stime = 25;
syscall_nr_ptrace = 26;
syscall_nr_alarm = 27;
syscall_nr_oldfstat = 28;
syscall_nr_pause = 29;
syscall_nr_utime = 30;
syscall_nr_stty = 31;
syscall_nr_gtty = 32;
syscall_nr_access = 33;
syscall_nr_nice = 34;
syscall_nr_ftime = 35;
syscall_nr_sync = 36;
syscall_nr_kill = 37;
syscall_nr_rename = 38;
syscall_nr_mkdir = 39;
syscall_nr_rmdir = 40;
syscall_nr_dup = 41;
syscall_nr_pipe = 42;
syscall_nr_times = 43;
syscall_nr_prof = 44;
syscall_nr_brk = 45;
syscall_nr_setgid = 46;
syscall_nr_getgid = 47;
syscall_nr_signal = 48;
syscall_nr_geteuid = 49;
syscall_nr_getegid = 50;
syscall_nr_acct = 51;
syscall_nr_phys = 52;
syscall_nr_lock = 53;
syscall_nr_ioctl = 54;
syscall_nr_fcntl = 55;
syscall_nr_mpx = 56;
syscall_nr_setpgid = 57;
syscall_nr_ulimit = 58;
syscall_nr_oldolduname = 59;
syscall_nr_umask = 60;
syscall_nr_chroot = 61;
syscall_nr_ustat = 62;
syscall_nr_dup2 = 63;
syscall_nr_getppid = 64;
syscall_nr_getpgrp = 65;
syscall_nr_setsid = 66;
syscall_nr_sigaction = 67;
syscall_nr_sgetmask = 68;
syscall_nr_ssetmask = 69;
syscall_nr_setreuid = 70;
syscall_nr_setregid = 71;
syscall_nr_sigsuspend = 72;
syscall_nr_sigpending = 73;
syscall_nr_sethostname = 74;
syscall_nr_setrlimit = 75;
syscall_nr_getrlimit = 76;
syscall_nr_getrusage = 77;
syscall_nr_gettimeofday = 78;
syscall_nr_settimeofday = 79;
syscall_nr_getgroups = 80;
syscall_nr_setgroups = 81;
syscall_nr_select = 82;
syscall_nr_symlink = 83;
syscall_nr_oldlstat = 84;
syscall_nr_readlink = 85;
syscall_nr_uselib = 86;
syscall_nr_swapon = 87;
syscall_nr_reboot = 88;
syscall_nr_readdir = 89;
syscall_nr_mmap = 90;
syscall_nr_munmap = 91;
syscall_nr_truncate = 92;
syscall_nr_ftruncate = 93;
syscall_nr_fchmod = 94;
syscall_nr_fchown = 95;
syscall_nr_getpriority = 96;
syscall_nr_setpriority = 97;
syscall_nr_profil = 98;
syscall_nr_statfs = 99;
syscall_nr_fstatfs = 100;
syscall_nr_ioperm = 101;
syscall_nr_socketcall = 102;
syscall_nr_syslog = 103;
syscall_nr_setitimer = 104;
syscall_nr_getitimer = 105;
syscall_nr_stat = 106;
syscall_nr_lstat = 107;
syscall_nr_fstat = 108;
syscall_nr_olduname = 109;
syscall_nr_iopl = 110;
syscall_nr_vhangup = 111;
syscall_nr_idle = 112;
syscall_nr_vm86old = 113;
syscall_nr_wait4 = 114;
syscall_nr_swapoff = 115;
syscall_nr_sysinfo = 116;
syscall_nr_ipc = 117;
syscall_nr_fsync = 118;
syscall_nr_sigreturn = 119;
syscall_nr_clone = 120;
syscall_nr_setdomainname = 121;
syscall_nr_uname = 122;
syscall_nr_modify_ldt = 123;
syscall_nr_adjtimex = 124;
syscall_nr_mprotect = 125;
syscall_nr_sigprocmask = 126;
syscall_nr_create_module = 127;
syscall_nr_init_module = 128;
syscall_nr_delete_module = 129;
syscall_nr_get_kernel_syms = 130;
syscall_nr_quotactl = 131;
syscall_nr_getpgid = 132;
syscall_nr_fchdir = 133;
syscall_nr_bdflush = 134;
syscall_nr_sysfs = 135;
syscall_nr_personality = 136;
syscall_nr_afs_syscall = 137;
syscall_nr_setfsuid = 138;
syscall_nr_setfsgid = 139;
syscall_nr__llseek = 140;
syscall_nr_getdents = 141;
syscall_nr__newselect = 142;
syscall_nr_flock = 143;
syscall_nr_msync = 144;
syscall_nr_readv = 145;
syscall_nr_writev = 146;
syscall_nr_getsid = 147;
syscall_nr_fdatasync = 148;
syscall_nr__sysctl = 149;
syscall_nr_mlock = 150;
syscall_nr_munlock = 151;
syscall_nr_mlockall = 152;
syscall_nr_munlockall = 153;
syscall_nr_sched_setparam = 154;
syscall_nr_sched_getparam = 155;
syscall_nr_sched_setscheduler = 156;
syscall_nr_sched_getscheduler = 157;
syscall_nr_sched_yield = 158;
syscall_nr_sched_get_priority_max = 159;
syscall_nr_sched_get_priority_min = 160;
syscall_nr_sched_rr_get_interval = 161;
syscall_nr_nanosleep = 162;
syscall_nr_mremap = 163;
syscall_nr_setresuid = 164;
syscall_nr_getresuid = 165;
syscall_nr_vm86 = 166;
syscall_nr_query_module = 167;
syscall_nr_poll = 168;
syscall_nr_sigaltstack = 186;
{$IFDEF SYSCALL_DEBUG}
const
Sys_nr_txt : array[0..168] of string[15]=(
'Setup', { 0 }
'Exit', { 1 }
'Fork', { 2 }
'Read', { 3 }
'Write', { 4 }
'Open', { 5 }
'Close', { 6 }
'WaitPid', { 7 }
'Create', { 8 }
'Link', { 9 }
'UnLink', { 10 }
'ExecVe', { 11 }
'ChDir', { 12 }
'Time', { 13 }
'MkNod', { 14 }
'ChMod', { 15 }
'ChOwn', { 16 }
'Break', { 17 }
'OldState', { 18 }
'LSeek', { 19 }
'GetPid', { 20 }
'Mount', { 21 }
'UMount', { 22 }
'SetUid', { 23 }
'GetUid', { 24 }
'STime', { 25 }
'PTrace', { 26 }
'Alarm', { 27 }
'OldFStat', { 28 }
'Pause', { 29 }
'UTime', { 30 }
'STTY', { 31 }
'GTTY', { 32 }
'Access', { 33 }
'Nice', { 34 }
'FTime', { 35 }
'Sync', { 36 }
'Kill', { 37 }
'Rename', { 38 }
'MkDir', { 39 }
'RmDir', { 40 }
'Dup', { 41 }
'Pipe', { 42 }
'Times', { 43 }
'Prof', { 44 }
'Break', { 45 }
'SetGid', { 46 }
'GetGid', { 47 }
'Signal', { 48 }
'GetEUid', { 49 }
'GetEGid', { 50 }
'Acct', { 51 }
'Phys', { 52 }
'Lock', { 53 }
'IOCtl', { 54 }
'FCNtl', { 55 }
'Mpx', { 56 }
'SetPGid', { 57 }
'ULimit', { 58 }
'OldOldUName', { 59 }
'UMask', { 60 }
'ChRoot', { 61 }
'UStat', { 62 }
'Dup2', { 63 }
'GetPPid', { 64 }
'GetPGrp', { 65 }
'SetSid', { 66 }
'SigAction', { 67 }
'SGetMask', { 68 }
'SSetMask', { 69 }
'SetReUid', { 70 }
'SetReGid', { 71 }
'SigSuspend', { 72 }
'SigPending', { 73 }
'SetHostName', { 74 }
'SetRLimit', { 75 }
'GetRLimit', { 76 }
'GetRUsage', { 77 }
'GetTimeOfDay', { 78 }
'SetTimeOfDay', { 79 }
'GetGroups', { 80 }
'SetGroups', { 81 }
'Select', { 82 }
'SymLink', { 83 }
'OldLStat', { 84 }
'ReadLink', { 85 }
'UseLib', { 86 }
'SwapOn', { 87 }
'Reboot', { 88 }
'ReadDir', { 89 }
'MMap', { 90 }
'MunMap', { 91 }
'Truncate', { 92 }
'FTruncate', { 93 }
'FChMod', { 94 }
'FChOwn', { 95 }
'GetPriority', { 96 }
'SetPriority', { 97 }
'Profile', { 98 }
'StatFs', { 99 }
'FStatFs', { 100 }
'IOPerm', { 101 }
'SocketCall', { 102 }
'SysLog', { 103 }
'SetITimer', { 104 }
'GetITimer', { 105 }
'Stat', { 106 }
'LStat', { 107 }
'FStat', { 108 }
'OldUName', { 109 }
'IOPl', { 110 }
'VHangup', { 111 }
'Idle', { 112 }
'VM86', { 113 }
'Wait4', { 114 }
'SwapOff', { 115 }
'SysInfo', { 116 }
'IPC', { 117 }
'FSync', { 118 }
'SigReturn', { 119 }
'Clone', { 120 }
'SetDomainName', { 121 }
'UName', { 122 }
'Modify_Ldt', { 123 }
'AdjTimeX', { 124 }
'MProtect', { 125 }
'SigProcMask', { 126 }
'Create_Module', { 127 }
'Init_Module', { 128 }
'Delete_Module', { 129 }
'Get_Kernel_Syms', { 130 }
'QuotaCtl', { 131 }
'GetPGid', { 132 }
'FChDir', { 133 }
'BDFlush', { 134 }
'SysFs', { 135 }
'Personality', { 136 }
'AFS_SysCall', { 137 }
'SetFsUid', { 138 }
'SetFsGid', { 139 }
'__LLSeek', { 140 }
'GetDents', { 141 }
'__NewSelect', { 142 }
'FLock', { 143 }
'MSync', { 144 }
'ReadV', { 145 }
'WriteV', { 146 }
'GetSid', { 147 }
'FDataSync', { 148 }
'__SysCtl', { 149 }
'MLock', { 150 }
'MUnLock', { 151 }
'MLockAll', { 152 }
'MUnLockAll', { 153 }
'MSchdSetParam', { 154 }
'MSchdGetParam', { 155 }
'MSchdSetSchd', { 156 }
'MSchdGetSchd', { 157 }
'MSchdYield', { 158 }
'MSchdGetPriMax', { 159 }
'MSchdGetPriMin', { 160 }
'MSchdRRGetInt', { 161 }
'NanoSleep', { 162 }
'MRemap', { 163 }
'SetReSuid', { 164 }
'GetReSuid', { 165 }
'vm86', { 166 }
'QueryModule', { 167 }
'Poll'); { 168 }
{$ENDIF}
Const
Sys_EPERM = 1; { Operation not permitted }
Sys_ENOENT = 2; { No such file or directory }
Sys_ESRCH = 3; { No such process }
Sys_EINTR = 4; { Interrupted system call }
Sys_EIO = 5; { I/O error }
Sys_ENXIO = 6; { No such device or address }
Sys_E2BIG = 7; { Arg list too long }
Sys_ENOEXEC = 8; { Exec format error }
Sys_EBADF = 9; { Bad file number }
Sys_ECHILD = 10; { No child processes }
Sys_EAGAIN = 11; { Try again }
Sys_ENOMEM = 12; { Out of memory }
Sys_EACCES = 13; { Permission denied }
Sys_EFAULT = 14; { Bad address }
Sys_ENOTBLK = 15; { Block device required, NOT POSIX! }
Sys_EBUSY = 16; { Device or resource busy }
Sys_EEXIST = 17; { File exists }
Sys_EXDEV = 18; { Cross-device link }
Sys_ENODEV = 19; { No such device }
Sys_ENOTDIR = 20; { Not a directory }
Sys_EISDIR = 21; { Is a directory }
Sys_EINVAL = 22; { Invalid argument }
Sys_ENFILE = 23; { File table overflow }
Sys_EMFILE = 24; { Too many open files }
Sys_ENOTTY = 25; { Not a typewriter }
Sys_ETXTBSY = 26; { Text file busy. The new process was
a pure procedure (shared text) file which was
open for writing by another process, or file
which was open for writing by another process,
or while the pure procedure file was being
executed an open(2) call requested write access
requested write access.}
Sys_EFBIG = 27; { File too large }
Sys_ENOSPC = 28; { No space left on device }
Sys_ESPIPE = 29; { Illegal seek }
Sys_EROFS = 30; { Read-only file system }
Sys_EMLINK = 31; { Too many links }
Sys_EPIPE = 32; { Broken pipe }
Sys_EDOM = 33; { Math argument out of domain of func }
Sys_ERANGE = 34; { Math result not representable }
Sys_EDEADLK = 35; { Resource deadlock would occur }
Sys_ENAMETOOLONG= 36; { File name too long }
Sys_ENOLCK = 37; { No record locks available }
Sys_ENOSYS = 38; { Function not implemented }
Sys_ENOTEMPTY= 39; { Directory not empty }
Sys_ELOOP = 40; { Too many symbolic links encountered }
Sys_EWOULDBLOCK = Sys_EAGAIN; { Operation would block }
Sys_ENOMSG = 42; { No message of desired type }
Sys_EIDRM = 43; { Identifier removed }
Sys_ECHRNG = 44; { Channel number out of range }
Sys_EL2NSYNC= 45; { Level 2 not synchronized }
Sys_EL3HLT = 46; { Level 3 halted }
Sys_EL3RST = 47; { Level 3 reset }
Sys_ELNRNG = 48; { Link number out of range }
Sys_EUNATCH = 49; { Protocol driver not attached }
Sys_ENOCSI = 50; { No CSI structure available }
Sys_EL2HLT = 51; { Level 2 halted }
Sys_EBADE = 52; { Invalid exchange }
Sys_EBADR = 53; { Invalid request descriptor }
Sys_EXFULL = 54; { Exchange full }
Sys_ENOANO = 55; { No anode }
Sys_EBADRQC = 56; { Invalid request code }
Sys_EBADSLT = 57; { Invalid slot }
Sys_EDEADLOCK= 58; { File locking deadlock error }
Sys_EBFONT = 59; { Bad font file format }
Sys_ENOSTR = 60; { Device not a stream }
Sys_ENODATA = 61; { No data available }
Sys_ETIME = 62; { Timer expired }
Sys_ENOSR = 63; { Out of streams resources }
Sys_ENONET = 64; { Machine is not on the network }
Sys_ENOPKG = 65; { Package not installed }
Sys_EREMOTE = 66; { Object is remote }
Sys_ENOLINK = 67; { Link has been severed }
Sys_EADV = 68; { Advertise error }
Sys_ESRMNT = 69; { Srmount error }
Sys_ECOMM = 70; { Communication error on send }
Sys_EPROTO = 71; { Protocol error }
Sys_EMULTIHOP= 72; { Multihop attempted }
Sys_EDOTDOT = 73; { RFS specific error }
Sys_EBADMSG = 74; { Not a data message }
Sys_EOVERFLOW= 75; { Value too large for defined data type }
Sys_ENOTUNIQ= 76; { Name not unique on network }
Sys_EBADFD = 77; { File descriptor in bad state }
Sys_EREMCHG = 78; { Remote address changed }
Sys_ELIBACC = 79; { Can not access a needed shared library }
Sys_ELIBBAD = 80; { Accessing a corrupted shared library }
Sys_ELIBSCN = 81; { .lib section in a.out corrupted }
Sys_ELIBMAX = 82; { Attempting to link in too many shared libraries }
Sys_ELIBEXEC= 83; { Cannot exec a shared library directly }
Sys_EILSEQ = 84; { Illegal byte sequence }
Sys_ERESTART= 85; { Interrupted system call should be restarted }
Sys_ESTRPIPE= 86; { Streams pipe error }
Sys_EUSERS = 87; { Too many users }
Sys_ENOTSOCK= 88; { Socket operation on non-socket }
Sys_EDESTADDRREQ= 89; { Destination address required }
Sys_EMSGSIZE= 90; { Message too long }
Sys_EPROTOTYPE= 91; { Protocol wrong type for socket }
Sys_ENOPROTOOPT= 92; { Protocol not available }
Sys_EPROTONOSUPPORT= 93; { Protocol not supported }
Sys_ESOCKTNOSUPPORT= 94; { Socket type not supported }
Sys_EOPNOTSUPP= 95; { Operation not supported on transport endpoint }
Sys_EPFNOSUPPORT= 96; { Protocol family not supported }
Sys_EAFNOSUPPORT= 97; { Address family not supported by protocol }
Sys_EADDRINUSE= 98; { Address already in use }
Sys_EADDRNOTAVAIL= 99; { Cannot assign requested address }
Sys_ENETDOWN= 100; { Network is down }
Sys_ENETUNREACH= 101; { Network is unreachable }
Sys_ENETRESET= 102; { Network dropped connection because of reset }
Sys_ECONNABORTED= 103; { Software caused connection abort }
Sys_ECONNRESET= 104; { Connection reset by peer }
Sys_ENOBUFS = 105; { No buffer space available }
Sys_EISCONN = 106; { Transport endpoint is already connected }
Sys_ENOTCONN= 107; { Transport endpoint is not connected }
Sys_ESHUTDOWN= 108; { Cannot send after transport endpoint shutdown }
Sys_ETOOMANYREFS= 109; { Too many references: cannot splice }
Sys_ETIMEDOUT= 110; { Connection timed out }
Sys_ECONNREFUSED= 111; { Connection refused }
Sys_EHOSTDOWN= 112; { Host is down }
Sys_EHOSTUNREACH= 113; { No route to host }
Sys_EALREADY= 114; { Operation already in progress }
Sys_EINPROGRESS= 115; { Operation now in progress }
Sys_ESTALE = 116; { Stale NFS file handle }
Sys_EUCLEAN = 117; { Structure needs cleaning }
Sys_ENOTNAM = 118; { Not a XENIX named type file }
Sys_ENAVAIL = 119; { No XENIX semaphores available }
Sys_EISNAM = 120; { Is a named type file }
Sys_EREMOTEIO= 121; { Remote I/O error }
Sys_EDQUOT = 122; { Quota exceeded }
{ This value was suggested by Daniel
based on infos from www.linuxassembly.org }
Sys_ERROR_MAX = $fff;
{$packrecords C}
{********************
Signal
********************}
type
SigSet = Longint;
PSigSet = ^SigSet;
Const
{ For sending a signal }
SA_NOCLDSTOP = 1;
SA_SHIRQ = $04000000;
SA_STACK = $08000000;
SA_RESTART = $10000000;
SA_INTERRUPT = $20000000;
SA_NOMASK = $40000000;
SA_ONESHOT = $80000000;
SA_ONSTACK = SA_STACK;
SIG_BLOCK = 0;
SIG_UNBLOCK = 1;
SIG_SETMASK = 2;
SIG_DFL = 0 ;
SIG_IGN = 1 ;
SIG_ERR = -1 ;
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGIOT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
SIGSEGV = 11;
SIGUSR2 = 12;
SIGPIPE = 13;
SIGALRM = 14;
SIGTerm = 15;
SIGSTKFLT = 16;
SIGCHLD = 17;
SIGCONT = 18;
SIGSTOP = 19;
SIGTSTP = 20;
SIGTTIN = 21;
SIGTTOU = 22;
SIGURG = 23;
SIGXCPU = 24;
SIGXFSZ = 25;
SIGVTALRM = 26;
SIGPROF = 27;
SIGWINCH = 28;
SIGIO = 29;
SIGPOLL = SIGIO;
SIGPWR = 30;
SIGUNUSED = 31;
const
SI_PAD_SIZE = ((128/sizeof(longint)) - 3);
type
Size_T = cardinal;
tfpreg = record
significand: array[0..3] of word;
exponent: word;
end;
pfpstate = ^tfpstate;
tfpstate = record
cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
st: array[0..7] of tfpreg;
status: cardinal;
end;
PSigContextRec = ^SigContextRec;
SigContextRec = record
gs, __gsh: word;
fs, __fsh: word;
es, __esh: word;
ds, __dsh: word;
edi: cardinal;
esi: cardinal;
ebp: cardinal;
esp: cardinal;
ebx: cardinal;
edx: cardinal;
ecx: cardinal;
eax: cardinal;
trapno: cardinal;
err: cardinal;
eip: cardinal;
cs, __csh: word;
eflags: cardinal;
esp_at_signal: cardinal;
ss, __ssh: word;
fpstate: pfpstate;
oldmask: cardinal;
cr2: cardinal;
end;
(*
PSigInfoRec = ^SigInfoRec;
SigInfoRec = record
si_signo: longint;
si_errno: longint;
si_code: longint;
case longint of
0:
(pad: array[SI_PAD_SIZE] of longint);
1: { kill }
( kill: record
pid: longint; { sender's pid }
uid : longint; { sender's uid }
end );
2: { POSIX.1b timers }
( timer : record
timer1 : cardinal;
timer2 : cardinal;
end );
3: { POSIX.1b signals }
( rt : record
pid : longint; { sender's pid }
uid : longint; { sender's uid }
sigval : longint;
end );
4: { SIGCHLD }
( sigchld : record
pid : longint; { which child }
uid : longint; { sender's uid }
status : longint; { exit code }
utime : timeval;
stime : timeval;
end );
5: { SIGILL, SIGFPE, SIGSEGV, SIGBUS }
( sigfault : record
addr : pointer;{ faulting insn/memory ref. }
end );
6:
( sigpoll : record
band : longint; { POLL_IN, POLL_OUT, POLL_MSG }
fd : longint;
end );
end;
*)
SignalHandler = Procedure(Sig : Longint);cdecl;
PSignalHandler = ^SignalHandler;
SignalRestorer = Procedure;cdecl;
PSignalRestorer = ^SignalRestorer;
TSigAction = procedure(Sig: Longint; SigContext: SigContextRec);cdecl;
SigActionRec = packed record
Handler : record
case byte of
0: (Sh: SignalHandler);
1: (Sa: TSigAction);
end;
Sa_Mask : SigSet;
Sa_Flags : Longint;
Sa_restorer : SignalRestorer; { Obsolete - Don't use }
end;
PSigActionRec = ^SigActionRec;
const
SS_ONSTACK = 1;
SS_DISABLE = 2;
MINSIGSTKSZ = 2048;
SIGSTKSZ = 8192;
type
SigAltStack = record
ss_sp : pointer;
ss_flags : longint;
ss_size : size_t;
end;
stack_t = sigaltstack;
PSigAltStack = ^SigAltStack;
pstack_t = ^stack_t;
var
ErrNo,
LinuxError : Longint;
{********************
Process
********************}
const
{Checked for BSD using Linuxthreads port}
{ cloning flags }
CSIGNAL = $000000ff; // signal mask to be sent at exit
CLONE_VM = $00000100; // set if VM shared between processes
CLONE_FS = $00000200; // set if fs info shared between processes
CLONE_FILES = $00000400; // set if open files shared between processes
CLONE_SIGHAND = $00000800; // set if signal handlers shared
CLONE_PID = $00001000; // set if pid shared
type
TCloneFunc=function(args:pointer):longint;cdecl;
const
{ For getting/setting priority }
Prio_Process = 0;
Prio_PGrp = 1;
Prio_User = 2;
{$ifdef Solaris}
WNOHANG = $100;
WUNTRACED = $4;
{$ELSE}
WNOHANG = $1;
WUNTRACED = $2;
__WCLONE = $80000000;
{$ENDIF}
{********************
File
********************}
Const
P_IN = 1;
P_OUT = 2;
Const
LOCK_SH = 1;
LOCK_EX = 2;
LOCK_UN = 8;
LOCK_NB = 4;
Type
Tpipe = array[1..2] of longint;
pglob = ^tglob;
tglob = record
name : pchar;
next : pglob;
end;
ComStr = String[255];
PathStr = String[255];
DirStr = String[255];
NameStr = String[255];
ExtStr = String[255];
const
{ For testing access rights }
R_OK = 4;
W_OK = 2;
X_OK = 1;
F_OK = 0;
{$ifndef newreaddir}
{ For File control mechanism }
F_GetFd = 1;
F_SetFd = 2;
F_GetFl = 3;
F_SetFl = 4;
{$ifdef Solaris}
F_DupFd = 0;
F_Dup2Fd = 9;
F_GetOwn = 23;
F_SetOwn = 24;
F_GetLk = 14;
F_SetLk = 6;
F_SetLkW = 7;
F_FreeSp = 11;
{$else}
F_GetLk = 5;
F_SetLk = 6;
F_SetLkW = 7;
F_SetOwn = 8;
F_GetOwn = 9;
{$endif}
{$endif}
{********************
IOCtl(TermIOS)
********************}
{Is too freebsd/Linux specific}
{********************
IOCtl(TermIOS)
********************}
Const
{ Amount of Control Chars }
NCCS = 32;
NCC = 8;
{$Ifndef BSD}
{ For Terminal handling }
TCGETS = $5401;
TCSETS = $5402;
TCSETSW = $5403;
TCSETSF = $5404;
TCGETA = $5405;
TCSETA = $5406;
TCSETAW = $5407;
TCSETAF = $5408;
TCSBRK = $5409;
TCXONC = $540A;
TCFLSH = $540B;
TIOCEXCL = $540C;
TIOCNXCL = $540D;
TIOCSCTTY = $540E;
TIOCGPGRP = $540F;
TIOCSPGRP = $5410;
TIOCOUTQ = $5411;
TIOCSTI = $5412;
TIOCGWINSZ = $5413;
TIOCSWINSZ = $5414;
TIOCMGET = $5415;
TIOCMBIS = $5416;
TIOCMBIC = $5417;
TIOCMSET = $5418;
TIOCGSOFTCAR = $5419;
TIOCSSOFTCAR = $541A;
FIONREAD = $541B;
TIOCINQ = FIONREAD;
TIOCLINUX = $541C;
TIOCCONS = $541D;
TIOCGSERIAL = $541E;
TIOCSSERIAL = $541F;
TIOCPKT = $5420;
FIONBIO = $5421;
TIOCNOTTY = $5422;
TIOCSETD = $5423;
TIOCGETD = $5424;
TCSBRKP = $5425;
TIOCTTYGSTRUCT = $5426;
FIONCLEX = $5450;
FIOCLEX = $5451;
FIOASYNC = $5452;
TIOCSERCONFIG = $5453;
TIOCSERGWILD = $5454;
TIOCSERSWILD = $5455;
TIOCGLCKTRMIOS = $5456;
TIOCSLCKTRMIOS = $5457;
TIOCSERGSTRUCT = $5458;
TIOCSERGETLSR = $5459;
TIOCSERGETMULTI = $545A;
TIOCSERSETMULTI = $545B;
TIOCMIWAIT = $545C;
TIOCGICOUNT = $545D;
TIOCPKT_DATA = 0;
TIOCPKT_FLUSHREAD = 1;
TIOCPKT_FLUSHWRITE = 2;
TIOCPKT_STOP = 4;
TIOCPKT_START = 8;
TIOCPKT_NOSTOP = 16;
TIOCPKT_DOSTOP = 32;
{$else}
{$endif}
Type
winsize = packed record
ws_row,
ws_col,
ws_xpixel,
ws_ypixel : word;
end;
TWinSize=winsize;
Termio = packed record
c_iflag, { input mode flags }
c_oflag, { output mode flags }
c_cflag, { control mode flags }
c_lflag : Word; { local mode flags }
c_line : Word; { line discipline - careful, only High byte in use}
c_cc : array [0..NCC-1] of char;{ control characters }
end;
TTermio=Termio;
{$PACKRECORDS C}
Termios = record
c_iflag,
c_oflag,
c_cflag,
c_lflag : Cardinal;
c_line : char;
c_cc : array[0..NCCS-1] of byte;
c_ispeed,
c_ospeed : longint;
end;
TTermios=Termios;
{$PACKRECORDS Default}
{const
InitCC:array[0..NCCS-1] of byte=(3,34,177,25,4,0,1,0,21,23,32,0,22,17,27,26,0,0,0);}
const
{c_cc characters}
VINTR = 0;
VQUIT = 1;
VERASE = 2;
VKILL = 3;
VEOF = 4;
VTIME = 5;
VMIN = 6;
VSWTC = 7;
VSTART = 8;
VSTOP = 9;
VSUSP = 10;
VEOL = 11;
VREPRINT = 12;
VDISCARD = 13;
VWERASE = 14;
VLNEXT = 15;
VEOL2 = 16;
{c_iflag bits}
IGNBRK = $0000001;
BRKINT = $0000002;
IGNPAR = $0000004;
PARMRK = $0000008;
INPCK = $0000010;
ISTRIP = $0000020;
INLCR = $0000040;
IGNCR = $0000080;
ICRNL = $0000100;
IUCLC = $0000200;
IXON = $0000400;
IXANY = $0000800;
IXOFF = $0001000;
IMAXBEL = $0002000;
{c_oflag bits}
OPOST = $0000001;
OLCUC = $0000002;
ONLCR = $0000004;
OCRNL = $0000008;
ONOCR = $0000010;
ONLRET = $0000020;
OFILL = $0000040;
OFDEL = $0000080;
NLDLY = $0000100;
NL0 = $0000000;
NL1 = $0000100;
CRDLY = $0000600;
CR0 = $0000000;
CR1 = $0000200;
CR2 = $0000400;
CR3 = $0000600;
TABDLY = $0001800;
TAB0 = $0000000;
TAB1 = $0000800;
TAB2 = $0001000;
TAB3 = $0001800;
XTABS = $0001800;
BSDLY = $0002000;
BS0 = $0000000;
BS1 = $0002000;
VTDLY = $0004000;
VT0 = $0000000;
VT1 = $0004000;
FFDLY = $0008000;
FF0 = $0000000;
FF1 = $0008000;
{c_cflag bits}
CBAUD = $000100F;
B0 = $0000000;
B50 = $0000001;
B75 = $0000002;
B110 = $0000003;
B134 = $0000004;
B150 = $0000005;
B200 = $0000006;
B300 = $0000007;
B600 = $0000008;
B1200 = $0000009;
B1800 = $000000A;
B2400 = $000000B;
B4800 = $000000C;
B9600 = $000000D;
B19200 = $000000E;
B38400 = $000000F;
EXTA = B19200;
EXTB = B38400;
CSIZE = $0000030;
CS5 = $0000000;
CS6 = $0000010;
CS7 = $0000020;
CS8 = $0000030;
CSTOPB = $0000040;
CREAD = $0000080;
PARENB = $0000100;
PARODD = $0000200;
HUPCL = $0000400;
CLOCAL = $0000800;
CBAUDEX = $0001000;
B57600 = $0001001;
B115200 = $0001002;
B230400 = $0001003;
B460800 = $0001004;
CIBAUD = $100F0000;
CMSPAR = $40000000;
CRTSCTS = $80000000;
{c_lflag bits}
ISIG = $0000001;
ICANON = $0000002;
XCASE = $0000004;
ECHO = $0000008;
ECHOE = $0000010;
ECHOK = $0000020;
ECHONL = $0000040;
NOFLSH = $0000080;
TOSTOP = $0000100;
ECHOCTL = $0000200;
ECHOPRT = $0000400;
ECHOKE = $0000800;
FLUSHO = $0001000;
PENDIN = $0004000;
IEXTEN = $0008000;
{c_line bits}
TIOCM_LE = $001;
TIOCM_DTR = $002;
TIOCM_RTS = $004;
TIOCM_ST = $008;
TIOCM_SR = $010;
TIOCM_CTS = $020;
TIOCM_CAR = $040;
TIOCM_RNG = $080;
TIOCM_DSR = $100;
TIOCM_CD = TIOCM_CAR;
TIOCM_RI = TIOCM_RNG;
TIOCM_OUT1 = $2000;
TIOCM_OUT2 = $4000;
{TCSetAttr}
TCSANOW = 0;
TCSADRAIN = 1;
TCSAFLUSH = 2;
{TCFlow}
TCOOFF = 0;
TCOON = 1;
TCIOFF = 2;
TCION = 3;
{TCFlush}
TCIFLUSH = 0;
TCOFLUSH = 1;
TCIOFLUSH = 2;
{********************
Info
********************}
Type
UTimBuf = packed record{in BSD array[0..1] of timeval, but this is
backwards compatible with linux version}
actime,
modtime
: longint;
end;
UTimeBuf=UTimBuf;
TUTimeBuf=UTimeBuf;
PUTimeBuf=^UTimeBuf;
TSysinfo = packed record
uptime : longint;
loads : array[1..3] of longint;
totalram,
freeram,
sharedram,
bufferram,
totalswap,
freeswap : longint;
procs : integer;
s : string[18];
end;
PSysInfo = ^TSysInfo;
{******************************************************************************
Procedure/Functions
******************************************************************************}
Function SysCall(callnr:longint;var regs:SysCallregs):longint;
{**************************
Time/Date Handling
***************************}
var
tzdaylight : boolean;
tzseconds : longint;
tzname : array[boolean] of pchar;
{ timezone support }
procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
procedure GetLocalTimezone(timer:longint);
procedure ReadTimezoneFile(fn:string);
function GetTimezoneFile:string;
Procedure GetTimeOfDay(var tv:timeval);
Function GetTimeOfDay:longint;
Function GetEpochTime: longint;
Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
procedure GetTime(var hour,min,sec,msec,usec:word);
procedure GetTime(var hour,min,sec,sec100:word);
procedure GetTime(var hour,min,sec:word);
Procedure GetDate(Var Year,Month,Day:Word);
Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
function SetTime(Hour,Min,Sec:word) : Boolean;
function SetDate(Year,Month,Day:Word) : Boolean;
function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
{**************************
Process Handling
***************************}
function CreateShellArgV(const prog:string):ppchar;
function CreateShellArgV(const prog:Ansistring):ppchar;
Procedure Execve(Path: pathstr;args:ppchar;ep:ppchar);
Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
Procedure Execve(path: pchar;args:ppchar;ep:ppchar);
Procedure Execv(const path:pathstr;args:ppchar);
Procedure Execv(const path: AnsiString;args:ppchar);
Procedure Execvp(Path: Pathstr;Args:ppchar;Ep:ppchar);
Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
Procedure Execl(const Todo: String);
Procedure Execl(const Todo: Ansistring);
Procedure Execle(Todo: String;Ep:ppchar);
Procedure Execle(Todo: AnsiString;Ep:ppchar);
Procedure Execlp(Todo: string;Ep:ppchar);
Procedure Execlp(Todo: Ansistring;Ep:ppchar);
Function Shell(const Command:String):Longint;
Function Shell(const Command:AnsiString):Longint;
Function Fork:longint;
{Clone for FreeBSD is copied from the LinuxThread port, and rfork based}
function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
Procedure ExitProcess(val:longint);
Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint; {=>PID (Status Valid), 0 (No Status), -1: Error, special case errno=EINTR }
Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
Procedure Nice(N:integer);
Function GetPriority(Which,Who:Integer):integer;
Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
function WEXITSTATUS(Status: Integer): Integer;
function WTERMSIG(Status: Integer): Integer;
function WSTOPSIG(Status: Integer): Integer;
Function WIFEXITED(Status: Integer): Boolean;
Function WIFSTOPPED(Status: Integer): Boolean;
Function WIFSIGNALED(Status: Integer): Boolean;
Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
Function W_STOPCODE(Signal: Integer): Integer;
Function GetPid:LongInt;
Function GetPPid:LongInt;
Function GetUid:Longint;
Function GetEUid:Longint;
Function GetGid:Longint;
Function GetEGid:Longint;
{**************************
File Handling
***************************}
Function fdOpen(pathname:string;flags:longint):longint;
Function fdOpen(pathname:string;flags,mode:longint):longint;
Function fdOpen(pathname:pchar;flags:longint):longint;
Function fdOpen(pathname:pchar;flags,mode:longint):longint;
Function fdClose(fd:longint):boolean;
Function fdRead(fd:longint;var buf;size:longint):longint;
Function fdWrite(fd:longint;const buf;size:longint):longint;
Function fdTruncate(fd,size:longint):boolean;
Function fdSeek (fd,pos,seektype :longint): longint;
Function fdFlush (fd : Longint) : Boolean;
Function Link(OldPath,NewPath:pathstr):boolean;
Function SymLink(OldPath,NewPath:pathstr):boolean;
Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
Function ReadLink(name:pathstr):pathstr;
Function UnLink(Path:pathstr):boolean;
Function UnLink(Path:pchar):Boolean;
Function FReName (OldName,NewName : Pchar) : Boolean;
Function FReName (OldName,NewName : String) : Boolean;
Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
Function Chmod(path:pathstr;Newmode:longint):boolean;
Function Utime(const path:pathstr;utim:utimebuf):boolean;
Function Access(Path:Pathstr ;mode:integer):boolean;
Function Umask(Mask:Integer):integer;
Function Flock (fd,mode : longint) : boolean;
Function Flock (var T : text;mode : longint) : boolean;
Function Flock (var F : File;mode : longint) : boolean;
Function FStat(Path:Pathstr;Var Info:stat):Boolean;
Function FStat(Fd:longint;Var Info:stat):Boolean;
Function FStat(var F:Text;Var Info:stat):Boolean;
Function FStat(var F:File;Var Info:stat):Boolean;
Function Lstat(Filename: PathStr;var Info:stat):Boolean;
Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
Function FSStat(Fd: Longint;Var Info:statfs):Boolean;
Function Fcntl(Fd:longint;Cmd:longint):longint;
Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
Function Fcntl(var Fd:Text;Cmd:longint):longint;
Procedure Fcntl(var Fd:Text;Cmd:longint;Arg:Longint);
Function Dup(oldfile:longint;var newfile:longint):Boolean;
Function Dup(var oldfile,newfile:text):Boolean;
Function Dup(var oldfile,newfile:file):Boolean;
Function Dup2(oldfile,newfile:longint):Boolean;
Function Dup2(var oldfile,newfile:text):Boolean;
Function Dup2(var oldfile,newfile:file):Boolean;
Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
Function SelectText(var T:Text;TimeOut :Longint):Longint;
{**************************
Directory Handling
***************************}
{$ifndef newreaddir} {only for FreeBSD, temporary solution}
Function OpenDir(f:pchar):pdir;
Function OpenDir(f: String):pdir;
function CloseDir(p:pdir):integer;
Function ReadDir(p:pdir):pdirent;
procedure SeekDir(p:pdir;off:longint);
function TellDir(p:pdir):longint;
{$else}
Function OpenDir(name:pchar):pdir;
Function OpenDir(f: String):pdir;
function CloseDir(dirp:pdir):integer;
Function ReadDir(p:pdir):pdirent;
procedure SeekDir(dirp:pdir;loc:longint);
function TellDir(dirp:pdir):longint;
{$endif}
{**************************
Pipe/Fifo/Stream
***************************}
Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
Function AssignPipe(var pipe_in,pipe_out:text):boolean;
Function AssignPipe(var pipe_in,pipe_out:file):boolean;
Function PClose(Var F:text) : longint;
Function PClose(Var F:file) : longint;
Procedure POpen(var F:text;const Prog:String;rw:char);
Procedure POpen(var F:file;const Prog:String;rw:char);
Function mkFifo(pathname:string;mode:longint):boolean;
function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
{**************************
General information
***************************}
Function GetEnv(P:string):Pchar;
Function GetDomainName:String;
Function GetHostName:String;
Function Sysinfo(var Info:TSysinfo):Boolean;
Function Uname(var unamerec:utsname):Boolean;
{**************************
Signal
***************************}
Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
Procedure SigProcMask (How:longint;SSet,OldSSet:PSigSet);
Function SigPending:SigSet;
Procedure SigSuspend(Mask:Sigset);
Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
Function Kill(Pid:longint;Sig:longint):integer;
Procedure SigRaise(Sig:integer);
Function Alarm(Sec : Longint) : longint;
Procedure Pause;
Function NanoSleep(const req : timespec;var rem : timespec) : longint;
{**************************
IOCtl/Termios Functions
***************************}
Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
Procedure CFMakeRaw(var tios:TermIOS);
Function TCSendBreak(fd,duration:longint):boolean;
Function TCSetPGrp(fd,id:longint):boolean;
Function TCGetPGrp(fd:longint;var id:longint):boolean;
Function TCFlush(fd,qsel:longint):boolean;
Function TCDrain(fd:longint):boolean;
Function TCFlow(fd,act:longint):boolean;
Function IsATTY(Handle:Longint):Boolean;
Function IsATTY(var f:text):Boolean;
function TTYname(Handle:Longint):string;
function TTYname(var F:Text):string;
{**************************
Memory functions
***************************}
const
PROT_READ = $1; { page can be read }
PROT_WRITE = $2; { page can be written }
PROT_EXEC = $4; { page can be executed }
PROT_NONE = $0; { page can not be accessed }
MAP_SHARED = $1; { Share changes }
// MAP_PRIVATE = $2; { Changes are private }
MAP_TYPE = $f; { Mask for type of mapping }
MAP_FIXED = $10; { Interpret addr exactly }
// MAP_ANONYMOUS = $20; { don't use a file }
{$if defined(cpumips) or defined(cpumipsel)}
MAP_GROWSDOWN = $1000; { stack-like segment }
MAP_DENYWRITE = $2000; { ETXTBSY }
MAP_EXECUTABLE = $4000; { mark it as an executable }
MAP_LOCKED = $8000; { pages are locked }
MAP_NORESERVE = $4000; { don't check for reservations }
{$else cpumips}
MAP_GROWSDOWN = $100; { stack-like segment }
MAP_DENYWRITE = $800; { ETXTBSY }
MAP_EXECUTABLE = $1000; { mark it as an executable }
MAP_LOCKED = $2000; { pages are locked }
MAP_NORESERVE = $4000; { don't check for reservations }
{$endif cpumips}
type
tmmapargs=record
address : longint;
size : longint;
prot : longint;
flags : longint;
fd : longint;
offset : longint;
end;
function MMap(const m:tmmapargs):longint;
function MUnMap (P : Pointer; Size : Longint) : Boolean;
{**************************
Port IO functions
***************************}
Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
Function IoPL(Level : longint) : Boolean;
{$ifdef cpui386}
Procedure WritePort (Port : Longint; Value : Byte);oldfpccall;
Procedure WritePort (Port : Longint; Value : Word);oldfpccall;
Procedure WritePort (Port : Longint; Value : Longint);oldfpccall;
Procedure WritePortB (Port : Longint; Value : Byte);oldfpccall;
Procedure WritePortW (Port : Longint; Value : Word);oldfpccall;
Procedure WritePortL (Port : Longint; Value : Longint);oldfpccall;
Procedure WritePortL (Port : Longint; Var Buf; Count: longint);oldfpccall;
Procedure WritePortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
Procedure WritePortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
Procedure ReadPort (Port : Longint; Var Value : Byte);oldfpccall;
Procedure ReadPort (Port : Longint; Var Value : Word);oldfpccall;
Procedure ReadPort (Port : Longint; Var Value : Longint);oldfpccall;
function ReadPortB (Port : Longint): Byte;oldfpccall;
function ReadPortW (Port : Longint): Word;oldfpccall;
function ReadPortL (Port : Longint): LongInt;oldfpccall;
Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);oldfpccall;
Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
{$endif}
{**************************
Utility functions
***************************}
Function Octal(l:longint):longint;
Function FExpand(Const Path: PathStr):PathStr;
Function FSearch(const path:pathstr;dirlist:string):pathstr;
Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
Function Dirname(Const path:pathstr):pathstr;
Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
Function FNMatch(const Pattern,Name:string):Boolean;
Function Glob(Const path:pathstr):pglob;
Procedure Globfree(var p:pglob);
Function StringToPPChar(Var S:String):ppchar;
Function StringToPPChar(Var S:AnsiString):ppchar;
Function StringToPPChar(S : Pchar):ppchar;
Function GetFS(var T:Text):longint;
Function GetFS(Var F:File):longint;
{Filedescriptorsets}
Procedure FD_Zero(var fds:fdSet);
Procedure FD_Clr(fd:longint;var fds:fdSet);
Procedure FD_Set(fd:longint;var fds:fdSet);
Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
{Stat.Mode Types}
Function S_ISLNK(m:word):boolean;
Function S_ISREG(m:word):boolean;
Function S_ISDIR(m:word):boolean;
Function S_ISCHR(m:word):boolean;
Function S_ISBLK(m:word):boolean;
Function S_ISFIFO(m:word):boolean;
Function S_ISSOCK(m:word):boolean;
{******************************************************************************
Implementation
******************************************************************************}
Implementation
Uses Strings;
{No debugging for syslinux include !}
{$IFDEF SYS_LINUX}
{$UNDEF SYSCALL_DEBUG}
{$ENDIF SYS_LINUX}
{*****************************************************************************
--- Main:The System Call Self ---
*****************************************************************************}
{$ifdef FPC_PROFILE}
{$define PROFILE_WAS_ACTIVE}
{$profile off}
{$else}
{$undef PROFILE_WAS_ACTIVE}
{$endif}
Procedure Do_SysCall( callnr:longint;var regs : SysCallregs );oldfpccall;assembler;
{
This function puts the registers in place, does the call, and then
copies back the registers as they are after the SysCall.
}
{$ifdef cpui386}
{$ASMMODE ATT}
asm
{ load the registers... }
movl 12(%ebp),%eax
movl 4(%eax),%ebx
movl 8(%eax),%ecx
movl 12(%eax),%edx
movl 16(%eax),%esi
movl 20(%eax),%edi
{ set the call number }
movl 8(%ebp),%eax
{ Go ! }
int $0x80
{ Put back the registers... }
pushl %eax
movl 12(%ebp),%eax
movl %edi,20(%eax)
movl %esi,16(%eax)
movl %edx,12(%eax)
movl %ecx,8(%eax)
movl %ebx,4(%eax)
popl %ebx
movl %ebx,(%eax)
end;
{$ASMMODE DEFAULT}
{$else}
{$ifdef cpum68k}
asm
{ load the registers... }
move.l 12(a6),a0
move.l 4(a0),d1
move.l 8(a0),d2
move.l 12(a0),d3
move.l 16(a0),d4
move.l 20(a0),d5
{ set the call number }
move.l 8(a6),d0
{ Go ! }
trap #0
{ Put back the registers... }
move.l d0,-(sp)
move.l 12(a6),a0
move.l d5,20(a0)
move.l d4,16(a0)
move.l d3,12(a0)
move.l d2,8(a0)
move.l d1,4(a0)
move.l (sp)+,d1
move.l d1,(a0)
end;
{$else}
{$error Cannot decide which processor you have ! define cpui386 or m68k }
{$endif}
{$endif}
{$IFDEF SYSCALL_DEBUG}
Const
DoSysCallDebug : Boolean = False;
var
LastCnt,
LastEax,
LastCall : longint;
DebugTxt : string[20];
{$ENDIF}
Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
{
This function serves as an interface to do_SysCall.
If the SysCall returned a negative number, it returns -1, and puts the
SysCall result in errno. Otherwise, it returns the SysCall return value
}
begin
do_SysCall(callnr,regs);
if (regs.reg1<0) and (regs.reg1>=-Sys_ERROR_MAX) then
begin
{$IFDEF SYSCALL_DEBUG}
If DoSysCallDebug then
debugtxt:=' syscall error: ';
{$endif}
ErrNo:=-regs.reg1;
SysCall:=-1;
end
else
begin
{$IFDEF SYSCALL_DEBUG}
if DoSysCallDebug then
debugtxt:=' syscall returned: ';
{$endif}
SysCall:=regs.reg1;
errno:=0
end;
{$IFDEF SYSCALL_DEBUG}
if DoSysCallDebug then
begin
inc(lastcnt);
if (callnr<>lastcall) or (regs.reg1<>lasteax) then
begin
if lastcnt>1 then
writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
lastcall:=callnr;
lasteax:=regs.reg1;
lastcnt:=0;
writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
end;
end;
{$endif}
end;
{$ifdef PROFILE_WAS_ACTIVE}
{$profile on}
{$undef PROFILE_WAS_ACTIVE}
{$endif}
Function Sys_Time:longint;
var
regs : SysCallregs;
begin
regs.reg2:=0;
Sys_Time:=SysCall(SysCall_nr_time,regs);
end;
{*****************************************************************************
--- File:File handling related calls ---
*****************************************************************************}
Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
var
regs : SysCallregs;
Begin
regs.reg2:=longint(f);
regs.reg3:=flags;
regs.reg4:=mode;
Sys_Open:=SysCall(SysCall_nr_open,regs);
End;
Function Sys_Close(f:longint):longint;
var
regs : SysCallregs;
begin
regs.reg2:=f;
Sys_Close:=SysCall(SysCall_nr_close,regs);
end;
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
var
regs : SysCallregs;
begin
regs.reg2:=f;
regs.reg3:=off;
regs.reg4:=Whence;
Sys_lseek:=SysCall(SysCall_nr_lseek,regs);
end;
Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
var
regs : SysCallregs;
begin
regs.reg2:=f;
regs.reg3:=longint(buffer);
regs.reg4:=count;
Sys_Read:=SysCall(SysCall_nr_read,regs);
end;
Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
var
regs : SysCallregs;
begin
regs.reg2:=f;
regs.reg3:=longint(buffer);
regs.reg4:=count;
Sys_Write:=SysCall(SysCall_nr_write,regs);
end;
Function Sys_Unlink(Filename:pchar):longint;
var
regs : SysCallregs;
begin
regs.reg2:=longint(filename);
Sys_Unlink:=SysCall(SysCall_nr_unlink,regs);
end;
Function Sys_fstat(fd : longint;var Info:stat):Longint;
var
regs : SysCallregs;
begin
regs.reg2:=fd;
regs.reg3:=longint(@Info);
Sys_fStat:=SysCall(SysCall_nr_fstat,regs);
end;
Function Sys_Rename(Oldname,Newname:pchar):longint;
var
regs : SysCallregs;
begin
regs.reg2:=longint(oldname);
regs.reg3:=longint(newname);
Sys_Rename:=SysCall(SysCall_nr_rename,regs);
end;
Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
{
We need this for getcwd
}
var
regs : SysCallregs;
begin
regs.reg2:=longint(filename);
regs.reg3:=longint(@buffer);
Sys_Stat:=SysCall(SysCall_nr_stat,regs);
end;
Function Sys_Symlink(oldname,newname:pchar):longint;
{
We need this for erase
}
var
regs : SysCallregs;
begin
regs.reg2:=longint(oldname);
regs.reg3:=longint(newname);
Sys_symlink:=SysCall(SysCall_nr_symlink,regs);
end;
Function Sys_ReadLink(name,linkname:pchar;maxlen:longint):longint;
var
regs : SysCallRegs;
begin
regs.reg2:=longint(name);
regs.reg3:=longint(linkname);
regs.reg4:=maxlen;
Sys_ReadLink:=SysCall(Syscall_nr_readlink,regs);
end;
{*****************************************************************************
--- Directory:Directory related calls ---
*****************************************************************************}
Function Sys_Chdir(Filename:pchar):longint;
var
regs : SysCallregs;
begin
regs.reg2:=longint(filename);
Sys_ChDir:=SysCall(SysCall_nr_chdir,regs);
end;
Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
var
regs : SysCallregs;
begin
{$if defined(generic_linux_syscalls)}
regs.reg2:=AT_FDCWD;
regs.reg3:=longint(filename);
regs.reg4:=mode;
Sys_MkDir:=SysCall(SysCall_nr_mkdirat,regs);
{$else}
regs.reg2:=longint(filename);
regs.reg3:=mode;
Sys_MkDir:=SysCall(SysCall_nr_mkdir,regs);
{$endif}
end;
Function Sys_Rmdir(Filename:pchar):longint;
var
regs : SysCallregs;
begin
{$if defined(generic_linux_syscalls)}
regs.reg2:=AT_FDCWD;
regs.reg3:=longint(filename);
regs.reg4:=AT_REMOVEDIR;
Sys_Rmdir:=SysCall(SysCall_nr_unlinkat,regs);
{$else}
regs.reg2:=longint(filename);
Sys_Rmdir:=SysCall(SysCall_nr_rmdir,regs);
{$endif}
end;
{ we need this for getcwd }
Function OpenDir(f:pchar):pdir;
var
fd:integer;
st:stat;
ptr:pdir;
begin
opendir:=nil;
if sys_stat(f,st)<0 then
exit;
{ Is it a dir ? }
if not((st.mode and $f000)=$4000)then
begin
errno:=sys_enotdir;
exit
end;
{ Open it}
fd:=sys_open(f,OPEN_RDONLY,438);
if fd<0 then
exit;
new(ptr);
if ptr=nil then
exit;
new(ptr^.buf);
if ptr^.buf=nil then
exit;
ptr^.fd:=fd;
ptr^.loc:=0;
ptr^.size:=0;
ptr^.dd_max:=sizeof(ptr^.buf^);
opendir:=ptr;
end;
function CloseDir(p:pdir):integer;
begin
closedir:=sys_close(p^.fd);
dispose(p^.buf);
dispose(p);
end;
Function Sys_ReadDir(p:pdir):pdirent;
var
regs :SysCallregs;
dummy:longint;
begin
regs.reg3:=longint(p^.buf);
regs.reg2:=p^.fd;
regs.reg4:=1;
dummy:=SysCall(SysCall_nr_readdir,regs);
{ the readdir system call returns the number of bytes written }
if dummy=0 then
sys_readdir:=nil
else
sys_readdir:=p^.buf
end;
{*****************************************************************************
--- Process:Process & program handling - related calls ---
*****************************************************************************}
Function Sys_GetPid:LongInt;
var
regs : SysCallregs;
begin
Sys_GetPid:=SysCall(SysCall_nr_getpid,regs);
end;
Procedure Sys_Exit(ExitCode:Integer);
var
regs : SysCallregs;
begin
regs.reg2:=exitcode;
SysCall(SysCall_nr_exit,regs)
end;
Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
{
Change action of process upon receipt of a signal.
Signum specifies the signal (all except SigKill and SigStop).
If Act is non-nil, it is used to specify the new action.
If OldAct is non-nil the previous action is saved there.
}
Var
sr : Syscallregs;
begin
sr.reg2:=Signum;
sr.reg3:=Longint(act);
sr.reg4:=Longint(oldact);
SysCall(Syscall_nr_sigaction,sr);
end;
function Sys_FTruncate(Handle,Pos:longint):longint; //moved from sysunix.inc Do_Truncate
var
sr : syscallregs;
begin
sr.reg2:=Handle;
sr.reg3:=Pos;
Sys_FTruncate:=syscall(syscall_nr_ftruncate,sr);
end;
Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint; // moved from sysunix.inc, used in sbrk
type
tmmapargs=packed record
address : longint;
size : longint;
prot : longint;
flags : longint;
fd : longint;
offset : longint;
end;
var
t : syscallregs;
mmapargs : tmmapargs;
begin
mmapargs.address:=adr;
mmapargs.size:=len;
mmapargs.prot:=prot;
mmapargs.flags:=flags;
mmapargs.fd:=fdes;
mmapargs.offset:=off;
t.reg2:=longint(@mmapargs);
do_syscall(syscall_nr_mmap,t);
Sys_mmap:=t.reg1;
if t.reg1=-1 then
errno:=-1;
end;
{
Interface to Unix ioctl call.
Performs various operations on the filedescriptor Handle.
Ndx describes the operation to perform.
Data points to data needed for the Ndx function. The structure of this
data is function-dependent.
}
Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; // This was missing here, instead hardcode in Do_IsDevice
var
sr: SysCallRegs;
begin
sr.reg2:=Handle;
sr.reg3:=Ndx;
sr.reg4:=Longint(Data);
Sys_IOCtl:=SysCall(Syscall_nr_ioctl,sr);
end;
Function Sys_SigAltStack(ss, oss :psigaltstack):longint;
var
regs : SysCallregs;
begin
regs.reg2:=longint(ss);
regs.reg3:=longint(oss);
sys_sigaltstack:=SysCall(syscall_nr_sigaltstack,regs);
end;
Function Fork:longint;
{
This function issues the 'fork' System call. the program is duplicated in memory
and Execution continues in parent and child process.
In the parent process, fork returns the PID of the child. In the child process,
zero is returned.
A negative value indicates that an error has occurred, the error is returned in
LinuxError.
}
var
regs:SysCallregs;
begin
Fork:=SysCall(SysCall_nr_fork,regs);
LinuxError:=Errno;
End;
function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
begin
if (pointer(func)=nil) or (sp=nil) then
begin
LinuxError:=Sys_EInval;
exit(-1); // give an error result
end;
{$ifdef cpui386}
{$ASMMODE ATT}
asm
{ Insert the argument onto the new stack. }
movl sp,%ecx
subl $8,%ecx
movl args,%eax
movl %eax,4(%ecx)
{ Save the function pointer as the zeroth argument.
It will be popped off in the child in the ebx frobbing below. }
movl func,%eax
movl %eax,0(%ecx)
{ Do the system call }
pushl %ebx
movl flags,%ebx
movl SysCall_nr_clone,%eax
int $0x80
popl %ebx
test %eax,%eax
jnz .Lclone_end
{ We're in the new thread }
subl %ebp,%ebp { terminate the stack frame }
call *%ebx
{ exit process }
movl %eax,%ebx
movl $1,%eax
int $0x80
.Lclone_end:
movl %eax,__RESULT
end;
{$endif cpui386}
{$ifdef cpum68k}
{ No yet translated, my m68k assembler is too weak for such things PM }
(*
asm
{ Insert the argument onto the new stack. }
movl sp,%ecx
subl $8,%ecx
movl args,%eax
movl %eax,4(%ecx)
{ Save the function pointer as the zeroth argument.
It will be popped off in the child in the ebx frobbing below. }
movl func,%eax
movl %eax,0(%ecx)
{ Do the system call }
pushl %ebx
movl flags,%ebx
movl SysCall_nr_clone,%eax
int $0x80
popl %ebx
test %eax,%eax
jnz .Lclone_end
{ We're in the new thread }
subl %ebp,%ebp { terminate the stack frame }
call *%ebx
{ exit process }
movl %eax,%ebx
movl $1,%eax
int $0x80
.Lclone_end:
movl %eax,__RESULT
end;
*)
{$endif cpum68k}
end;
Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
{
Replaces the current program by the program specified in path,
arguments in args are passed to Execve.
environment specified in ep is passed on.
}
var
regs:SysCallregs;
begin
path:=path+#0;
regs.reg2:=longint(@path[1]);
regs.reg3:=longint(args);
regs.reg4:=longint(ep);
SysCall(SysCall_nr_Execve,regs);
{ This only gets set when the call fails, otherwise we don't get here ! }
Linuxerror:=errno;
end;
Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
{
Replaces the current program by the program specified in path,
arguments in args are passed to Execve.
environment specified in ep is passed on.
}
var
regs:SysCallregs;
begin
regs.reg2:=longint(path);
regs.reg3:=longint(args);
regs.reg4:=longint(ep);
SysCall(SysCall_nr_Execve,regs);
{ This only gets set when the call fails, otherwise we don't get here ! }
Linuxerror:=errno;
end;
Procedure ExitProcess(val:longint);
var
regs : SysCallregs;
begin
regs.reg2:=val;
SysCall(SysCall_nr_exit,regs);
end;
Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
{
Waits until a child with PID Pid exits, or returns if it is exited already.
Any resources used by the child are freed.
The exit status is reported in the adress referred to by Status. It should
be a longint.
}
var
regs : SysCallregs;
begin
regs.reg2:=pid;
regs.reg3:=longint(status);
regs.reg4:=options;
WaitPid:=SysCall(SysCall_nr_waitpid,regs);
LinuxError:=errno;
end;
Procedure GetTimeOfDay(var tv:timeval);
{
Get the number of seconds since 00:00, January 1 1970, GMT
the time NOT corrected any way
}
var
regs : SysCallregs;
begin
regs.reg2:=longint(@tv);
regs.reg3:=0;
SysCall(SysCall_nr_gettimeofday,regs);
LinuxError:=Errno;
end;
Function GetPriority(Which,Who:Integer):integer;
{
Get Priority of process, process group, or user.
Which : selects what kind of priority is used.
can be one of the following predefined Constants :
Prio_User.
Prio_PGrp.
Prio_Process.
Who : depending on which, this is , respectively :
Uid
Pid
Process Group id
Errors are reported in linuxerror _only_. (priority can be negative)
}
var
sr : Syscallregs;
begin
errno:=0;
if (which<prio_process) or (which>prio_user) then
begin
{ We can save an interrupt here }
getpriority:=0;
linuxerror:=Sys_einval;
end
else
begin
sr.reg2:=which;
sr.reg3:=who;
getpriority:=SysCall(Syscall_nr_getpriority,sr);
linuxerror:=errno;
end;
end;
Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
{
Set Priority of process, process group, or user.
Which : selects what kind of priority is used.
can be one of the following predefined Constants :
Prio_User.
Prio_PGrp.
Prio_Process.
Who : depending on value of which, this is, respectively :
Uid
Pid
Process Group id
what : A number between -20 and 20. -20 is most favorable, 20 least.
0 is the default.
}
var
sr : Syscallregs;
begin
errno:=0;
if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
linuxerror:=Sys_einval { We can save an interrupt here }
else
begin
sr.reg2:=which;
sr.reg3:=who;
sr.reg4:=what;
SysCall(Syscall_nr_setpriority,sr);
linuxerror:=errno;
end;
end;
Procedure Nice(N:integer);
{
Set process priority. A positive N means a lower priority.
A negative N decreases priority.
}
var
sr : Syscallregs;
begin
sr.reg2:=n;
SysCall(Syscall_nr_nice,sr);
linuxerror:=errno;
end;
Function GetPid:LongInt;
{
Get Process ID.
}
var
regs : SysCallregs;
begin
GetPid:=SysCall(SysCall_nr_getpid,regs);
linuxerror:=errno;
end;
Function GetPPid:LongInt;
{
Get Process ID of parent process.
}
var
regs : SysCallregs;
begin
GetPpid:=SysCall(SysCall_nr_getppid,regs);
linuxerror:=errno;
end;
Function GetUid:Longint;
{
Get User ID.
}
var
regs : SysCallregs;
begin
GetUid:=SysCall(SysCall_nr_getuid,regs);
Linuxerror:=errno;
end;
Function GetEUid:Longint;
{
Get _effective_ User ID.
}
var
regs : SysCallregs;
begin
GetEuid:=SysCall(SysCall_nr_geteuid,regs);
Linuxerror:=errno;
end;
Function GetGid:Longint;
{
Get Group ID.
}
var
regs : SysCallregs;
begin
Getgid:=SysCall(SysCall_nr_getgid,regs);
Linuxerror:=errno;
end;
Function GetEGid:Longint;
{
Get _effective_ Group ID.
}
var
regs : SysCallregs;
begin
GetEgid:=SysCall(SysCall_nr_getegid,regs);
Linuxerror:=errno;
end;
Function GetTimeOfDay: longint;
{
Get the number of seconds since 00:00, January 1 1970, GMT
the time NOT corrected any way
}
var
regs : SysCallregs;
tv : timeval;
begin
regs.reg2:=longint(@tv);
regs.reg3:=0;
SysCall(SysCall_nr_gettimeofday,regs);
LinuxError:=Errno;
GetTimeOfDay:=tv.sec;
end;
Function fdTruncate(fd,size:longint):boolean;
var
Regs : SysCallRegs;
begin
Regs.reg2:=fd;
Regs.reg3:=size;
fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
LinuxError:=Errno;
end;
Function fdFlush (fd : Longint) : Boolean;
var
SR: SysCallRegs;
begin
SR.reg2 := fd;
fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
LinuxError:=Errno;
end;
Function Fcntl(Fd:longint;Cmd:longint): longint;
{
Read or manipulate a file.(See also fcntl (2) )
Possible values for Cmd are :
F_GetFd,F_GetFl,F_GetOwn
Errors are reported in Linuxerror;
If Cmd is different from the allowed values, linuxerror=Sys_eninval.
}
var
sr : Syscallregs;
begin
if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
begin
sr.reg2:=Fd;
sr.reg3:=cmd;
Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
if linuxerror=-1 then
begin
linuxerror:=errno;
fcntl:=0;
end
else
begin
fcntl:=linuxerror;
linuxerror:=0;
end;
end
else
begin
linuxerror:=Sys_einval;
Fcntl:=0;
end;
end;
Procedure Fcntl(Fd:longint;Cmd:LongInt;Arg:Longint);
{
Read or manipulate a file. (See also fcntl (2) )
Possible values for Cmd are :
F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
Errors are reported in Linuxerror;
If Cmd is different from the allowed values, linuxerror=Sys_eninval.
F_DupFD is not allowed, due to the structure of Files in Pascal.
}
var
sr : Syscallregs;
begin
if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
begin
sr.reg2:=Fd;
sr.reg3:=cmd;
sr.reg4:=arg;
SysCall(Syscall_nr_fcntl,sr);
linuxerror:=errno;
end
else
linuxerror:=Sys_einval;
end;
Function Chmod(path:pathstr;Newmode:longint):Boolean;
{
Changes the permissions of a file.
}
var
sr : Syscallregs;
begin
path:=path+#0;
sr.reg2:=longint(@(path[1]));
sr.reg3:=newmode;
Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
linuxerror:=errno;
end;
Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
{
Change the owner and group of a file.
A user can only change the group to a group of which he is a member.
The super-user can change uid and gid of any file.
}
var
sr : Syscallregs;
begin
path:=path+#0;
sr.reg2:=longint(@(path[1]));
sr.reg3:=newuid;
sr.reg4:=newgid;
ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
linuxerror:=errno;
end;
Function Utime(const path:pathstr;utim:utimebuf):boolean;
var
sr : Syscallregs;
buf : pathstr;
begin
buf:=path+#0;
sr.reg2:=longint(@(buf[1]));
sr.reg3:=longint(@utim);
Utime:=SysCall(Syscall_nr_utime,sr)=0;
linuxerror:=errno;
end;
Function Flock (fd,mode : longint) : boolean;
var
sr : Syscallregs;
begin
sr.reg2:=fd;
sr.reg3:=mode;
flock:=Syscall(Syscall_nr_flock,sr)=0;
LinuxError:=errno;
end;
Function Fstat(Fd:Longint;var Info:stat):Boolean;
{
Get all information on a file descriptor, and return it in info.
}
var
regs : SysCallregs;
begin
regs.reg2:=Fd;
regs.reg3:=longint(@Info);
FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
LinuxError:=Errno;
end;
Function Lstat(Filename: PathStr;var Info:stat):Boolean;
{
Get all information on a link (the link itself), and return it in info.
}
var
regs : SysCallregs;
begin
FileName:=FileName+#0;
regs.reg2:=longint(@filename[1]);
regs.reg3:=longint(@Info);
LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
LinuxError:=Errno;
end;
Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
{
Get all information on a fileSystem, and return it in Info.
Path is the name of a file/directory on the fileSystem you wish to
investigate.
}
var
regs : SysCallregs;
begin
path:=path+#0;
regs.reg2:=longint(@path[1]);
regs.reg3:=longint(@Info);
FSStat:=(SysCall(SysCall_nr_statfs,regs)=0);
LinuxError:=errno;
end;
Function FSStat(Fd:Longint;Var Info:statfs):Boolean;
{
Get all information on a fileSystem, and return it in Info.
Fd is the file descriptor of a file/directory on the fileSystem
you wish to investigate.
}
var
regs : SysCallregs;
begin
regs.reg2:=Fd;
regs.reg3:=longint(@Info);
FSStat:=(SysCall(SysCall_nr_fstatfs,regs)=0);
LinuxError:=errno;
end;
Function Link(OldPath,NewPath:pathstr):boolean;
{
Proceduces a hard link from new to old.
In effect, new will be the same file as old.
}
var
regs : SysCallregs;
begin
oldpath:=oldpath+#0;
newpath:=newpath+#0;
regs.reg2:=longint(@oldpath[1]);
regs.reg3:=longint(@newpath[1]);
Link:=SysCall(SysCall_nr_link,regs)=0;
linuxerror:=errno;
end;
Function Umask(Mask:Integer):integer;
{
Sets file creation mask to (Mask and 0777 (octal) ), and returns the
previous value.
}
var
sr : Syscallregs;
begin
sr.reg2:=mask;
Umask:=SysCall(Syscall_nr_umask,sr);
linuxerror:=0;
end;
Function Access(Path:Pathstr ;mode:integer):boolean;
{
Test users access rights on the specified file.
Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
R,W,X stand for read,write and Execute access, simultaneously.
F_OK checks whether the test would be allowed on the file.
i.e. It checks the search permissions in all directory components
of the path.
The test is done with the real user-ID, instead of the effective.
If access is denied, or an error occurred, false is returned.
If access is granted, true is returned.
Errors other than no access,are reported in linuxerror.
}
var
sr : Syscallregs;
begin
path:=path+#0;
sr.reg2:=longint(@(path[1]));
sr.reg3:=mode;
access:=(SysCall(Syscall_nr_access,sr)=0);
linuxerror:=errno;
end;
Function Dup(oldfile:longint;var newfile:longint):Boolean;
{
Copies the filedescriptor oldfile to newfile
}
var
sr : Syscallregs;
begin
sr.reg2:=oldfile;
newfile:=Syscall(Syscall_nr_dup,sr);
linuxerror:=errno;
Dup:=(LinuxError=0);
end;
Function Dup2(oldfile,newfile:longint):Boolean;
{
Copies the filedescriptor oldfile to newfile
}
var
sr : Syscallregs;
begin
sr.reg2:=oldfile;
sr.reg3:=newfile;
{$if defined(generic_linux_syscalls)}
sr.reg4:=0;
if oldfile<>newfile then
SysCall(Syscall_nr_dup3,sr)
else
begin
sr.reg3:=F_GetFd;
SysCall(Syscall_nr_fcntl,sr);
end;
{$else}
SysCall(Syscall_nr_dup2,sr);
{$endif}
linuxerror:=errno;
Dup2:=(LinuxError=0);
end;
Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
{
Select checks whether the file descriptor sets in readfs/writefs/exceptfs
have changed.
}
Var
SelectArray : Array[1..5] of longint;
Sr : Syscallregs;
begin
SelectArray[1]:=n;
SelectArray[2]:=longint(Readfds);
Selectarray[3]:=longint(Writefds);
selectarray[4]:=longint(exceptfds);
Selectarray[5]:=longint(TimeOut);
sr.reg2:=longint(@selectarray);
Select:=SysCall(Syscall_nr_select,sr);
LinuxError:=Errno;
end;
Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
{
Sets up a pair of file variables, which act as a pipe. The first one can
be read from, the second one can be written to.
If the operation was unsuccesful, linuxerror is set.
}
var
pip : tpipe;
regs : SysCallregs;
begin
regs.reg2:=longint(@pip);
{$if defined(generic_linux_syscalls)}
regs.reg3:=0;
SysCall(SysCall_nr_pipe2,regs);
{$else}
SysCall(SysCall_nr_pipe,regs);
{$endif}
pipe_in:=pip[1];
pipe_out:=pip[2];
linuxerror:=errno;
AssignPipe:=(LinuxError=0);
end;
Function PClose(Var F:text) :longint;
var
sr : syscallregs;
pl : ^longint;
res : longint;
begin
sr.reg2:=Textrec(F).Handle;
SysCall (syscall_nr_close,sr);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=plongint(@(textrec(f).userdata[2]));
waitpid(pl^,@res,0);
pclose:=res shr 8;
end;
Function PClose(Var F:file) : longint;
var
sr : syscallregs;
pl : ^longint;
res : longint;
begin
sr.reg2:=FileRec(F).Handle;
SysCall (Syscall_nr_close,sr);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=plongint(@(filerec(f).userdata[2]));
waitpid(pl^,@res,0);
pclose:=res shr 8;
end;
Function Sysinfo(var Info:TSysinfo):Boolean;
{
Get system info
}
var
regs : SysCallregs;
Begin
regs.reg2:=longint(@info);
Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
End;
Function mkFifo(pathname:string;mode:longint):boolean;
var
regs : SysCallRegs;
begin
pathname:=pathname+#0;
regs.reg2:=longint(@pathname[1]);
regs.reg3:=mode or STAT_IFIFO;
regs.reg4:=0;
mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
end;
Function Uname(var unamerec:utsname):Boolean;
{
Get machine's names
}
var
regs : SysCallregs;
Begin
regs.reg2:=longint(@unamerec);
Uname:=SysCall(SysCall_nr_uname,regs)=0;
LinuxError:=Errno;
End;
Function Kill(Pid:longint;Sig:longint):integer;
{
Send signal 'sig' to a process, or a group of processes.
If Pid > 0 then the signal is sent to pid
pid=-1 to all processes except process 1
pid < -1 to process group -pid
Return value is zero, except for case three, where the return value
is the number of processes to which the signal was sent.
}
var
regs : Syscallregs;
begin
regs.reg2:=Pid;
regs.reg3:=Sig;
kill:=SysCall(Syscall_nr_kill,regs);
if kill<0 then
Kill:=0;
linuxerror:=errno;
end;
Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
{
Change the list of currently blocked signals.
How determines which signals will be blocked :
SigBlock : Add SSet to the current list of blocked signals
SigUnBlock : Remove the signals in SSet from the list of blocked signals.
SigSetMask : Set the list of blocked signals to SSet
if OldSSet is non-null, the old set will be saved there.
}
Var
sr : SyscallRegs;
begin
sr.reg2:=how;
sr.reg3:=longint(SSet);
sr.reg4:=longint(OldSSet);
SysCall(Syscall_nr_sigprocmask,sr);
linuxerror:=errno;
end;
Function SigPending:SigSet;
{
Allows examination of pending signals. The signal mask of pending
signals is set in SSet
}
Var
sr : SyscallRegs;
dummy : Sigset;
begin
sr.reg2:=longint(@dummy);
SysCall(Syscall_nr_sigpending,sr);
linuxerror:=errno;
Sigpending:=dummy;
end;
Procedure SigSuspend(Mask:Sigset);
{
Set the signal mask with Mask, and suspend the program until a signal
is received.
}
Var
sr : SyscallRegs;
begin
sr.reg2:=mask;
SysCall(Syscall_nr_sigsuspend,sr);
linuxerror:=errno;
end;
Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
{
Install a new handler for signal Signum.
The old signal handler is returned.
This call does, in fact, the same as SigAction.
}
var
sr : Syscallregs;
begin
sr.reg2:=signum;
sr.reg3:=longint(handler);
Linuxerror:=SysCall(Syscall_nr_signal,sr);
If linuxerror=Sig_Err then
begin
Signal:=nil;
Linuxerror:=errno;
end
else
begin
Signal:=signalhandler(Linuxerror);
linuxerror:=0;
end;
end;
Function Alarm(Sec : Longint) : longint;
Var Sr : Syscallregs;
begin
sr.reg2:=Sec;
Alarm:=Syscall(syscall_nr_alarm,sr);
end;
Procedure Pause;
Var Sr : Syscallregs;
begin
syscall(syscall_nr_pause,sr);
end;
Function NanoSleep(const req : timespec;var rem : timespec) : longint;
var Sr : Syscallregs;
begin
sr.reg2:=longint(@req);
sr.reg3:=longint(@rem);
NanoSleep:=Syscall(syscall_nr_nanosleep,sr);
LinuxError:=Errno;
end;
Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
{
Interface to Unix ioctl call.
Performs various operations on the filedescriptor Handle.
Ndx describes the operation to perform.
Data points to data needed for the Ndx function. The structure of this
data is function-dependent.
}
var
sr: SysCallRegs;
begin
sr.reg2:=Handle;
sr.reg3:=Ndx;
sr.reg4:=Longint(Data);
IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
LinuxError:=Errno;
end;
function MMap(const m:tmmapargs):longint;
Var
Sr : Syscallregs;
begin
Sr.reg2:=longint(@m);
MMap:=syscall(syscall_nr_mmap,sr);
LinuxError:=Errno;
end;
function MUnMap (P : Pointer; Size : Longint) : Boolean;
Var
Sr : Syscallregs;
begin
Sr.reg2:=longint(P);
sr.reg3:=Size;
MUnMap:=syscall(syscall_nr_munmap,sr)=0;
LinuxError:=Errno;
end;
{--------------------------------
Port IO functions
--------------------------------}
Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
{
Set permissions on NUM ports starting with port FROM to VALUE
this works ONLY as root.
}
Var
Sr : Syscallregs;
begin
Sr.Reg2:=From;
Sr.Reg3:=Num;
Sr.Reg4:=Value;
IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
LinuxError:=Errno;
end;
Function IoPL(Level : longint) : Boolean;
Var
Sr : Syscallregs;
begin
Sr.Reg2:=Level;
IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
LinuxError:=Errno;
end;
{******************************************************************************
Process related calls
******************************************************************************}
{ Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
var r,s : LongInt;
begin
repeat
s:=$7F00;
r:=WaitPid(Pid,@s,0);
until (r<>-1) or (LinuxError<>Sys_EINTR);
if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
WaitProcess:=-1 // return -1 to indicate an error
else
begin
{$ifdef solaris}
if (s and $FF)=0 then // Only this is a valid returncode
{$else solaris}
{ the following is at least correct for Linux and Darwin (JM) }
if (s and $7F)=0 then
{$endif solaris}
WaitProcess:=s shr 8
else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
WaitProcess:=-s // normal case
else
WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
end;
end;
function InternalCreateShellArgV(cmd:pChar; len:longint):ppchar;
{
Create an argv which executes a command in a shell using /bin/sh -c
}
const Shell = '/bin/sh'#0'-c'#0;
var
pp,p : ppchar;
// temp : string; !! Never pass a local var back!!
begin
getmem(pp,4*4);
p:=pp;
p^:=@Shell[1];
inc(p);
p^:=@Shell[9];
inc(p);
getmem(p^,len+1);
move(cmd^,p^^,len);
pchar(p^)[len]:=#0;
inc(p);
p^:=Nil;
InternalCreateShellArgV:=pp;
end;
function CreateShellArgV(const prog:string):ppchar;
begin
CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
end;
function CreateShellArgV(const prog:Ansistring):ppchar;
{
Create an argv which executes a command in a shell using /bin/sh -c
using a AnsiString;
}
begin
CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
end;
procedure FreeShellArgV(p:ppchar);
begin
if (p<>nil) then begin
freemem(p[2]);
freemem(p);
end;
end;
Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
{
overloaded ansistring version.
}
begin
ExecVE(PChar(Path),args,ep);
end;
Procedure Execv(const path: AnsiString;args:ppchar);
{
Overloaded ansistring version.
}
begin
ExecVe(Path,Args,envp)
end;
Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
{
Overloaded ansistring version
}
var
thepath : Ansistring;
begin
if path[1]<>'/' then
begin
Thepath:=strpas(getenv('PATH'));
if thepath='' then
thepath:='.';
Path:=FSearch(path,thepath)
end
else
Path:='';
if Path='' then
linuxerror:=Sys_enoent
else
Execve(Path,args,ep);{On error linuxerror will get set there}
end;
Procedure Execv(const path:pathstr;args:ppchar);
{
Replaces the current program by the program specified in path,
arguments in args are passed to Execve.
the current environment is passed on.
}
begin
Execve(path,args,envp); {On error linuxerror will get set there}
end;
Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
{
This does the same as Execve, only it searches the PATH environment
for the place of the Executable, except when Path starts with a slash.
if the PATH environment variable is unavailable, the path is set to '.'
}
var
thepath : string;
begin
if path[1]<>'/' then
begin
Thepath:=strpas(getenv('PATH'));
if thepath='' then
thepath:='.';
Path:=FSearch(path,thepath)
end
else
Path:='';
if Path='' then
linuxerror:=Sys_enoent
else
Execve(Path,args,ep);{On error linuxerror will get set there}
end;
Procedure Execle(Todo:string;Ep:ppchar);
{
This procedure takes the string 'Todo', parses it for command and
command options, and Executes the command with the given options.
The string 'Todo' shoud be of the form 'command options', options
separated by commas.
the PATH environment is not searched for 'command'.
The specified environment(in 'ep') is passed on to command
}
var
p : ppchar;
begin
p:=StringToPPChar(ToDo);
if (p=nil) or (p^=nil) then
exit;
ExecVE(p^,p,EP);
end;
Procedure Execle(Todo:AnsiString;Ep:ppchar);
{
This procedure takes the string 'Todo', parses it for command and
command options, and Executes the command with the given options.
The string 'Todo' shoud be of the form 'command options', options
separated by commas.
the PATH environment is not searched for 'command'.
The specified environment(in 'ep') is passed on to command
}
var
p : ppchar;
begin
p:=StringToPPChar(ToDo);
if (p=nil) or (p^=nil) then
exit;
ExecVE(p^,p,EP);
end;
Procedure Execl(const Todo:string);
{
This procedure takes the string 'Todo', parses it for command and
command options, and Executes the command with the given options.
The string 'Todo' shoud be of the form 'command options', options
separated by commas.
the PATH environment is not searched for 'command'.
The current environment is passed on to command
}
begin
ExecLE(ToDo,EnvP);
end;
Procedure Execl(const Todo:Ansistring);
{
Overloaded AnsiString Version of ExecL.
}
begin
ExecLE(ToDo,EnvP);
end;
Procedure Execlp(Todo:string;Ep:ppchar);
{
This procedure takes the string 'Todo', parses it for command and
command options, and Executes the command with the given options.
The string 'Todo' shoud be of the form 'command options', options
separated by commas.
the PATH environment is searched for 'command'.
The specified environment (in 'ep') is passed on to command
}
var
p : ppchar;
begin
p:=StringToPPchar(todo);
if (p=nil) or (p^=nil) then
exit;
ExecVP(StrPas(p^),p,EP);
end;
Procedure Execlp(Todo: Ansistring;Ep:ppchar);
{
Overloaded ansistring version.
}
var
p : ppchar;
begin
p:=StringToPPchar(todo);
if (p=nil) or (p^=nil) then
exit;
ExecVP(StrPas(p^),p,EP);
end;
Function Shell(const Command:String):Longint;
{
Executes the shell, and passes it the string Command. (Through /bin/sh -c)
The current environment is passed to the shell.
It waits for the shell to exit, and returns its exit status.
If the Exec call failed exit status 127 is reported.
}
{ Changed the structure:
- the previous version returns an undefinied value if fork fails
- it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
- it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
- ShellArgs are now released
- The Old CreateShellArg gives back pointers to a local var
}
var
p : ppchar;
pid,r,s : longint;
begin
p:=CreateShellArgv(command);
pid:=fork;
if pid=0 then // We are in the Child
begin
{This is the child.}
Execve(p^,p,envp);
ExitProcess(127); // was Exit(127)
end
else if (pid<>-1) then // Successfull started
begin
repeat
s:=$7F00;
r:=WaitPid(Pid,@s,0);
until (r<>-1) or (LinuxError<>Sys_EINTR);
if (r=-1) or (r=0) then
Shell:=-1
else
Shell:=s;
end
else // no success
Shell:=-1; // indicate an error
FreeShellArgV(p);
end;
Function Shell(const Command:AnsiString):Longint;
{
AnsiString version of Shell
}
var
p : ppchar;
pid : longint;
begin { Changes as above }
p:=CreateShellArgv(command);
pid:=fork;
if pid=0 then // We are in the Child
begin
Execve(p^,p,envp);
ExitProcess(127); // was exit(127)!! We must exit the Process, not the function
end
else if (pid<>-1) then // Successfull started
Shell:=WaitProcess(pid) {Linuxerror is set there}
else // no success
Shell:=-1;
FreeShellArgV(p);
end;
function WEXITSTATUS(Status: Integer): Integer;
begin
WEXITSTATUS:=(Status and $FF00) shr 8;
end;
function WTERMSIG(Status: Integer): Integer;
begin
WTERMSIG:=(Status and $7F);
end;
function WSTOPSIG(Status: Integer): Integer;
begin
WSTOPSIG:=WEXITSTATUS(Status);
end;
Function WIFEXITED(Status: Integer): Boolean;
begin
WIFEXITED:=(WTERMSIG(Status)=0);
end;
Function WIFSTOPPED(Status: Integer): Boolean;
begin
WIFSTOPPED:=((Status and $FF)=$7F);
end;
Function WIFSIGNALED(Status: Integer): Boolean;
begin
WIFSIGNALED:=(not WIFSTOPPED(Status)) and
(not WIFEXITED(Status));
end;
Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
begin
W_EXITCODE:=(ReturnCode shl 8) or Signal;
end;
Function W_STOPCODE(Signal: Integer): Integer;
begin
W_STOPCODE:=(Signal shl 8) or $7F;
end;
{******************************************************************************
Date and Time related calls
******************************************************************************}
Const
{Date Translation}
C1970=2440588;
D0 = 1461;
D1 = 146097;
D2 =1721119;
Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
Var
Century,XYear: LongInt;
Begin
If Month<=2 Then
Begin
Dec(Year);
Inc(Month,12);
End;
Dec(Month,3);
Century:=(longint(Year Div 100)*D1) shr 2;
XYear:=(longint(Year Mod 100)*D0) shr 2;
GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
End;
Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
Var
YYear,XYear,Temp,TempMonth : LongInt;
Begin
Temp:=((JulianDN-D2) shl 2)-1;
JulianDN:=Temp Div D1;
XYear:=(Temp Mod D1) or 3;
YYear:=(XYear Div D0);
Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
Day:=((Temp Mod 153)+5) Div 5;
TempMonth:=Temp Div 153;
If TempMonth>=10 Then
Begin
inc(YYear);
dec(TempMonth,12);
End;
inc(TempMonth,3);
Month := TempMonth;
Year:=YYear+(JulianDN*100);
end;
Function GetEpochTime: longint;
{
Get the number of seconds since 00:00, January 1 1970, GMT
the time NOT corrected any way
}
begin
GetEpochTime:=GetTimeOfDay;
end;
Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
{
Transforms Epoch time into local time (hour, minute,seconds)
}
Var
DateNum: LongInt;
Begin
inc(Epoch,TZSeconds);
Datenum:=(Epoch Div 86400) + c1970;
JulianToGregorian(DateNum,Year,Month,day);
Epoch:=Abs(Epoch Mod 86400);
Hour:=Epoch Div 3600;
Epoch:=Epoch Mod 3600;
Minute:=Epoch Div 60;
Second:=Epoch Mod 60;
End;
Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
{
Transforms local time (year,month,day,hour,minutes,second) to Epoch time
(seconds since 00:00, january 1 1970, corrected for local time zone)
}
Begin
LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
(LongInt(Hour)*3600)+(Minute*60)+Second-TZSeconds;
End;
procedure GetTime(var hour,min,sec,msec,usec:word);
{
Gets the current time, adjusted to local time
}
var
year,day,month:Word;
t : timeval;
begin
gettimeofday(t);
EpochToLocal(t.sec,year,month,day,hour,min,sec);
msec:=t.usec div 1000;
usec:=t.usec mod 1000;
end;
procedure GetTime(var hour,min,sec,sec100:word);
{
Gets the current time, adjusted to local time
}
var
usec : word;
begin
gettime(hour,min,sec,sec100,usec);
sec100:=sec100 div 10;
end;
Procedure GetTime(Var Hour,Min,Sec:Word);
{
Gets the current time, adjusted to local time
}
var
msec,usec : Word;
Begin
gettime(hour,min,sec,msec,usec);
End;
Procedure GetDate(Var Year,Month,Day:Word);
{
Gets the current date, adjusted to local time
}
var
hour,minute,second : word;
Begin
EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
End;
Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
{
Gets the current date, adjusted to local time
}
Begin
EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
End;
{$ifndef BSD} {Fix for 1.0.x starting compiler only}
{$ifdef linux}
Function stime (t : longint) : Boolean;
var
sr : Syscallregs;
begin
sr.reg2:=longint(@t);
SysCall(Syscall_nr_stime,sr);
linuxerror:=errno;
stime:=linuxerror=0;
end;
{$endif}
{$endif}
{$ifdef BSD}
Function stime (t : longint) : Boolean;
begin
stime:=false;
end;
{$endif}
Function SetTime(Hour,Min,Sec:word) : boolean;
var
Year, Month, Day : Word;
begin
GetDate (Year, Month, Day);
SetTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Min, Sec ) );
end;
Function SetDate(Year,Month,Day:Word) : boolean;
var
Hour, Minute, Second, Sec100 : Word;
begin
GetTime ( Hour, Minute, Second, Sec100 );
SetDate:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
end;
Function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
begin
SetDateTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
end;
{ Include timezone handling routines which use /usr/share/timezone info }
type
plongint=^longint;
pbyte=^byte;
ttzhead=packed record
tzh_reserved : array[0..19] of byte;
tzh_ttisgmtcnt,
tzh_ttisstdcnt,
tzh_leapcnt,
tzh_timecnt,
tzh_typecnt,
tzh_charcnt : longint;
end;
pttinfo=^tttinfo;
tttinfo=packed record
offset : longint;
isdst : boolean;
idx : byte;
isstd : byte;
isgmt : byte;
end;
pleap=^tleap;
tleap=record
transition : longint;
change : longint;
end;
var
num_transitions,
num_leaps,
num_types : longint;
transitions : plongint;
type_idxs : pbyte;
types : pttinfo;
zone_names : pchar;
leaps : pleap;
function find_transition(timer:longint):pttinfo;
var
i : longint;
begin
if (num_transitions=0) or (timer<transitions[0]) then
begin
i:=0;
while (i<num_types) and (types[i].isdst) do
inc(i);
if (i=num_types) then
i:=0;
end
else
begin
for i:=1 to num_transitions do
if (timer<transitions[i]) then
break;
i:=type_idxs[i-1];
end;
find_transition:=@types[i];
end;
procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
var
info : pttinfo;
i : longint;
begin
{ reset }
TZDaylight:=false;
TZSeconds:=0;
TZName[false]:=nil;
TZName[true]:=nil;
leap_correct:=0;
leap_hit:=0;
{ get info }
info:=find_transition(timer);
if not assigned(info) then
exit;
TZDaylight:=info^.isdst;
TZSeconds:=info^.offset;
i:=0;
while (i<num_types) do
begin
tzname[types[i].isdst]:=@zone_names[types[i].idx];
inc(i);
end;
tzname[info^.isdst]:=@zone_names[info^.idx];
i:=num_leaps;
repeat
if i=0 then
exit;
dec(i);
until (timer>leaps[i].transition);
leap_correct:=leaps[i].change;
if (timer=leaps[i].transition) and
(((i=0) and (leaps[i].change>0)) or
(leaps[i].change>leaps[i-1].change)) then
begin
leap_hit:=1;
while (i>0) and
(leaps[i].transition=leaps[i-1].transition+1) and
(leaps[i].change=leaps[i-1].change+1) do
begin
inc(leap_hit);
dec(i);
end;
end;
end;
procedure GetLocalTimezone(timer:longint);
var
lc,lh : longint;
begin
GetLocalTimezone(timer,lc,lh);
end;
procedure ReadTimezoneFile(fn:string);
procedure decode(var l:longint);
var
k : longint;
p : pbyte;
begin
p:=pbyte(@l);
if (p[0] and (1 shl 7))<>0 then
k:=not 0
else
k:=0;
k:=(k shl 8) or p[0];
k:=(k shl 8) or p[1];
k:=(k shl 8) or p[2];
k:=(k shl 8) or p[3];
l:=k;
end;
var
f : longint;
tzdir : string;
tzhead : ttzhead;
i : longint;
chars : longint;
buf : pbyte;
begin
if fn='' then
fn:='localtime';
if fn[1]<>'/' then
begin
tzdir:=getenv('TZDIR');
if tzdir='' then
tzdir:='/usr/share/zoneinfo';
if tzdir[length(tzdir)]<>'/' then
tzdir:=tzdir+'/';
fn:=tzdir+fn;
end;
f:=fdopen(fn,Open_RdOnly);
if f<0 then
exit;
i:=fdread(f,tzhead,sizeof(tzhead));
if i<>sizeof(tzhead) then
exit;
decode(tzhead.tzh_timecnt);
decode(tzhead.tzh_typecnt);
decode(tzhead.tzh_charcnt);
decode(tzhead.tzh_leapcnt);
decode(tzhead.tzh_ttisstdcnt);
decode(tzhead.tzh_ttisgmtcnt);
num_transitions:=tzhead.tzh_timecnt;
num_types:=tzhead.tzh_typecnt;
chars:=tzhead.tzh_charcnt;
reallocmem(transitions,num_transitions*sizeof(longint));
reallocmem(type_idxs,num_transitions);
reallocmem(types,num_types*sizeof(tttinfo));
reallocmem(zone_names,chars);
reallocmem(leaps,num_leaps*sizeof(tleap));
fdread(f,transitions^,num_transitions*4);
fdread(f,type_idxs^,num_transitions);
for i:=0 to num_transitions-1 do
decode(transitions[i]);
for i:=0 to num_types-1 do
begin
fdread(f,types[i].offset,4);
fdread(f,types[i].isdst,1);
fdread(f,types[i].idx,1);
decode(types[i].offset);
types[i].isstd:=0;
types[i].isgmt:=0;
end;
fdread(f,zone_names^,chars);
for i:=0 to num_leaps-1 do
begin
fdread(f,leaps[i].transition,4);
fdread(f,leaps[i].change,4);
decode(leaps[i].transition);
decode(leaps[i].change);
end;
getmem(buf,tzhead.tzh_ttisstdcnt);
fdread(f,buf^,tzhead.tzh_ttisstdcnt);
for i:=0 to tzhead.tzh_ttisstdcnt-1 do
types[i].isstd:=byte(buf[i]<>0);
freemem(buf);
getmem(buf,tzhead.tzh_ttisgmtcnt);
fdread(f,buf^,tzhead.tzh_ttisgmtcnt);
for i:=0 to tzhead.tzh_ttisgmtcnt-1 do
types[i].isgmt:=byte(buf[i]<>0);
freemem(buf);
fdclose(f);
end;
Const
// Debian system; contains location of timezone file.
TimeZoneLocationFile = '/etc/timezone';
// SuSE has link in /usr/lib/zoneinfo/localtime to /etc/localtime
// RedHat uses /etc/localtime
TimeZoneFile = '/usr/lib/zoneinfo/localtime';
AltTimeZoneFile = '/etc/localtime';
function GetTimezoneFile:string;
var
f,len : longint;
s : string;
info : stat;
begin
GetTimezoneFile:='';
f:=fdopen(TimeZoneLocationFile,Open_RdOnly);
if f>0 then
begin
len:=fdread(f,s[1],high(s));
s[0]:=chr(len);
len:=pos(#10,s);
if len<>0 then
s[0]:=chr(len-1);
fdclose(f);
GetTimezoneFile:=s;
end
// Try SuSE
else if fstat(TimeZoneFile,info) then
GetTimeZoneFile:=TimeZoneFile
// Try RedHat
else If fstat(AltTimeZoneFile,Info) then
GetTimeZoneFile:=AltTimeZoneFile;
end;
procedure InitLocalTime;
begin
ReadTimezoneFile(GetTimezoneFile);
GetLocalTimezone(GetTimeOfDay);
end;
procedure DoneLocalTime;
begin
if assigned(transitions) then
freemem(transitions);
if assigned(type_idxs) then
freemem(type_idxs);
if assigned(types) then
freemem(types);
if assigned(zone_names) then
freemem(zone_names);
if assigned(leaps) then
freemem(leaps);
num_transitions:=0;
num_leaps:=0;
num_types:=0;
end;
{******************************************************************************
FileSystem calls
******************************************************************************}
Function fdOpen(pathname:string;flags:longint):longint;
begin
pathname:=pathname+#0;
fdOpen:=Sys_Open(@pathname[1],flags,438);
LinuxError:=Errno;
end;
Function fdOpen(pathname:string;flags,mode:longint):longint;
begin
pathname:=pathname+#0;
fdOpen:=Sys_Open(@pathname[1],flags,mode);
LinuxError:=Errno;
end;
Function fdOpen(pathname:pchar;flags:longint):longint;
begin
fdOpen:=Sys_Open(pathname,flags,0);
LinuxError:=Errno;
end;
Function fdOpen(pathname:pchar;flags,mode:longint):longint;
begin
fdOpen:=Sys_Open(pathname,flags,mode);
LinuxError:=Errno;
end;
Function fdClose(fd:longint):boolean;
begin
fdClose:=(Sys_Close(fd)=0);
LinuxError:=Errno;
end;
Function fdRead(fd:longint;var buf;size:longint):longint;
begin
fdRead:=Sys_Read(fd,pchar(@buf),size);
LinuxError:=Errno;
end;
Function fdWrite(fd:longint;const buf;size:longint):longint;
begin
fdWrite:=Sys_Write(fd,pchar(@buf),size);
LinuxError:=Errno;
end;
Function fdSeek (fd,pos,seektype :longint): longint;
{
Do a Seek on a file descriptor fd to position pos, starting from seektype
}
begin
fdseek:=Sys_LSeek (fd,pos,seektype);
LinuxError:=Errno;
end;
{$ifdef BSD}
Function Fcntl(Fd:longint;Cmd:longint):longint;
{
Read or manipulate a file.(See also fcntl (2) )
Possible values for Cmd are :
F_GetFd,F_GetFl,F_GetOwn
Errors are reported in Linuxerror;
If Cmd is different from the allowed values, linuxerror=Sys_eninval.
}
begin
if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
begin
Linuxerror:=sys_fcntl(fd,cmd,0);
if linuxerror=-1 then
begin
linuxerror:=errno;
fcntl:=0;
end
else
begin
fcntl:=linuxerror;
linuxerror:=0;
end;
end
else
begin
linuxerror:=Sys_einval;
Fcntl:=0;
end;
end;
Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
{
Read or manipulate a file. (See also fcntl (2) )
Possible values for Cmd are :
F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
Errors are reported in Linuxerror;
If Cmd is different from the allowed values, linuxerror=Sys_eninval.
F_DupFD is not allowed, due to the structure of Files in Pascal.
}
begin
if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
begin
sys_fcntl(fd,cmd,arg);
LinuxError:=ErrNo;
end
else
linuxerror:=Sys_einval;
end;
{$endif}
Function Fcntl(var Fd:Text;Cmd:longint):longint;
begin
Fcntl := Fcntl(textrec(Fd).handle, Cmd);
end;
Procedure Fcntl(var Fd:Text;Cmd,Arg:Longint);
begin
Fcntl(textrec(Fd).handle, Cmd, Arg);
end;
Function Flock (var T : text;mode : longint) : boolean;
begin
Flock:=Flock(TextRec(T).Handle,mode);
end;
Function Flock (var F : File;mode : longint) : boolean;
begin
Flock:=Flock(FileRec(F).Handle,mode);
end;
Function FStat(Path:Pathstr;Var Info:stat):Boolean;
{
Get all information on a file, and return it in Info.
}
begin
path:=path+#0;
FStat:=(Sys_stat(@(path[1]),Info)=0);
LinuxError:=errno;
end;
Function FStat(var F:Text;Var Info:stat):Boolean;
{
Get all information on a text file, and return it in info.
}
begin
FStat:=Fstat(TextRec(F).Handle,INfo);
end;
Function FStat(var F:File;Var Info:stat):Boolean;
{
Get all information on a untyped file, and return it in info.
}
begin
FStat:=Fstat(FileRec(F).Handle,Info);
end;
Function SymLink(OldPath,newPath:pathstr):boolean;
{
Proceduces a soft link from new to old.
}
begin
oldpath:=oldpath+#0;
newpath:=newpath+#0;
Symlink:=Sys_symlink(pchar(@(oldpath[1])),pchar(@(newpath[1])))=0;
linuxerror:=errno;
end;
Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
{
Read a link (where it points to)
}
begin
Readlink:=Sys_readlink(Name,LinkName,maxlen);
linuxerror:=errno;
end;
Function ReadLink(Name:pathstr):pathstr;
{
Read a link (where it points to)
}
var
LinkName : pathstr;
i : longint;
begin
Name:=Name+#0;
i:=ReadLink(@Name[1],@LinkName[1],high(linkname));
if i>0 then
begin
linkname[0]:=chr(i);
ReadLink:=LinkName;
end
else
ReadLink:='';
end;
Function UnLink(Path:pathstr):boolean;
{
Removes the file in 'Path' (that is, it decreases the link count with one.
if the link count is zero, the file is removed from the disk.
}
begin
path:=path+#0;
Unlink:=Sys_unlink(pchar(@(path[1])))=0;
linuxerror:=errno;
end;
Function UnLink(Path:pchar):Boolean;
{
Removes the file in 'Path' (that is, it decreases the link count with one.
if the link count is zero, the file is removed from the disk.
}
begin
Unlink:=(Sys_unlink(path)=0);
linuxerror:=errno;
end;
Function FRename (OldName,NewName : Pchar) : Boolean;
begin
FRename:=Sys_rename(OldName,NewName)=0;
LinuxError:=Errno;
end;
Function FRename (OldName,NewName : String) : Boolean;
begin
OldName:=OldName+#0;
NewName:=NewName+#0;
FRename:=FRename (@OldName[1],@NewName[1]);
end;
Function Dup(var oldfile,newfile:text):Boolean;
{
Copies the filedescriptor oldfile to newfile, after flushing the buffer of
oldfile.
After which the two textfiles are, in effect, the same, except
that they don't share the same buffer, and don't share the same
close_on_exit flag.
}
begin
flush(oldfile);{ We cannot share buffers, so we flush them. }
textrec(newfile):=textrec(oldfile);
textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
Dup:=Dup(textrec(oldfile).handle,textrec(newfile).handle);
end;
Function Dup(var oldfile,newfile:file):Boolean;
{
Copies the filedescriptor oldfile to newfile
}
begin
filerec(newfile):=filerec(oldfile);
Dup:=Dup(filerec(oldfile).handle,filerec(newfile).handle);
end;
Function Dup2(var oldfile,newfile:text):Boolean;
{
Copies the filedescriptor oldfile to newfile, after flushing the buffer of
oldfile. It closes newfile if it was still open.
After which the two textfiles are, in effect, the same, except
that they don't share the same buffer, and don't share the same
close_on_exit flag.
}
var
tmphandle : word;
begin
case TextRec(oldfile).mode of
fmOutput, fmInOut, fmAppend :
flush(oldfile);{ We cannot share buffers, so we flush them. }
end;
case TextRec(newfile).mode of
fmOutput, fmInOut, fmAppend :
flush(newfile);
end;
tmphandle:=textrec(newfile).handle;
textrec(newfile):=textrec(oldfile);
textrec(newfile).handle:=tmphandle;
textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
Dup2:=Dup2(textrec(oldfile).handle,textrec(newfile).handle);
end;
Function Dup2(var oldfile,newfile:file):Boolean;
{
Copies the filedescriptor oldfile to newfile
}
begin
filerec(newfile):=filerec(oldfile);
Dup2:=Dup2(filerec(oldfile).handle,filerec(newfile).handle);
end;
Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
{
Select checks whether the file descriptor sets in readfs/writefs/exceptfs
have changed.
This function allows specification of a timeout as a longint.
}
var
p : PTimeVal;
tv : TimeVal;
begin
if TimeOut=-1 then
p:=nil
else
begin
tv.Sec:=Timeout div 1000;
tv.Usec:=(Timeout mod 1000)*1000;
p:=@tv;
end;
Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
end;
Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
Var
F:FDSet;
begin
if textrec(t).mode=fmclosed then
begin
LinuxError:=Sys_EBADF;
exit(-1);
end;
FD_Zero(f);
FD_Set(textrec(T).handle,f);
if textrec(T).mode=fminput then
SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
else
SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
end;
Function SelectText(var T:Text;TimeOut :Longint):Longint;
var
p : PTimeVal;
tv : TimeVal;
begin
if TimeOut=-1 then
p:=nil
else
begin
tv.Sec:=Timeout div 1000;
tv.Usec:=(Timeout mod 1000)*1000;
p:=@tv;
end;
SelectText:=SelectText(T,p);
end;
{******************************************************************************
Directory
******************************************************************************}
Function OpenDir(F:String):PDir;
begin
F:=F+#0;
OpenDir:=OpenDir(@F[1]);
LinuxError:=ErrNo;
end;
{$ifndef newreaddir}
procedure SeekDir(p:pdir;off:longint);
begin
if p=nil then
begin
errno:=Sys_EBADF;
exit;
end;
{$ifndef bsd}
p^.nextoff:=Sys_lseek(p^.fd,off,seek_set);
{$endif}
p^.size:=0;
p^.loc:=0;
end;
function TellDir(p:pdir):longint;
begin
if p=nil then
begin
errno:=Sys_EBADF;
telldir:=-1;
exit;
end;
telldir:=Sys_lseek(p^.fd,0,seek_cur)
{ We could try to use the nextoff field here, but on my 1.2.13
kernel, this gives nothing... This may have to do with
the readdir implementation of libc... I also didn't find any trace of
the field in the kernel code itself, So I suspect it is an artifact of libc.
Michael. }
end;
{$endif}
Function ReadDir(P:pdir):pdirent;
begin
ReadDir:=Sys_ReadDir(p);
LinuxError:=Errno;
end;
{******************************************************************************
Pipes/Fifo
******************************************************************************}
Procedure OpenPipe(var F:Text);
begin
case textrec(f).mode of
fmoutput :
if textrec(f).userdata[1]<>P_OUT then
textrec(f).mode:=fmclosed;
fminput :
if textrec(f).userdata[1]<>P_IN then
textrec(f).mode:=fmclosed;
else
textrec(f).mode:=fmclosed;
end;
end;
Procedure IOPipe(var F:text);
begin
case textrec(f).mode of
fmoutput :
begin
{ first check if we need something to write, else we may
get a SigPipe when Close() is called (PFV) }
if textrec(f).bufpos>0 then
Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
end;
fminput :
textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
end;
textrec(f).bufpos:=0;
end;
Procedure FlushPipe(var F:Text);
begin
if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
IOPipe(f);
textrec(f).bufpos:=0;
end;
Procedure ClosePipe(var F:text);
begin
textrec(f).mode:=fmclosed;
Sys_close(textrec(f).handle);
end;
Function AssignPipe(var pipe_in,pipe_out:text):boolean;
{
Sets up a pair of file variables, which act as a pipe. The first one can
be read from, the second one can be written to.
If the operation was unsuccesful, linuxerror is set.
}
var
f_in,f_out : longint;
begin
if not AssignPipe(f_in,f_out) then
begin
AssignPipe:=false;
exit;
end;
{ Set up input }
Assign(Pipe_in,'');
Textrec(Pipe_in).Handle:=f_in;
Textrec(Pipe_in).Mode:=fmInput;
Textrec(Pipe_in).userdata[1]:=P_IN;
TextRec(Pipe_in).OpenFunc:=@OpenPipe;
TextRec(Pipe_in).InOutFunc:=@IOPipe;
TextRec(Pipe_in).FlushFunc:=@FlushPipe;
TextRec(Pipe_in).CloseFunc:=@ClosePipe;
{ Set up output }
Assign(Pipe_out,'');
Textrec(Pipe_out).Handle:=f_out;
Textrec(Pipe_out).Mode:=fmOutput;
Textrec(Pipe_out).userdata[1]:=P_OUT;
TextRec(Pipe_out).OpenFunc:=@OpenPipe;
TextRec(Pipe_out).InOutFunc:=@IOPipe;
TextRec(Pipe_out).FlushFunc:=@FlushPipe;
TextRec(Pipe_out).CloseFunc:=@ClosePipe;
AssignPipe:=true;
end;
Function AssignPipe(var pipe_in,pipe_out:file):boolean;
{
Sets up a pair of file variables, which act as a pipe. The first one can
be read from, the second one can be written to.
If the operation was unsuccesful, linuxerror is set.
}
var
f_in,f_out : longint;
begin
if not AssignPipe(f_in,f_out) then
begin
AssignPipe:=false;
exit;
end;
{ Set up input }
Assign(Pipe_in,'');
Filerec(Pipe_in).Handle:=f_in;
Filerec(Pipe_in).Mode:=fmInput;
Filerec(Pipe_in).recsize:=1;
Filerec(Pipe_in).userdata[1]:=P_IN;
{ Set up output }
Assign(Pipe_out,'');
Filerec(Pipe_out).Handle:=f_out;
Filerec(Pipe_out).Mode:=fmoutput;
Filerec(Pipe_out).recsize:=1;
Filerec(Pipe_out).userdata[1]:=P_OUT;
AssignPipe:=true;
end;
Procedure PCloseText(Var F:text);
{
May not use @PClose due overloading
}
begin
PClose(f);
end;
Procedure POpen(var F:text;const Prog:String;rw:char);
{
Starts the program in 'Prog' and makes it's input or out put the
other end of a pipe. If rw is 'w' or 'W', then whatever is written to
F, will be read from stdin by the program in 'Prog'. The inverse is true
for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
read from 'f'.
}
var
pipi,
pipo : text;
pid : longint;
pl : ^longint;
pp : ppchar;
begin
LinuxError:=0;
rw:=upcase(rw);
if not (rw in ['R','W']) then
begin
LinuxError:=Sys_enoent;
exit;
end;
AssignPipe(pipi,pipo);
if Linuxerror<>0 then
exit;
pid:=fork;
if linuxerror<>0 then
begin
close(pipi);
close(pipo);
exit;
end;
if pid=0 then
begin
{$ifdef BSD} // FreeBSD checked only
{ We're in the child }
close(pipi);
if textrec(pipo).handle<>textrec(output).handle Then
begin
dup2(textrec(pipo).handle,textrec(output).handle);
if rw='W' Then
dup2(textrec(output).handle,textrec(input).handle);
end
else
if (rw='W') and (textrec(pipi).handle<>textrec(input).handle) then
dup2(textrec(output).handle,textrec(input).handle);
close(pipo);
if linuxerror<>0 then
halt(127);
pp:=createshellargv(prog);
Execve(pp^,pp,envp);
halt(127);
end
{$else}
{ We're in the child }
if rw='W' then
begin
close(pipo);
dup2(pipi,input);
close(pipi);
if linuxerror<>0 then
halt(127);
end
else
begin
close(pipi);
dup2(pipo,output);
close(pipo);
if linuxerror<>0 then
halt(127);
end;
pp:=createshellargv(prog);
Execve(pp^,pp,envp);
halt(127);
end
{$endif}
else
begin
{ We're in the parent }
if rw='W' then
begin
close(pipi);
f:=pipo;
textrec(f).bufptr:=@textrec(f).buffer;
end
else
begin
close(pipo);
f:=pipi;
textrec(f).bufptr:=@textrec(f).buffer;
end;
{Save the process ID - needed when closing }
pl:=plongint(@(textrec(f).userdata[2]));
pl^:=pid;
textrec(f).closefunc:=@PCloseText;
end;
end;
Procedure POpen(var F:file;const Prog:String;rw:char);
{
Starts the program in 'Prog' and makes it's input or out put the
other end of a pipe. If rw is 'w' or 'W', then whatever is written to
F, will be read from stdin by the program in 'Prog'. The inverse is true
for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
read from 'f'.
}
var
pipi,
pipo : file;
pid : longint;
pl : ^longint;
p,pp : ppchar;
temp : string[255];
begin
LinuxError:=0;
rw:=upcase(rw);
if not (rw in ['R','W']) then
begin
LinuxError:=Sys_enoent;
exit;
end;
AssignPipe(pipi,pipo);
if Linuxerror<>0 then
exit;
pid:=fork;
if linuxerror<>0 then
begin
close(pipi);
close(pipo);
exit;
end;
if pid=0 then
begin
{ We're in the child }
if rw='W' then
begin
close(pipo);
dup2(filerec(pipi).handle,stdinputhandle);
close(pipi);
if linuxerror<>0 then
halt(127);
end
else
begin
close(pipi);
dup2(filerec(pipo).handle,stdoutputhandle);
close(pipo);
if linuxerror<>0 then
halt(127);
end;
getmem(pp,sizeof(pchar)*4);
temp:='/bin/sh'#0'-c'#0+prog+#0;
p:=pp;
p^:=@temp[1];
inc(p);
p^:=@temp[9];
inc(p);
p^:=@temp[12];
inc(p);
p^:=Nil;
Execve('/bin/sh',pp,envp);
halt(127);
end
else
begin
{ We're in the parent }
if rw='W' then
begin
close(pipi);
f:=pipo;
end
else
begin
close(pipo);
f:=pipi;
end;
{Save the process ID - needed when closing }
pl:=plongint(@(filerec(f).userdata[2]));
pl^:=pid;
end;
end;
Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
{
Starts the program in 'Prog' and makes its input and output the
other end of two pipes, which are the stdin and stdout of a program
specified in 'Prog'.
streamout can be used to write to the program, streamin can be used to read
the output of the program. See the following diagram :
Parent Child
STreamout --> Input
Streamin <-- Output
Return value is the process ID of the process being spawned, or -1 in case of failure.
}
var
pipi,
pipo : text;
pid : longint;
pl : ^Longint;
begin
LinuxError:=0;
AssignStream:=-1;
AssignPipe(streamin,pipo);
if Linuxerror<>0 then
exit;
AssignPipe(pipi,streamout);
if Linuxerror<>0 then
exit;
pid:=fork;
if linuxerror<>0 then
begin
close(pipi);
close(pipo);
close (streamin);
close (streamout);
exit;
end;
if pid=0 then
begin
{ We're in the child }
{ Close what we don't need }
close(streamout);
close(streamin);
dup2(pipi,input);
if linuxerror<>0 then
halt(127);
close(pipi);
dup2(pipo,output);
if linuxerror<>0 then
halt (127);
close(pipo);
Execl(Prog);
halt(127);
end
else
begin
{ we're in the parent}
close(pipo);
close(pipi);
{Save the process ID - needed when closing }
pl:=plongint(@(textrec(StreamIn).userdata[2]));
pl^:=pid;
textrec(StreamIn).closefunc:=@PCloseText;
{Save the process ID - needed when closing }
pl:=plongint(@(textrec(StreamOut).userdata[2]));
pl^:=pid;
textrec(StreamOut).closefunc:=@PCloseText;
AssignStream:=Pid;
end;
end;
function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
{
Starts the program in 'prog' and makes its input, output and error output the
other end of three pipes, which are the stdin, stdout and stderr of a program
specified in 'prog'.
StreamOut can be used to write to the program, StreamIn can be used to read
the output of the program, StreamErr reads the error output of the program.
See the following diagram :
Parent Child
StreamOut --> StdIn (input)
StreamIn <-- StdOut (output)
StreamErr <-- StdErr (error output)
}
var
PipeIn, PipeOut, PipeErr: text;
pid: LongInt;
pl: ^LongInt;
begin
LinuxError := 0;
AssignStream := -1;
// Assign pipes
AssignPipe(StreamIn, PipeOut);
if LinuxError <> 0 then exit;
AssignPipe(StreamErr, PipeErr);
if LinuxError <> 0 then begin
Close(StreamIn);
Close(PipeOut);
exit;
end;
AssignPipe(PipeIn, StreamOut);
if LinuxError <> 0 then begin
Close(StreamIn);
Close(PipeOut);
Close(StreamErr);
Close(PipeErr);
exit;
end;
// Fork
pid := Fork;
if LinuxError <> 0 then begin
Close(StreamIn);
Close(PipeOut);
Close(StreamErr);
Close(PipeErr);
Close(PipeIn);
Close(StreamOut);
exit;
end;
if pid = 0 then begin
// *** We are in the child ***
// Close what we don not need
Close(StreamOut);
Close(StreamIn);
Close(StreamErr);
// Connect pipes
dup2(PipeIn, Input);
if LinuxError <> 0 then Halt(127);
Close(PipeIn);
dup2(PipeOut, Output);
if LinuxError <> 0 then Halt(127);
Close(PipeOut);
dup2(PipeErr, StdErr);
if LinuxError <> 0 then Halt(127);
Close(PipeErr);
// Execute program
Execl(Prog);
Halt(127);
end else begin
// *** We are in the parent ***
Close(PipeErr);
Close(PipeOut);
Close(PipeIn);
// Save the process ID - needed when closing
pl := plongint(@(TextRec(StreamIn).userdata[2]));
pl^ := pid;
TextRec(StreamIn).closefunc := @PCloseText;
// Save the process ID - needed when closing
pl := plongint(@(TextRec(StreamOut).userdata[2]));
pl^ := pid;
TextRec(StreamOut).closefunc := @PCloseText;
// Save the process ID - needed when closing
pl := plongint(@(TextRec(StreamErr).userdata[2]));
pl^ := pid;
TextRec(StreamErr).closefunc := @PCloseText;
AssignStream := pid;
end;
end;
{******************************************************************************
General information calls
******************************************************************************}
Function GetEnv(P:string):Pchar;
{
Searches the environment for a string with name p and
returns a pchar to it's value.
A pchar is used to accomodate for strings of length > 255
}
var
ep : ppchar;
found : boolean;
Begin
p:=p+'='; {Else HOST will also find HOSTNAME, etc}
ep:=envp;
found:=false;
if ep<>nil then
begin
while (not found) and (ep^<>nil) do
begin
if strlcomp(@p[1],(ep^),length(p))=0 then
found:=true
else
inc(ep);
end;
end;
if found then
getenv:=ep^+length(p)
else
getenv:=nil;
end;
{$ifndef bsd}
Function GetDomainName:String;
{
Get machines domain name. Returns empty string if not set.
}
Var
Sysn : utsname;
begin
Uname(Sysn);
linuxerror:=errno;
If linuxerror<>0 then
getdomainname:=''
else
getdomainname:=strpas(@Sysn.domainname[0]);
end;
Function GetHostName:String;
{
Get machines name. Returns empty string if not set.
}
Var
Sysn : utsname;
begin
uname(Sysn);
linuxerror:=errno;
If linuxerror<>0 then
gethostname:=''
else
gethostname:=strpas(@Sysn.nodename[0]);
end;
{$endif}
{******************************************************************************
Signal handling calls
******************************************************************************}
procedure SigRaise(sig:integer);
begin
Kill(GetPid,Sig);
end;
{******************************************************************************
IOCtl and Termios calls
******************************************************************************}
Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
begin
{$ifndef BSD}
TCGetAttr:=IOCtl(fd,TCGETS,@tios);
{$else}
TCGETAttr:=IoCtl(Fd,TIOCGETA,@tios);
{$endif}
end;
Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
var
nr:longint;
begin
{$ifndef BSD}
case OptAct of
TCSANOW : nr:=TCSETS;
TCSADRAIN : nr:=TCSETSW;
TCSAFLUSH : nr:=TCSETSF;
{$else}
case OptAct of
TCSANOW : nr:=TIOCSETA;
TCSADRAIN : nr:=TIOCSETAW;
TCSAFLUSH : nr:=TIOCSETAF;
{$endif}
else
begin
ErrNo:=Sys_EINVAL;
TCSetAttr:=false;
exit;
end;
end;
TCSetAttr:=IOCtl(fd,nr,@Tios);
end;
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
begin
{$ifndef BSD}
tios.c_cflag:=Cardinal(tios.c_cflag and cardinal(not CBAUD)) or speed;
{$else}
tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
{$endif}
end;
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
begin
{$ifndef BSD}
CFSetISpeed(tios,speed);
{$else}
tios.c_ospeed:=speed;
{$endif}
end;
Procedure CFMakeRaw(var tios:TermIOS);
begin
{$ifndef BSD}
with tios do
begin
c_iflag:=c_iflag and cardinal(not (IGNBRK or BRKINT or PARMRK or ISTRIP or
INLCR or IGNCR or ICRNL or IXON));
c_oflag:=c_oflag and cardinal(not OPOST);
c_lflag:=c_lflag and cardinal(not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
c_cflag:=(c_cflag and cardinal(not (CSIZE or PARENB))) or CS8;
end;
{$else}
with tios do
begin
c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
IGNPAR));
c_iflag:=c_iflag OR IGNBRK;
c_oflag:=c_oflag and (not OPOST);
c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
c_cc[VMIN]:=1;
c_cc[VTIME]:=0;
end;
{$endif}
end;
Function TCSendBreak(fd,duration:longint):boolean;
begin
{$ifndef BSD}
TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
{$else}
TCSendBreak:=IOCtl(fd,TIOCSBRK,0);
{$endif}
end;
Function TCSetPGrp(fd,id:longint):boolean;
begin
TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
end;
Function TCGetPGrp(fd:longint;var id:longint):boolean;
begin
TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
end;
Function TCDrain(fd:longint):boolean;
begin
{$ifndef BSD}
TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
{$else}
TCDrain:=IOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
{$endif}
end;
Function TCFlow(fd,act:longint):boolean;
begin
{$ifndef BSD}
TCFlow:=IOCtl(fd,TCXONC,pointer(act));
{$else}
case act OF
TCOOFF : TCFlow:=Ioctl(fd,TIOCSTOP,0);
TCOOn : TCFlow:=IOctl(Fd,TIOCStart,0);
TCIOFF : {N/I}
end;
{$endif}
end;
Function TCFlush(fd,qsel:longint):boolean;
begin
{$ifndef BSD}
TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
{$else}
TCFlush:=IOCtl(fd,TIOCFLUSH,pointer(qsel));
{$endif}
end;
Function IsATTY(Handle:Longint):Boolean;
{
Check if the filehandle described by 'handle' is a TTY (Terminal)
}
var
t : Termios;
begin
IsAtty:=TCGetAttr(Handle,t);
end;
Function IsATTY(var f: text):Boolean;
{
Idem as previous, only now for text variables.
}
begin
IsATTY:=IsaTTY(textrec(f).handle);
end;
function TTYName(Handle:Longint):string;
{
Return the name of the current tty described by handle f.
returns empty string in case of an error.
}
{$ifdef BSD}
var
mydev,
myino : cardinal;
{$else not BSD}
var
mydev,
myino : longint;
{$endif not BSD}
st : stat;
function mysearch(n:string): boolean;
{searches recursively for the device in the directory given by n,
returns true if found and sets the name of the device in ttyname}
var dirstream : pdir;
d : pdirent;
name : string;
st : stat;
begin
dirstream:=opendir(n);
if (linuxerror<>0) then
exit;
d:=Readdir(dirstream);
while (d<>nil) do
begin
name:=n+'/'+strpas(@(d^.name[0]));
fstat(name,st);
if linuxerror=0 then
begin
if ((st.mode and $E000)=$4000) and { if it is a directory }
(strpas(@(d^.name[0]))<>'.') and { but not ., .. and fd subdirs }
(strpas(@(d^.name[0]))<>'..') and
(strpas(@(d^.name[0]))<>'') and
(strpas(@(d^.name[0]))<>'fd') then
begin {we found a directory, search inside it}
if mysearch(name) then
begin {the device is here}
closedir(dirstream); {then don't continue searching}
mysearch:=true;
exit;
end;
end
else if (d^.ino=myino) and (st.dev=mydev) then
begin
closedir(dirstream);
ttyname:=name;
mysearch:=true;
exit;
end;
end;
d:=Readdir(dirstream);
end;
closedir(dirstream);
mysearch:=false;
end;
begin
TTYName:='';
fstat(handle,st);
if (errno<>0) and isatty (handle) then
exit;
mydev:=st.dev;
myino:=st.ino;
mysearch('/dev');
end;
function TTYName(var F:Text):string;
{
Idem as previous, only now for text variables;
}
begin
TTYName:=TTYName(textrec(f).handle);
end;
{******************************************************************************
Utility calls
******************************************************************************}
Function Octal(l:longint):longint;
{
Convert an octal specified number to decimal;
}
var
octnr,
oct : longint;
begin
octnr:=0;
oct:=0;
while (l>0) do
begin
oct:=oct or ((l mod 10) shl octnr);
l:=l div 10;
inc(octnr,3);
end;
Octal:=oct;
end;
Function StringToPPChar(S: PChar):ppchar;
var
nr : longint;
Buf : ^char;
p : ppchar;
begin
buf:=s;
nr:=0;
while(buf^<>#0) do
begin
while (buf^ in [' ',#9,#10]) do
inc(buf);
inc(nr);
while not (buf^ in [' ',#0,#9,#10]) do
inc(buf);
end;
getmem(p,(nr+1)*4);
StringToPPChar:=p;
if p=nil then
begin
LinuxError:=sys_enomem;
exit;
end;
buf:=s;
while (buf^<>#0) do
begin
while (buf^ in [' ',#9,#10]) do
begin
buf^:=#0;
inc(buf);
end;
p^:=buf;
inc(p);
p^:=nil;
while not (buf^ in [' ',#0,#9,#10]) do
inc(buf);
end;
end;
Function StringToPPChar(Var S:String):ppchar;
{
Create a PPChar to structure of pchars which are the arguments specified
in the string S. Especially useful for creating an ArgV for Exec-calls
Note that the string S is destroyed by this call.
}
begin
S:=S+#0;
StringToPPChar:=StringToPPChar(@S[1]);
end;
Function StringToPPChar(Var S:AnsiString):ppchar;
{
Create a PPChar to structure of pchars which are the arguments specified
in the string S. Especially useful for creating an ArgV for Exec-calls
}
begin
StringToPPChar:=StringToPPChar(PChar(S));
end;
{
function FExpand (const Path: PathStr): PathStr;
- declared in fexpand.inc
}
{$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
{$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
const
LFNSupport = true;
FileNameCaseSensitive = true;
FileNameCasePreserving = true;
{$I fexpand.inc}
{$UNDEF FPC_FEXPAND_GETENVPCHAR}
{$UNDEF FPC_FEXPAND_TILDE}
Function FSearch(const path:pathstr;dirlist:string):pathstr;
{
Searches for a file 'path' in the list of direcories in 'dirlist'.
returns an empty string if not found. Wildcards are NOT allowed.
If dirlist is empty, it is set to '.'
}
Var
NewDir : PathStr;
p1 : Longint;
Info : Stat;
Begin
{Replace ':' with ';'}
for p1:=1to length(dirlist) do
if dirlist[p1]=':' then
dirlist[p1]:=';';
{Check for WildCards}
If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
FSearch:='' {No wildcards allowed in these things.}
Else
Begin
Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
Repeat
p1:=Pos(';',DirList);
If p1=0 Then
p1:=255;
NewDir:=Copy(DirList,1,P1 - 1);
if NewDir[Length(NewDir)]<>'/' then
NewDir:=NewDir+'/';
NewDir:=NewDir+Path;
Delete(DirList,1,p1);
if FStat(NewDir,Info) then
Begin
If Pos('./',NewDir)=1 Then
Delete(NewDir,1,2);
{DOS strips off an initial .\}
End
Else
NewDir:='';
Until (DirList='') or (Length(NewDir) > 0);
FSearch:=NewDir;
End;
End;
Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
Var
DotPos,SlashPos,i : longint;
Begin
SlashPos:=0;
DotPos:=256;
i:=Length(Path);
While (i>0) and (SlashPos=0) Do
Begin
If (DotPos=256) and (Path[i]='.') Then
begin
DotPos:=i;
end;
If (Path[i]='/') Then
SlashPos:=i;
Dec(i);
End;
Ext:=Copy(Path,DotPos,255);
Dir:=Copy(Path,1,SlashPos);
Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
End;
Function Dirname(Const path:pathstr):pathstr;
{
This function returns the directory part of a complete path.
Unless the directory is root '/', The last character is not
a slash.
}
var
Dir : PathStr;
Name : NameStr;
Ext : ExtStr;
begin
FSplit(Path,Dir,Name,Ext);
if length(Dir)>1 then
Delete(Dir,length(Dir),1);
DirName:=Dir;
end;
Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
{
This function returns the filename part of a complete path. If suf is
supplied, it is cut off the filename.
}
var
Dir : PathStr;
Name : NameStr;
Ext : ExtStr;
begin
FSplit(Path,Dir,Name,Ext);
if Suf<>Ext then
Name:=Name+Ext;
BaseName:=Name;
end;
Function FNMatch(const Pattern,Name:string):Boolean;
Var
LenPat,LenName : longint;
Function DoFNMatch(i,j:longint):Boolean;
Var
Found : boolean;
Begin
Found:=true;
While Found and (i<=LenPat) Do
Begin
Case Pattern[i] of
'?' : Found:=(j<=LenName);
'*' : Begin
{find the next character in pattern, different of ? and *}
while Found and (i<LenPat) do
begin
inc(i);
case Pattern[i] of
'*' : ;
'?' : begin
inc(j);
Found:=(j<=LenName);
end;
else
Found:=false;
end;
end;
{Now, find in name the character which i points to, if the * or ?
wasn't the last character in the pattern, else, use up all the
chars in name}
Found:=true;
if (i<=LenPat) then
begin
repeat
{find a letter (not only first !) which maches pattern[i]}
while (j<=LenName) and (name[j]<>pattern[i]) do
inc (j);
if (j<LenName) then
begin
if DoFnMatch(i+1,j+1) then
begin
i:=LenPat;
j:=LenName;{we can stop}
Found:=true;
end
else
inc(j);{We didn't find one, need to look further}
end;
until (j>=LenName);
end
else
j:=LenName;{we can stop}
end;
else {not a wildcard character in pattern}
Found:=(j<=LenName) and (pattern[i]=name[j]);
end;
inc(i);
inc(j);
end;
DoFnMatch:=Found and (j>LenName);
end;
Begin {start FNMatch}
LenPat:=Length(Pattern);
LenName:=Length(Name);
FNMatch:=DoFNMatch(1,1);
End;
Procedure Globfree(var p : pglob);
{
Release memory occupied by pglob structure, and names in it.
sets p to nil.
}
var
temp : pglob;
begin
while assigned(p) do
begin
temp:=p^.next;
if assigned(p^.name) then
freemem(p^.name);
dispose(p);
p:=temp;
end;
end;
Function Glob(Const path:pathstr):pglob;
{
Fills a tglob structure with entries matching path,
and returns a pointer to it. Returns nil on error,
linuxerror is set accordingly.
}
var
temp,
temp2 : string[255];
thedir : pdir;
buffer : pdirent;
root,
current : pglob;
begin
{ Get directory }
temp:=dirname(path);
if temp='' then
temp:='.';
temp:=temp+#0;
thedir:=opendir(@temp[1]);
if thedir=nil then
begin
glob:=nil;
linuxerror:=errno;
exit;
end;
temp:=basename(path,''); { get the pattern }
if thedir^.fd<0 then
begin
linuxerror:=errno;
glob:=nil;
exit;
end;
{get the entries}
root:=nil;
current:=nil;
repeat
buffer:=Sys_readdir(thedir);
if buffer=nil then
break;
temp2:=strpas(@(buffer^.name[0]));
if fnmatch(temp,temp2) then
begin
if root=nil then
begin
new(root);
current:=root;
end
else
begin
new(current^.next);
current:=current^.next;
end;
if current=nil then
begin
linuxerror:=Sys_ENOMEM;
globfree(root);
break;
end;
current^.next:=nil;
getmem(current^.name,length(temp2)+1);
if current^.name=nil then
begin
linuxerror:=Sys_ENOMEM;
globfree(root);
break;
end;
move(buffer^.name[0],current^.name^,length(temp2)+1);
end;
until false;
closedir(thedir);
glob:=root;
end;
{--------------------------------
FiledescriptorSets
--------------------------------}
Procedure FD_Zero(var fds:fdSet);
{
Clear the set of filedescriptors
}
begin
FillChar(fds,sizeof(fdSet),0);
end;
Procedure FD_Clr(fd:longint;var fds:fdSet);
{
Remove fd from the set of filedescriptors
}
begin
fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
end;
Procedure FD_Set(fd:longint;var fds:fdSet);
{
Add fd to the set of filedescriptors
}
begin
fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
end;
Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
{
Test if fd is part of the set of filedescriptors
}
begin
FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
end;
Function GetFS (var T:Text):longint;
{
Get File Descriptor of a text file.
}
begin
if textrec(t).mode=fmclosed then
exit(-1)
else
GETFS:=textrec(t).Handle
end;
Function GetFS(Var F:File):longint;
{
Get File Descriptor of an unTyped file.
}
begin
{ Handle and mode are on the same place in textrec and filerec. }
if filerec(f).mode=fmclosed then
exit(-1)
else
GETFS:=filerec(f).Handle
end;
{--------------------------------
Stat.Mode Macro's
--------------------------------}
Function S_ISLNK(m:word):boolean;
{
Check mode field of inode for link.
}
begin
S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
end;
Function S_ISREG(m:word):boolean;
{
Check mode field of inode for regular file.
}
begin
S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
end;
Function S_ISDIR(m:word):boolean;
{
Check mode field of inode for directory.
}
begin
S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
end;
Function S_ISCHR(m:word):boolean;
{
Check mode field of inode for character device.
}
begin
S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
end;
Function S_ISBLK(m:word):boolean;
{
Check mode field of inode for block device.
}
begin
S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
end;
Function S_ISFIFO(m:word):boolean;
{
Check mode field of inode for named pipe (FIFO).
}
begin
S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
end;
Function S_ISSOCK(m:word):boolean;
{
Check mode field of inode for socket.
}
begin
S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
end;
Procedure WritePort (Port : Longint; Value : Byte);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movb value,%al
outb %al,%dx
end ['EAX','EDX'];
end;
Procedure WritePort (Port : Longint; Value : Word);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movw value,%ax
outw %ax,%dx
end ['EAX','EDX'];
end;
Procedure WritePort (Port : Longint; Value : Longint);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movl value,%eax
outl %eax,%dx
end ['EAX','EDX'];
end;
Procedure WritePortB (Port : Longint; Value : Byte);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movb value,%al
outb %al,%dx
end ['EAX','EDX'];
end;
Procedure WritePortW (Port : Longint; Value : Word);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movw value,%ax
outw %ax,%dx
end ['EAX','EDX'];
end;
Procedure WritePortL (Port : Longint; Value : Longint);oldfpccall;
{
Writes 'Value' to port 'Port'
}
begin
asm
movl port,%edx
movl value,%eax
outl %eax,%dx
end ['EAX','EDX'];
end;
Procedure WritePortl (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Writes 'Count' longints from 'Buf' to Port
}
begin
asm
movl count,%ecx
movl buf,%esi
movl port,%edx
cld
rep
outsl
end ['ECX','ESI','EDX'];
end;
Procedure WritePortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Writes 'Count' words from 'Buf' to Port
}
begin
asm
movl count,%ecx
movl buf,%esi
movl port,%edx
cld
rep
outsw
end ['ECX','ESI','EDX'];
end;
Procedure WritePortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Writes 'Count' bytes from 'Buf' to Port
}
begin
asm
movl count,%ecx
movl buf,%esi
movl port,%edx
cld
rep
outsb
end ['ECX','ESI','EDX'];
end;
Procedure ReadPort (Port : Longint; Var Value : Byte);oldfpccall;
{
Reads 'Value' from port 'Port'
}
begin
asm
movl port,%edx
inb %dx,%al
movl value,%edx
movb %al,(%edx)
end ['EAX','EDX'];
end;
Procedure ReadPort (Port : Longint; Var Value : Word);oldfpccall;
{
Reads 'Value' from port 'Port'
}
begin
asm
movl port,%edx
inw %dx,%ax
movl value,%edx
movw %ax,(%edx)
end ['EAX','EDX'];
end;
Procedure ReadPort (Port : Longint; Var Value : Longint);oldfpccall;
{
Reads 'Value' from port 'Port'
}
begin
asm
movl port,%edx
inl %dx,%eax
movl value,%edx
movl %eax,(%edx)
end ['EAX','EDX'];
end;
function ReadPortB (Port : Longint): Byte;oldfpccall; assembler;
{
Reads a byte from port 'Port'
}
asm
xorl %eax,%eax
movl port,%edx
inb %dx,%al
end ['EAX','EDX'];
function ReadPortW (Port : Longint): Word;oldfpccall; assembler;
{
Reads a word from port 'Port'
}
asm
xorl %eax,%eax
movl port,%edx
inw %dx,%ax
end ['EAX','EDX'];
function ReadPortL (Port : Longint): LongInt;oldfpccall; assembler;
{
Reads a LongInt from port 'Port'
}
asm
movl port,%edx
inl %dx,%eax
end ['EAX','EDX'];
Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Reads 'Count' longints from port 'Port' to 'Buf'.
}
begin
asm
movl count,%ecx
movl buf,%edi
movl port,%edx
cld
rep
insl
end ['ECX','EDI','EDX'];
end;
Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Reads 'Count' words from port 'Port' to 'Buf'.
}
begin
asm
movl count,%ecx
movl buf,%edi
movl port,%edx
cld
rep
insw
end ['ECX','EDI','EDX'];
end;
Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
{
Reads 'Count' bytes from port 'Port' to 'Buf'.
}
begin
asm
movl count,%ecx
movl buf,%edi
movl port,%edx
cld
rep
insb
end ['ECX','EDI','EDX'];
end;
{--------------------------------
Memory functions
--------------------------------}
Initialization
InitLocalTime;
finalization
DoneLocalTime;
End.
|