fileops: Cleanup Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
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
diff --git a/src/blob.c b/src/blob.c
index 2e3c7b3..b8282e5 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -91,9 +91,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
if (repo->path_workdir == NULL)
return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)");
- git__joinpath(full_path, repo->path_workdir, path);
+ git_path_join(full_path, repo->path_workdir, path);
- error = gitfo_lstat(full_path, &st);
+ error = p_lstat(full_path, &st);
if (error < 0) {
return git__throw(GIT_EOSERR, "Failed to stat blob. %s", strerror(errno));
}
@@ -102,12 +102,12 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
size = st.st_size;
if (!islnk)
- if ((fd = gitfo_open(full_path, O_RDONLY)) < 0)
+ if ((fd = p_open(full_path, O_RDONLY)) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path);
if ((error = git_odb_open_wstream(&stream, repo->db, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) {
if (!islnk)
- gitfo_close(fd);
+ p_close(fd);
return git__rethrow(error, "Failed to create blob");
}
@@ -115,13 +115,13 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
ssize_t read_len;
if (!islnk)
- read_len = gitfo_read(fd, buffer, sizeof(buffer));
+ read_len = p_read(fd, buffer, sizeof(buffer));
else
- read_len = gitfo_readlink(full_path, buffer, sizeof(buffer));
+ read_len = p_readlink(full_path, buffer, sizeof(buffer));
if (read_len < 0) {
if (!islnk)
- gitfo_close(fd);
+ p_close(fd);
stream->free(stream);
return git__throw(GIT_EOSERR, "Failed to create blob. Can't read full file");
}
@@ -133,7 +133,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
error = stream->finalize_write(oid, stream);
stream->free(stream);
if (!islnk)
- gitfo_close(fd);
+ p_close(fd);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create blob");
}
diff --git a/src/config.c b/src/config.c
index a2202d7..12fa8f2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -333,9 +333,9 @@ int git_config_find_global(char *global_config_path)
if (home == NULL)
return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");
- git__joinpath(global_config_path, home, GIT_CONFIG_FILENAME);
+ git_path_join(global_config_path, home, GIT_CONFIG_FILENAME);
- if (gitfo_exists(global_config_path) < GIT_SUCCESS)
+ if (git_futils_exists(global_config_path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");
return GIT_SUCCESS;
diff --git a/src/config_file.c b/src/config_file.c
index b017787..5f8cffa 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -89,7 +89,7 @@ typedef struct {
cvar_t_list var_list;
struct {
- gitfo_buf buffer;
+ git_fbuffer buffer;
char *read_ptr;
int line_number;
int eof;
@@ -278,7 +278,7 @@ static int config_open(git_config_file *cfg)
int error;
diskfile_backend *b = (diskfile_backend *)cfg;
- error = gitfo_read_file(&b->reader.buffer, b->file_path);
+ error = git_futils_readbuffer(&b->reader.buffer, b->file_path);
if(error < GIT_SUCCESS)
goto cleanup;
@@ -286,13 +286,13 @@ static int config_open(git_config_file *cfg)
if (error < GIT_SUCCESS)
goto cleanup;
- gitfo_free_buf(&b->reader.buffer);
+ git_futils_freebuffer(&b->reader.buffer);
return error;
cleanup:
cvar_list_free(&b->var_list);
- gitfo_free_buf(&b->reader.buffer);
+ git_futils_freebuffer(&b->reader.buffer);
return git__rethrow(error, "Failed to open config");
}
@@ -921,7 +921,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
const char *pre_end = NULL, *post_start = NULL;
/* We need to read in our own config file */
- error = gitfo_read_file(&cfg->reader.buffer, cfg->file_path);
+ error = git_futils_readbuffer(&cfg->reader.buffer, cfg->file_path);
if (error < GIT_SUCCESS) {
return git__rethrow(error, "Failed to read existing config file %s", cfg->file_path);
}
@@ -1068,7 +1068,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
else
error = git_filebuf_commit(&file);
- gitfo_free_buf(&cfg->reader.buffer);
+ git_futils_freebuffer(&cfg->reader.buffer);
return error;
}
diff --git a/src/filebuf.c b/src/filebuf.c
index ea5599b..acfdcd1 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -32,39 +32,39 @@ static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
static int lock_file(git_filebuf *file, int flags)
{
- if (gitfo_exists(file->path_lock) == 0) {
+ if (git_futils_exists(file->path_lock) == 0) {
if (flags & GIT_FILEBUF_FORCE)
- gitfo_unlink(file->path_lock);
+ p_unlink(file->path_lock);
else
return git__throw(GIT_EOSERR, "Failed to lock file");
}
/* create path to the file buffer is required */
if (flags & GIT_FILEBUF_FORCE) {
- file->fd = gitfo_creat_locked_force(file->path_lock, 0644);
+ file->fd = git_futils_creat_locked_withpath(file->path_lock, 0644);
} else {
- file->fd = gitfo_creat_locked(file->path_lock, 0644);
+ file->fd = git_futils_creat_locked(file->path_lock, 0644);
}
if (file->fd < 0)
return git__throw(GIT_EOSERR, "Failed to create lock");
- if ((flags & GIT_FILEBUF_APPEND) && gitfo_exists(file->path_original) == 0) {
+ if ((flags & GIT_FILEBUF_APPEND) && git_futils_exists(file->path_original) == 0) {
git_file source;
char buffer[2048];
size_t read_bytes;
- source = gitfo_open(file->path_original, O_RDONLY);
+ source = p_open(file->path_original, O_RDONLY);
if (source < 0)
return git__throw(GIT_EOSERR, "Failed to lock file. Could not open %s", file->path_original);
- while ((read_bytes = gitfo_read(source, buffer, 2048)) > 0) {
- gitfo_write(file->fd, buffer, read_bytes);
+ while ((read_bytes = p_read(source, buffer, 2048)) > 0) {
+ p_write(file->fd, buffer, read_bytes);
if (file->digest)
git_hash_update(file->digest, buffer, read_bytes);
}
- gitfo_close(source);
+ p_close(source);
}
return GIT_SUCCESS;
@@ -73,10 +73,10 @@ static int lock_file(git_filebuf *file, int flags)
void git_filebuf_cleanup(git_filebuf *file)
{
if (file->fd >= 0)
- gitfo_close(file->fd);
+ p_close(file->fd);
- if (file->fd >= 0 && file->path_lock && gitfo_exists(file->path_lock) == GIT_SUCCESS)
- gitfo_unlink(file->path_lock);
+ if (file->fd >= 0 && file->path_lock && git_futils_exists(file->path_lock) == GIT_SUCCESS)
+ p_unlink(file->path_lock);
if (file->digest)
git_hash_free_ctx(file->digest);
@@ -102,7 +102,7 @@ static int write_normal(git_filebuf *file, const void *source, size_t len)
int result = 0;
if (len > 0) {
- result = gitfo_write(file->fd, (void *)source, len);
+ result = p_write(file->fd, (void *)source, len);
if (file->digest)
git_hash_update(file->digest, source, len);
}
@@ -130,7 +130,7 @@ static int write_deflate(git_filebuf *file, const void *source, size_t len)
have = file->buf_size - zs->avail_out;
- if (gitfo_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
+ if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to write to file");
} while (zs->avail_out == 0);
@@ -200,7 +200,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
char tmp_path[GIT_PATH_MAX];
/* Open the file as temporary for locking */
- file->fd = gitfo_mktemp(tmp_path, path);
+ file->fd = git_futils_mktmp(tmp_path, path);
if (file->fd < 0) {
error = GIT_EOSERR;
goto cleanup;
@@ -283,10 +283,10 @@ int git_filebuf_commit(git_filebuf *file)
if ((error = flush_buffer(file)) < GIT_SUCCESS)
goto cleanup;
- gitfo_close(file->fd);
+ p_close(file->fd);
file->fd = -1;
- error = gitfo_mv(file->path_lock, file->path_original);
+ error = git_futils_mv_atomic(file->path_lock, file->path_original);
cleanup:
git_filebuf_cleanup(file);
diff --git a/src/fileops.c b/src/fileops.c
index 3f0198d..486ea3b 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -2,22 +2,45 @@
#include "fileops.h"
#include <ctype.h>
-int gitfo_mkdir_2file(const char *file_path)
+int git_futils_mv_atomic(const char *from, const char *to)
+{
+#ifdef GIT_WIN32
+ /*
+ * Win32 POSIX compilance my ass. If the destination
+ * file exists, the `rename` call fails. This is as
+ * close as it gets with the Win32 API.
+ */
+ return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? GIT_SUCCESS : GIT_EOSERR;
+#else
+ /* Don't even try this on Win32 */
+ if (!link(from, to)) {
+ p_unlink(from);
+ return GIT_SUCCESS;
+ }
+
+ if (!rename(from, to))
+ return GIT_SUCCESS;
+
+ return GIT_ERROR;
+#endif
+}
+
+int git_futils_mkpath2file(const char *file_path)
{
const int mode = 0755; /* or 0777 ? */
int error = GIT_SUCCESS;
char target_folder_path[GIT_PATH_MAX];
- error = git__dirname_r(target_folder_path, sizeof(target_folder_path), file_path);
+ error = git_path_dirname_r(target_folder_path, sizeof(target_folder_path), file_path);
if (error < GIT_SUCCESS)
return git__throw(GIT_EINVALIDPATH, "Failed to recursively build `%s` tree structure. Unable to parse parent folder name", file_path);
/* Does the containing folder exist? */
- if (gitfo_isdir(target_folder_path)) {
- git__joinpath(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */
+ if (git_futils_isdir(target_folder_path)) {
+ git_path_join(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */
/* Let's create the tree structure */
- error = gitfo_mkdir_recurs(target_folder_path, mode);
+ error = git_futils_mkdir_r(target_folder_path, mode);
if (error < GIT_SUCCESS)
return error; /* The callee already takes care of setting the correct error message. */
}
@@ -25,7 +48,7 @@ int gitfo_mkdir_2file(const char *file_path)
return GIT_SUCCESS;
}
-int gitfo_mktemp(char *path_out, const char *filename)
+int git_futils_mktmp(char *path_out, const char *filename)
{
int fd;
@@ -38,7 +61,7 @@ int gitfo_mktemp(char *path_out, const char *filename)
if (_mktemp_s(path_out, GIT_PATH_MAX) != 0)
return git__throw(GIT_EOSERR, "Failed to make temporary file %s", path_out);
- fd = gitfo_creat(path_out, 0744);
+ fd = p_creat(path_out, 0744);
#else
fd = mkstemp(path_out);
#endif
@@ -46,79 +69,29 @@ int gitfo_mktemp(char *path_out, const char *filename)
return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create temporary file %s", path_out);
}
-int gitfo_open(const char *path, int flags)
+int git_futils_creat_withpath(const char *path, int mode)
{
- int fd = open(path, flags | O_BINARY);
- return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to open %s", path);
-}
-
-int gitfo_creat(const char *path, int mode)
-{
- int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
- return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create file. Could not open %s", path);
-}
-
-int gitfo_creat_force(const char *path, int mode)
-{
- if (gitfo_mkdir_2file(path) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to create file %s", path);
- return gitfo_creat(path, mode);
+ return p_creat(path, mode);
}
-int gitfo_creat_locked(const char *path, int mode)
+int git_futils_creat_locked(const char *path, int mode)
{
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode);
return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create locked file. Could not open %s", path);
}
-int gitfo_creat_locked_force(const char *path, int mode)
+int git_futils_creat_locked_withpath(const char *path, int mode)
{
- if (gitfo_mkdir_2file(path) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to create locked file %s", path);
- return gitfo_creat_locked(path, mode);
-}
-
-int gitfo_read(git_file fd, void *buf, size_t cnt)
-{
- char *b = buf;
- while (cnt) {
- ssize_t r = read(fd, b, cnt);
- if (r < 0) {
- if (errno == EINTR || errno == EAGAIN)
- continue;
- return git__throw(GIT_EOSERR, "Failed to read from file");
- }
- if (!r)
- break;
- cnt -= r;
- b += r;
- }
- return (int)(b - (char *)buf);
-}
-
-int gitfo_write(git_file fd, void *buf, size_t cnt)
-{
- char *b = buf;
- while (cnt) {
- ssize_t r = write(fd, b, cnt);
- if (r < 0) {
- if (errno == EINTR || errno == EAGAIN)
- continue;
- return git__throw(GIT_EOSERR, "Failed to write to file");
- }
- if (!r) {
- errno = EPIPE;
- return git__throw(GIT_EOSERR, "Failed to write to file");
- }
- cnt -= r;
- b += r;
- }
- return GIT_SUCCESS;
+ return git_futils_creat_locked(path, mode);
}
-int gitfo_isdir(const char *path)
+int git_futils_isdir(const char *path)
{
struct stat st;
int len, stat_error;
@@ -132,10 +105,10 @@ int gitfo_isdir(const char *path)
char *path_fixed = NULL;
path_fixed = git__strdup(path);
path_fixed[len - 1] = 0;
- stat_error = gitfo_stat(path_fixed, &st);
+ stat_error = p_stat(path_fixed, &st);
free(path_fixed);
} else {
- stat_error = gitfo_stat(path, &st);
+ stat_error = p_stat(path, &st);
}
if (stat_error < GIT_SUCCESS)
@@ -147,15 +120,15 @@ int gitfo_isdir(const char *path)
return GIT_SUCCESS;
}
-int gitfo_isfile(const char *path)
+int git_futils_isfile(const char *path)
{
struct stat st;
int stat_error;
if (!path)
- return git__throw(GIT_ENOTFOUND, "No path given to gitfo_isfile");
+ return git__throw(GIT_ENOTFOUND, "No path given to git_futils_isfile");
- stat_error = gitfo_stat(path, &st);
+ stat_error = p_stat(path, &st);
if (stat_error < GIT_SUCCESS)
return git__throw(GIT_ENOTFOUND, "%s does not exist", path);
@@ -166,21 +139,21 @@ int gitfo_isfile(const char *path)
return GIT_SUCCESS;
}
-int gitfo_exists(const char *path)
+int git_futils_exists(const char *path)
{
assert(path);
return access(path, F_OK);
}
-git_off_t gitfo_size(git_file fd)
+git_off_t git_futils_filesize(git_file fd)
{
struct stat sb;
- if (gitfo_fstat(fd, &sb))
+ if (p_fstat(fd, &sb))
return git__throw(GIT_EOSERR, "Failed to get size of file. File missing or corrupted");
return sb.st_size;
}
-int gitfo_read_file(gitfo_buf *obj, const char *path)
+int git_futils_readbuffer(git_fbuffer *obj, const char *path)
{
git_file fd;
size_t len;
@@ -189,28 +162,28 @@ int gitfo_read_file(gitfo_buf *obj, const char *path)
assert(obj && path && *path);
- if ((fd = gitfo_open(path, O_RDONLY)) < 0)
+ if ((fd = p_open(path, O_RDONLY)) < 0)
return git__throw(GIT_ERROR, "Failed to open %s for reading", path);
- if (((size = gitfo_size(fd)) < 0) || !git__is_sizet(size+1)) {
- gitfo_close(fd);
+ if (((size = git_futils_filesize(fd)) < 0) || !git__is_sizet(size+1)) {
+ p_close(fd);
return git__throw(GIT_ERROR, "Failed to read file `%s`. An error occured while calculating its size", path);
}
len = (size_t) size;
if ((buff = git__malloc(len + 1)) == NULL) {
- gitfo_close(fd);
+ p_close(fd);
return GIT_ENOMEM;
}
- if (gitfo_read(fd, buff, len) < 0) {
- gitfo_close(fd);
+ if (p_read(fd, buff, len) < 0) {
+ p_close(fd);
free(buff);
return git__throw(GIT_ERROR, "Failed to read file `%s`", path);
}
buff[len] = '\0';
- gitfo_close(fd);
+ p_close(fd);
obj->data = buff;
obj->len = len;
@@ -218,64 +191,33 @@ int gitfo_read_file(gitfo_buf *obj, const char *path)
return GIT_SUCCESS;
}
-void gitfo_free_buf(gitfo_buf *obj)
+void git_futils_freebuffer(git_fbuffer *obj)
{
assert(obj);
free(obj->data);
obj->data = NULL;
}
-int gitfo_mv(const char *from, const char *to)
-{
- int error;
-
-#ifdef GIT_WIN32
- /*
- * Win32 POSIX compilance my ass. If the destination
- * file exists, the `rename` call fails. This is as
- * close as it gets with the Win32 API.
- */
- error = MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? GIT_SUCCESS : GIT_EOSERR;
-#else
- /* Don't even try this on Win32 */
- if (!link(from, to)) {
- gitfo_unlink(from);
- return GIT_SUCCESS;
- }
- if (!rename(from, to))
- return GIT_SUCCESS;
-
- error = GIT_EOSERR;
-#endif
-
- if (error < GIT_SUCCESS)
- return git__throw(error, "Failed to move file from `%s` to `%s`", from, to);
-
- return GIT_SUCCESS;
-}
-
-int gitfo_mv_force(const char *from, const char *to)
+int git_futils_mv_withpath(const char *from, const char *to)
{
- if (gitfo_mkdir_2file(to) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(to) < GIT_SUCCESS)
return GIT_EOSERR; /* The callee already takes care of setting the correct error message. */
- return gitfo_mv(from, to); /* The callee already takes care of setting the correct error message. */
+ return git_futils_mv_atomic(from, to); /* The callee already takes care of setting the correct error message. */
}
-int gitfo_map_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
+int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
{
- if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)
- return GIT_EOSERR;
- return GIT_SUCCESS;
+ return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin);
}
-void gitfo_free_map(git_map *out)
+void git_futils_mmap_free(git_map *out)
{
- git__munmap(out);
+ p_munmap(out);
}
-int gitfo_dirent(
+int git_futils_direach(
char *path,
size_t path_sz,
int (*fn)(void *, char *),
@@ -331,33 +273,14 @@ int gitfo_dirent(
return GIT_SUCCESS;
}
-#if GIT_PLATFORM_PATH_SEP == '/'
-void gitfo_posixify_path(char *GIT_UNUSED(path))
-{
- /* nothing to do*/
-}
-#else
-void gitfo_posixify_path(char *path)
-{
- while (*path) {
- if (*path == GIT_PLATFORM_PATH_SEP)
- *path = '/';
-
- path++;
- }
-}
-#endif
-
-int gitfo_retrieve_path_root_offset(const char *path)
+int git_futils_root_offset(const char *path)
{
int offset = 0;
#ifdef GIT_WIN32
-
/* Does the root of the path look like a windows drive ? */
if (isalpha(path[0]) && (path[1] == ':'))
offset += 2;
-
#endif
if (*(path + offset) == '/')
@@ -366,7 +289,7 @@ int gitfo_retrieve_path_root_offset(const char *path)
return -1; /* Not a real error. Rather a signal than the path is not rooted */
}
-int gitfo_mkdir_recurs(const char *path, int mode)
+int git_futils_mkdir_r(const char *path, int mode)
{
int error, root_path_offset;
char *pp, *sp;
@@ -378,14 +301,14 @@ int gitfo_mkdir_recurs(const char *path, int mode)
error = GIT_SUCCESS;
pp = path_copy;
- root_path_offset = gitfo_retrieve_path_root_offset(pp);
+ root_path_offset = git_futils_root_offset(pp);
if (root_path_offset > 0)
pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) {
- if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) {
+ if (sp != pp && git_futils_isdir(path_copy) < GIT_SUCCESS) {
*sp = 0;
- error = gitfo_mkdir(path_copy, mode);
+ error = p_mkdir(path_copy, mode);
/* Do not choke while trying to recreate an existing directory */
if (errno == EEXIST)
@@ -398,7 +321,7 @@ int gitfo_mkdir_recurs(const char *path, int mode)
}
if (*pp != '\0' && error == GIT_SUCCESS) {
- error = gitfo_mkdir(path, mode);
+ error = p_mkdir(path, mode);
if (errno == EEXIST)
error = GIT_SUCCESS;
}
@@ -415,7 +338,7 @@ static int retrieve_previous_path_component_start(const char *path)
{
int offset, len, root_offset, start = 0;
- root_offset = gitfo_retrieve_path_root_offset(path);
+ root_offset = git_futils_root_offset(path);
if (root_offset > -1)
start += root_offset;
@@ -440,7 +363,7 @@ static int retrieve_previous_path_component_start(const char *path)
return offset;
}
-int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, const char *base_path)
+int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, const char *base_path)
{
int len = 0, segment_len, only_dots, root_path_offset, error = GIT_SUCCESS;
char *current;
@@ -450,10 +373,10 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con
buffer_end = path + strlen(path);
buffer_out_start = buffer_out;
- root_path_offset = gitfo_retrieve_path_root_offset(path);
+ root_path_offset = git_futils_root_offset(path);
if (root_path_offset < 0) {
if (base_path == NULL) {
- error = gitfo_getcwd(buffer_out, size);
+ error = p_getcwd(buffer_out, size);
if (error < GIT_SUCCESS)
return error; /* The callee already takes care of setting the correct error message. */
} else {
@@ -461,8 +384,8 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con
return git__throw(GIT_EOVERFLOW, "Failed to prettify dir path: the base path is too long for the buffer.");
strcpy(buffer_out, base_path);
- gitfo_posixify_path(buffer_out);
- git__joinpath(buffer_out, buffer_out, "");
+ git_path_mkposix(buffer_out);
+ git_path_join(buffer_out, buffer_out, "");
}
len = strlen(buffer_out);
@@ -527,7 +450,7 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con
return GIT_SUCCESS;
}
-int gitfo_prettify_file_path(char *buffer_out, size_t size, const char *path, const char *base_path)
+int git_futils_prettyify_file(char *buffer_out, size_t size, const char *path, const char *base_path)
{
int error, path_len, i, root_offset;
const char* pattern = "/..";
@@ -544,12 +467,12 @@ int gitfo_prettify_file_path(char *buffer_out, size_t size, const char *path, co
return git__throw(GIT_EINVALIDPATH, "Failed to normalize file path `%s`. The path points to a folder", path);
}
- error = gitfo_prettify_dir_path(buffer_out, size, path, base_path);
+ error = git_futils_prettify_dir(buffer_out, size, path, base_path);
if (error < GIT_SUCCESS)
return error; /* The callee already takes care of setting the correct error message. */
path_len = strlen(buffer_out);
- root_offset = gitfo_retrieve_path_root_offset(buffer_out) + 1;
+ root_offset = git_futils_root_offset(buffer_out) + 1;
if (path_len == root_offset)
return git__throw(GIT_EINVALIDPATH, "Failed to normalize file path `%s`. The path points to a folder", path);
@@ -559,7 +482,7 @@ int gitfo_prettify_file_path(char *buffer_out, size_t size, const char *path, co
return GIT_SUCCESS;
}
-int gitfo_cmp_path(const char *name1, int len1, int isdir1,
+int git_futils_cmp_path(const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2)
{
int len = len1 < len2 ? len1 : len2;
@@ -577,185 +500,3 @@ int gitfo_cmp_path(const char *name1, int len1, int isdir1,
return 0;
}
-int gitfo_getcwd(char *buffer_out, size_t size)
-{
- char *cwd_buffer;
-
- assert(buffer_out && size > 0);
-
-#ifdef GIT_WIN32
- cwd_buffer = _getcwd(buffer_out, size);
-#else
- cwd_buffer = getcwd(buffer_out, size);
-#endif
-
- if (cwd_buffer == NULL)
- return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");
-
- gitfo_posixify_path(buffer_out);
-
- git__joinpath(buffer_out, buffer_out, ""); //Ensure the path ends with a trailing slash
-
- return GIT_SUCCESS;
-}
-
-#ifdef GIT_WIN32
-GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft)
-{
- long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
- winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
- winTime /= 10000000; /* Nano to seconds resolution */
- return (time_t)winTime;
-}
-
-static int do_lstat(const char *file_name, struct stat *buf)
-{
- WIN32_FILE_ATTRIBUTE_DATA fdata;
-
- if (GetFileAttributesExA(file_name, GetFileExInfoStandard, &fdata)) {
- int fMode = S_IREAD;
-
- if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- fMode |= S_IFDIR;
- else
- fMode |= S_IFREG;
-
- if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
- fMode |= S_IWRITE;
-
- if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
- fMode |= S_IFLNK;
-
- buf->st_ino = 0;
- buf->st_gid = 0;
- buf->st_uid = 0;
- buf->st_nlink = 1;
- buf->st_mode = (mode_t)fMode;
- buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
- buf->st_dev = buf->st_rdev = (_getdrive() - 1);
- buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
- buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
- buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
- return GIT_SUCCESS;
- }
-
- switch (GetLastError()) {
- case ERROR_ACCESS_DENIED:
- case ERROR_SHARING_VIOLATION:
- case ERROR_LOCK_VIOLATION:
- case ERROR_SHARING_BUFFER_EXCEEDED:
- return GIT_EOSERR;
-
- case ERROR_BUFFER_OVERFLOW:
- case ERROR_NOT_ENOUGH_MEMORY:
- return GIT_ENOMEM;
-
- default:
- return GIT_EINVALIDPATH;
- }
-}
-
-int gitfo_lstat__w32(const char *file_name, struct stat *buf)
-{
- int namelen, error;
- char alt_name[GIT_PATH_MAX];
-
- if ((error = do_lstat(file_name, buf)) == GIT_SUCCESS)
- return GIT_SUCCESS;
-
- /* if file_name ended in a '/', Windows returned ENOENT;
- * try again without trailing slashes
- */
- if (error != GIT_EINVALIDPATH)
- return git__throw(GIT_EOSERR, "Failed to lstat file");
-
- namelen = strlen(file_name);
- if (namelen && file_name[namelen-1] != '/')
- return git__throw(GIT_EOSERR, "Failed to lstat file");
-
- while (namelen && file_name[namelen-1] == '/')
- --namelen;
-
- if (!namelen || namelen >= GIT_PATH_MAX)
- return git__throw(GIT_ENOMEM, "Failed to lstat file");
-
- memcpy(alt_name, file_name, namelen);
- alt_name[namelen] = 0;
- return do_lstat(alt_name, buf);
-}
-
-int gitfo_readlink__w32(const char *link, char *target, size_t target_len)
-{
- typedef DWORD (WINAPI *fpath_func)(HANDLE, LPTSTR, DWORD, DWORD);
- static fpath_func pGetFinalPath = NULL;
- HANDLE hFile;
- DWORD dwRet;
-
- /*
- * Try to load the pointer to pGetFinalPath dynamically, because
- * it is not available in platforms older than Vista
- */
- if (pGetFinalPath == NULL) {
- HINSTANCE library = LoadLibrary("kernel32");
-
- if (library != NULL)
- pGetFinalPath = (fpath_func)GetProcAddress(library, "GetFinalPathNameByHandleA");
-
- if (pGetFinalPath == NULL)
- return git__throw(GIT_EOSERR,
- "'GetFinalPathNameByHandleA' is not available in this platform");
- }
-
- hFile = CreateFile(link, // file to open
- GENERIC_READ, // open for reading
- FILE_SHARE_READ, // share for reading
- NULL, // default security
- OPEN_EXISTING, // existing file only
- FILE_FLAG_BACKUP_SEMANTICS, // normal file
- NULL); // no attr. template
-
- if (hFile == INVALID_HANDLE_VALUE)
- return GIT_EOSERR;
-
- dwRet = pGetFinalPath(hFile, target, target_len, 0x0);
- if (dwRet >= target_len)
- return GIT_ENOMEM;
-
- CloseHandle(hFile);
-
- if (dwRet > 4) {
- /* Skip first 4 characters if they are "\\?\" */
- if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
- char tmp[GIT_PATH_MAX];
- unsigned int offset = 4;
- dwRet -= 4;
-
- /* \??\UNC\ */
- if (dwRet > 7 && target[4] == 'U' && target[5] == 'N' && target[6] == 'C') {
- offset += 2;
- dwRet -= 2;
- target[offset] = '\\';
- }
-
- memcpy(tmp, target + offset, dwRet);
- memcpy(target, tmp, dwRet);
- }
- }
-
- target[dwRet] = '\0';
- return dwRet;
-}
-
-int gitfo_hide_directory__w32(const char *path)
-{
- int error;
-
- error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ?
- GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
-
- if (error < GIT_SUCCESS)
- error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path);
-
- return error;
-}
-#endif
diff --git a/src/fileops.h b/src/fileops.h
index d9fa960..52eb229 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -9,110 +9,98 @@
#include "common.h"
#include "map.h"
#include "dir.h"
-#include <fcntl.h>
-#include <time.h>
-
-#ifdef GIT_WIN32
-#define GIT_PLATFORM_PATH_SEP '\\'
-#else
-#define GIT_PLATFORM_PATH_SEP '/'
-#endif
-
-#define S_IFGITLINK 0160000
-#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
-
-#ifdef GIT_WIN32
-GIT_INLINE(int) link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new))
-{
- GIT_UNUSED_ARG(old)
- GIT_UNUSED_ARG(new)
- errno = ENOSYS;
- return -1;
-}
-
-GIT_INLINE(int) git__mkdir(const char *path, int GIT_UNUSED(mode))
-{
- GIT_UNUSED_ARG(mode)
- return mkdir(path);
-}
-
-extern int git__unlink(const char *path);
-extern int git__mkstemp(char *template);
-extern int git__fsync(int fd);
-
-# ifndef GIT__WIN32_NO_HIDE_FILEOPS
-# define unlink(p) git__unlink(p)
-# define mkstemp(t) git__mkstemp(t)
-# define mkdir(p,m) git__mkdir(p, m)
-# define fsync(fd) git__fsync(fd)
-# endif
-#endif /* GIT_WIN32 */
-
-
-#if !defined(O_BINARY)
-#define O_BINARY 0
-#endif
-
-#define GITFO_BUF_INIT {NULL, 0}
-
-typedef int git_file;
+#include "posix.h"
+#include "path.h"
+
+/**
+ * Filebuffer methods
+ *
+ * Read whole files into an in-memory buffer for processing
+ */
+#define GIT_FBUFFER_INIT {NULL, 0}
typedef struct { /* file io buffer */
void *data; /* data bytes */
size_t len; /* data length */
-} gitfo_buf;
-
-extern int gitfo_exists(const char *path);
-extern int gitfo_open(const char *path, int flags);
-extern int gitfo_creat(const char *path, int mode);
-extern int gitfo_creat_force(const char *path, int mode);
-extern int gitfo_creat_locked(const char *path, int mode);
-extern int gitfo_creat_locked_force(const char *path, int mode);
-extern int gitfo_mktemp(char *path_out, const char *filename);
-extern int gitfo_isdir(const char *path);
-extern int gitfo_isfile(const char *path);
-extern int gitfo_mkdir_recurs(const char *path, int mode);
-extern int gitfo_mkdir_2file(const char *path);
-#define gitfo_close(fd) close(fd)
-
-extern int gitfo_read(git_file fd, void *buf, size_t cnt);
-extern int gitfo_write(git_file fd, void *buf, size_t cnt);
-#define gitfo_lseek(f,n,w) lseek(f, n, w)
-extern git_off_t gitfo_size(git_file fd);
-
-extern int gitfo_read_file(gitfo_buf *obj, const char *path);
-extern void gitfo_free_buf(gitfo_buf *obj);
-
-/* Move (rename) a file; this operation is atomic */
-extern int gitfo_mv(const char *from, const char *to);
-
-/* Move a file (forced); this will create the destination
- * path if it doesn't exist */
-extern int gitfo_mv_force(const char *from, const char *to);
-
-#define gitfo_stat(p,b) stat(p, b)
-#define gitfo_fstat(f,b) fstat(f, b)
-
-#ifdef GIT_WIN32
-# define gitfo_lstat(p,b) gitfo_lstat__w32(p,b)
-# define gitfo_readlink(a, b, c) gitfo_readlink__w32(a, b, c)
-
- extern int gitfo_lstat__w32(const char *file_name, struct stat *buf);
- extern int gitfo_readlink__w32(const char *link, char *target, size_t target_len);
- extern int gitfo_hide_directory__w32(const char *path);
-#else
-# define gitfo_lstat(p,b) lstat(p,b)
-# define gitfo_readlink(a, b, c) readlink(a, b, c)
-#endif
-
-#define gitfo_unlink(p) unlink(p)
-#define gitfo_rmdir(p) rmdir(p)
-#define gitfo_chdir(p) chdir(p)
-#define gitfo_mkdir(p,m) mkdir(p, m)
-
-#define gitfo_mkstemp(t) mkstemp(t)
-#define gitfo_fsync(fd) fsync(fd)
-#define gitfo_chmod(p,m) chmod(p, m)
+} git_fbuffer;
+
+extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
+extern void git_futils_freebuffer(git_fbuffer *obj);
+
+/**
+ * File utils
+ *
+ * These are custom filesystem-related helper methods. They are
+ * rather high level, and wrap the underlying POSIX methods
+ *
+ * All these methods return GIT_SUCCESS on success,
+ * or an error code on failure and an error message is set.
+ */
+
+/**
+ * Check if a file exists and can be accessed.
+ */
+extern int git_futils_exists(const char *path);
+
+/**
+ * Create and open a file, while also
+ * creating all the folders in its path
+ */
+extern int git_futils_creat_withpath(const char *path, int mode);
+
+/**
+ * Create an open a process-locked file
+ */
+extern int git_futils_creat_locked(const char *path, int mode);
+
+/**
+ * Create an open a process-locked file, while
+ * also creating all the folders in its path
+ */
+extern int git_futils_creat_locked_withpath(const char *path, int mode);
+
+/**
+ * Check if the given path points to a directory
+ */
+extern int git_futils_isdir(const char *path);
+
+/**
+ * Check if the given path points to a regular file
+ */
+extern int git_futils_isfile(const char *path);
+
+/**
+ * Create a path recursively
+ */
+extern int git_futils_mkdir_r(const char *path, int mode);
+
+/**
+ * Create all the folders required to contain
+ * the full path of a file
+ */
+extern int git_futils_mkpath2file(const char *path);
+
+/**
+ * Create and open a temporary file with a `_git2_` suffix
+ */
+extern int git_futils_mktmp(char *path_out, const char *filename);
+
+/**
+ * Atomically rename a file on the filesystem
+ */
+extern int git_futils_mv_atomic(const char *from, const char *to);
+
+/**
+ * Move a file on the filesystem, create the
+ * destination path if it doesn't exist
+ */
+extern int git_futils_mv_withpath(const char *from, const char *to);
+
+
+/**
+ * Get the filesize in bytes of a file
+ */
+extern git_off_t git_futils_filesize(git_file fd);
/**
* Read-only map all or part of a file into memory.
@@ -129,7 +117,7 @@ extern int gitfo_mv_force(const char *from, const char *to);
* - GIT_SUCCESS on success;
* - GIT_EOSERR on an unspecified OS related error.
*/
-extern int gitfo_map_ro(
+extern int git_futils_mmap_ro(
git_map *out,
git_file fd,
git_off_t begin,
@@ -139,7 +127,7 @@ extern int gitfo_map_ro(
* Release the memory associated with a previous memory mapping.
* @param map the mapping description previously configured.
*/
-extern void gitfo_free_map(git_map *map);
+extern void git_futils_mmap_free(git_map *map);
/**
* Walk each directory entry, except '.' and '..', calling fn(state).
@@ -152,16 +140,15 @@ extern void gitfo_free_map(git_map *map);
* may modify the pathbuf, but only by appending new text.
* @param state to pass to fn as the first arg.
*/
-extern int gitfo_dirent(
+extern int git_futils_direach(
char *pathbuf,
size_t pathmax,
int (*fn)(void *, char *),
void *state);
-extern int gitfo_cmp_path(const char *name1, int len1, int isdir1,
+extern int git_futils_cmp_path(const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2);
-extern int gitfo_getcwd(char *buffer_out, size_t size);
/**
* Clean up a provided absolute or relative directory path.
@@ -186,7 +173,7 @@ extern int gitfo_getcwd(char *buffer_out, size_t size);
* - GIT_SUCCESS on success;
* - GIT_ERROR when the input path is invalid or escapes the current directory.
*/
-int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, const char *base_path);
+int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, const char *base_path);
/**
* Clean up a provided absolute or relative file path.
@@ -209,10 +196,8 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con
* - GIT_SUCCESS on success;
* - GIT_ERROR when the input path is invalid or escapes the current directory.
*/
-int gitfo_prettify_file_path(char *buffer_out, size_t size, const char *path, const char *base_path);
-
-void gitfo_posixify_path(char *path);
+int git_futils_prettyify_file(char *buffer_out, size_t size, const char *path, const char *base_path);
-int gitfo_retrieve_path_root_offset(const char *path);
+int git_futils_root_offset(const char *path);
#endif /* INCLUDE_fileops_h__ */
diff --git a/src/index.c b/src/index.c
index ed91e05..06fa95c 100644
--- a/src/index.c
+++ b/src/index.c
@@ -170,7 +170,7 @@ static int index_initialize(git_index **index_out, git_repository *owner, const
git_vector_init(&index->entries, 32, index_cmp);
/* Check if index file is stored on disk already */
- if (gitfo_exists(index->index_file_path) == 0)
+ if (git_futils_exists(index->index_file_path) == 0)
index->on_disk = 1;
*index_out = index;
@@ -259,13 +259,13 @@ int git_index_read(git_index *index)
assert(index->index_file_path);
- if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) {
+ if (!index->on_disk || git_futils_exists(index->index_file_path) < 0) {
git_index_clear(index);
index->on_disk = 0;
return GIT_SUCCESS;
}
- if (gitfo_stat(index->index_file_path, &indexst) < 0)
+ if (p_stat(index->index_file_path, &indexst) < 0)
return git__throw(GIT_EOSERR, "Failed to read index. %s does not exist or is corrupted", index->index_file_path);
if (!S_ISREG(indexst.st_mode))
@@ -273,9 +273,9 @@ int git_index_read(git_index *index)
if (indexst.st_mtime != index->last_modified) {
- gitfo_buf buffer;
+ git_fbuffer buffer;
- if ((error = gitfo_read_file(&buffer, index->index_file_path)) < GIT_SUCCESS)
+ if ((error = git_futils_readbuffer(&buffer, index->index_file_path)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to read index");
git_index_clear(index);
@@ -284,7 +284,7 @@ int git_index_read(git_index *index)
if (error == GIT_SUCCESS)
index->last_modified = indexst.st_mtime;
- gitfo_free_buf(&buffer);
+ git_futils_freebuffer(&buffer);
}
if (error < GIT_SUCCESS)
@@ -311,7 +311,7 @@ int git_index_write(git_index *index)
if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write index");
- if (gitfo_stat(index->index_file_path, &indexst) == 0) {
+ if (p_stat(index->index_file_path, &indexst) == 0) {
index->last_modified = indexst.st_mtime;
index->on_disk = 1;
}
@@ -409,9 +409,9 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
if (index->repository == NULL)
return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare");
- git__joinpath(full_path, index->repository->path_workdir, rel_path);
+ git_path_join(full_path, index->repository->path_workdir, rel_path);
- if (gitfo_lstat(full_path, &st) < 0)
+ if (p_lstat(full_path, &st) < 0)
return git__throw(GIT_EOSERR, "Failed to initialize entry. '%s' cannot be opened", full_path);
if (stage < 0 || stage > 3)
diff --git a/src/map.h b/src/map.h
index be569ab..1dfbeeb 100644
--- a/src/map.h
+++ b/src/map.h
@@ -4,7 +4,7 @@
#include "common.h"
-/* git__mmap() prot values */
+/* p_mmap() prot values */
#define GIT_PROT_NONE 0x0
#define GIT_PROT_READ 0x1
#define GIT_PROT_WRITE 0x2
@@ -25,7 +25,7 @@ typedef struct { /* memory mapped buffer */
#endif
} git_map;
-extern int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
-extern int git__munmap(git_map *map);
+extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
+extern int p_munmap(git_map *map);
#endif /* INCLUDE_map_h__ */
diff --git a/src/odb.c b/src/odb.c
index 0ee790e..b099316 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -323,15 +323,15 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
char alternates_path[GIT_PATH_MAX];
char *buffer, *alternate;
- gitfo_buf alternates_buf = GITFO_BUF_INIT;
+ git_fbuffer alternates_buf = GIT_FBUFFER_INIT;
int error;
- git__joinpath(alternates_path, objects_dir, GIT_ALTERNATES_FILE);
+ git_path_join(alternates_path, objects_dir, GIT_ALTERNATES_FILE);
- if (gitfo_exists(alternates_path) < GIT_SUCCESS)
+ if (git_futils_exists(alternates_path) < GIT_SUCCESS)
return GIT_SUCCESS;
- if (gitfo_read_file(&alternates_buf, alternates_path) < GIT_SUCCESS)
+ if (git_futils_readbuffer(&alternates_buf, alternates_path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates");
buffer = (char *)alternates_buf.data;
@@ -346,7 +346,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
/* relative path: build based on the current `objects` folder */
if (*alternate == '.') {
- git__joinpath(full_path, objects_dir, alternate);
+ git_path_join(full_path, objects_dir, alternate);
alternate = full_path;
}
@@ -354,7 +354,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
break;
}
- gitfo_free_buf(&alternates_buf);
+ git_futils_freebuffer(&alternates_buf);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to load alternates");
return error;
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 510712b..2a2c464 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -97,7 +97,7 @@ static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *i
}
-static size_t get_binary_object_header(obj_hdr *hdr, gitfo_buf *obj)
+static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
{
unsigned char c;
unsigned char *data = obj->data;
@@ -199,7 +199,7 @@ static void set_stream_output(z_stream *s, void *out, size_t len)
}
-static int start_inflate(z_stream *s, gitfo_buf *obj, void *out, size_t len)
+static int start_inflate(z_stream *s, git_fbuffer *obj, void *out, size_t len)
{
int status;
@@ -309,7 +309,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
* of loose object data into packs. This format is no longer used, but
* we must still read it.
*/
-static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj)
+static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
{
unsigned char *in, *buf;
obj_hdr hdr;
@@ -347,7 +347,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj)
return GIT_SUCCESS;
}
-static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj)
+static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
{
unsigned char head[64], *buf;
z_stream zs;
@@ -405,7 +405,7 @@ static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj)
static int read_loose(git_rawobj *out, const char *loc)
{
int error;
- gitfo_buf obj = GITFO_BUF_INIT;
+ git_fbuffer obj = GIT_FBUFFER_INIT;
assert(out && loc);
@@ -413,11 +413,11 @@ static int read_loose(git_rawobj *out, const char *loc)
out->len = 0;
out->type = GIT_OBJ_BAD;
- if (gitfo_read_file(&obj, loc) < 0)
+ if (git_futils_readbuffer(&obj, loc) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found");
error = inflate_disk_obj(out, &obj);
- gitfo_free_buf(&obj);
+ git_futils_freebuffer(&obj);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object");
}
@@ -434,7 +434,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
out->data = NULL;
- if ((fd = gitfo_open(loc, O_RDONLY)) < 0)
+ if ((fd = p_open(loc, O_RDONLY)) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to read loose object header. File not found");
init_stream(&zs, inflated_buffer, sizeof(inflated_buffer));
@@ -466,7 +466,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
cleanup:
finish_inflate(&zs);
- gitfo_close(fd);
+ p_close(fd);
if (error < GIT_SUCCESS)
return git__throw(error, "Failed to read loose object header. Header is corrupted");
@@ -477,7 +477,7 @@ cleanup:
static int locate_object(char *object_location, loose_backend *backend, const git_oid *oid)
{
object_file_name(object_location, GIT_PATH_MAX, backend->objects_dir, oid);
- return gitfo_exists(object_location);
+ return git_futils_exists(object_location);
}
/* Explore an entry of a directory and see if it matches a short oid */
@@ -490,7 +490,7 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) {
return GIT_SUCCESS;
}
- if (!gitfo_exists(pathbuf) && gitfo_isdir(pathbuf)) {
+ if (!git_futils_exists(pathbuf) && git_futils_isdir(pathbuf)) {
/* We are already in the directory matching the 2 first hex characters,
* compare the first ncmp characters of the oids */
if (!memcmp(sstate->short_oid + 2,
@@ -534,14 +534,14 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
sprintf(object_location+dir_len, "%.2s/", state.short_oid);
/* Check that directory exists */
- if (gitfo_exists(object_location) || gitfo_isdir(object_location))
+ if (git_futils_exists(object_location) || git_futils_isdir(object_location))
return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found");
state.dir_len = dir_len+3;
state.short_oid_len = len;
state.found = 0;
/* Explore directory to find a unique object matching short_oid */
- error = gitfo_dirent(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state);
+ error = git_futils_direach(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state);
if (error) {
return git__rethrow(error, "Failed to locate object from short oid");
}
@@ -684,7 +684,7 @@ int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
if (object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid))
return GIT_ENOMEM;
- if ((error = gitfo_mkdir_2file(final_path)) < GIT_SUCCESS)
+ if ((error = git_futils_mkpath2file(final_path)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write loose backend");
stream->finished = 1;
@@ -749,7 +749,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend
stream->stream.free = &loose_backend__stream_free;
stream->stream.mode = GIT_STREAM_WRONLY;
- git__joinpath(tmp_path, backend->objects_dir, "tmp_object");
+ git_path_join(tmp_path, backend->objects_dir, "tmp_object");
error = git_filebuf_open(&stream->fbuf, tmp_path,
GIT_FILEBUF_HASH_CONTENTS |
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 2f95fae..59661a6 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -359,7 +359,7 @@ void pack_window_free_all(struct pack_backend *backend, struct pack_file *p)
backend->mapped -= w->window_map.len;
backend->open_windows--;
- gitfo_free_map(&w->window_map);
+ git_futils_mmap_free(&w->window_map);
p->windows = w->next;
free(w);
@@ -416,14 +416,14 @@ static int pack_window_close_lru(
if (lru_p) {
backend->mapped -= lru_w->window_map.len;
- gitfo_free_map(&lru_w->window_map);
+ git_futils_mmap_free(&lru_w->window_map);
if (lru_l)
lru_l->next = lru_w->next;
else {
lru_p->windows = lru_w->next;
if (!lru_p->windows && lru_p->pack_fd != keep_fd) {
- gitfo_close(lru_p->pack_fd);
+ p_close(lru_p->pack_fd);
lru_p->pack_fd = -1;
}
}
@@ -491,7 +491,7 @@ static unsigned char *pack_window_open(
while (backend->mapped_limit < backend->mapped &&
pack_window_close_lru(backend, p, p->pack_fd) == GIT_SUCCESS) {}
- if (gitfo_map_ro(&win->window_map, p->pack_fd,
+ if (git_futils_mmap_ro(&win->window_map, p->pack_fd,
win->offset, len) < GIT_SUCCESS)
return NULL;
@@ -539,7 +539,7 @@ static unsigned char *pack_window_open(
static void pack_index_free(struct pack_file *p)
{
if (p->index_map.data) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
p->index_map.data = NULL;
}
}
@@ -555,15 +555,15 @@ static int pack_index_check(const char *path, struct pack_file *p)
struct stat st;
/* TODO: properly open the file without access time */
- git_file fd = gitfo_open(path, O_RDONLY /*| O_NOATIME */);
+ git_file fd = p_open(path, O_RDONLY /*| O_NOATIME */);
int error;
if (fd < 0)
return git__throw(GIT_EOSERR, "Failed to check index. File missing or corrupted");
- if (gitfo_fstat(fd, &st) < GIT_SUCCESS) {
- gitfo_close(fd);
+ if (p_fstat(fd, &st) < GIT_SUCCESS) {
+ p_close(fd);
return git__throw(GIT_EOSERR, "Failed to check index. File appears to be corrupted");
}
@@ -573,12 +573,12 @@ static int pack_index_check(const char *path, struct pack_file *p)
idx_size = (size_t)st.st_size;
if (idx_size < 4 * 256 + 20 + 20) {
- gitfo_close(fd);
+ p_close(fd);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
}
- error = gitfo_map_ro(&p->index_map, fd, 0, idx_size);
- gitfo_close(fd);
+ error = git_futils_mmap_ro(&p->index_map, fd, 0, idx_size);
+ p_close(fd);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to check index");
@@ -589,7 +589,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
version = ntohl(hdr->idx_version);
if (version < 2 || version > 2) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Unsupported index version");
}
@@ -605,7 +605,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
for (i = 0; i < 256; i++) {
uint32_t n = ntohl(index[i]);
if (n < nr) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Index is non-monotonic");
}
nr = n;
@@ -620,7 +620,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
* - 20-byte SHA1 file checksum
*/
if (idx_size != 4*256 + nr * 24 + 20 + 20) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
}
} else if (version == 2) {
@@ -644,14 +644,14 @@ static int pack_index_check(const char *path, struct pack_file *p)
max_size += (nr - 1)*8;
if (idx_size < min_size || idx_size > max_size) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Wrong index size");
}
/* Make sure that off_t is big enough to access the whole pack...
* Is this an issue in libgit2? It shouldn't. */
if (idx_size != min_size && (sizeof(off_t) <= 4)) {
- gitfo_free_map(&p->index_map);
+ git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOSERR, "Failed to check index. off_t not big enough to access the whole pack");
}
}
@@ -738,7 +738,7 @@ static void packfile_free(struct pack_backend *backend, struct pack_file *p)
pack_window_free_all(backend, p);
if (p->pack_fd != -1)
- gitfo_close(p->pack_fd);
+ p_close(p->pack_fd);
pack_index_free(p);
@@ -757,8 +757,8 @@ static int packfile_open(struct pack_file *p)
return git__throw(GIT_ENOTFOUND, "Failed to open packfile. File not found");
/* TODO: open with noatime */
- p->pack_fd = gitfo_open(p->pack_name, O_RDONLY);
- if (p->pack_fd < 0 || gitfo_fstat(p->pack_fd, &st) < GIT_SUCCESS)
+ p->pack_fd = p_open(p->pack_name, O_RDONLY);
+ if (p->pack_fd < 0 || p_fstat(p->pack_fd, &st) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to open packfile. File appears to be corrupted");
/* If we created the struct before we had the pack we lack size. */
@@ -783,7 +783,7 @@ static int packfile_open(struct pack_file *p)
#endif
/* Verify we recognize this pack file format. */
- if (gitfo_read(p->pack_fd, &hdr, sizeof(hdr)) < GIT_SUCCESS)
+ if (p_read(p->pack_fd, &hdr, sizeof(hdr)) < GIT_SUCCESS)
goto cleanup;
if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
@@ -796,10 +796,10 @@ static int packfile_open(struct pack_file *p)
if (p->num_objects != ntohl(hdr.hdr_entries))
goto cleanup;
- if (gitfo_lseek(p->pack_fd, p->pack_size - GIT_OID_RAWSZ, SEEK_SET) == -1)
+ if (p_lseek(p->pack_fd, p->pack_size - GIT_OID_RAWSZ, SEEK_SET) == -1)
goto cleanup;
- if (gitfo_read(p->pack_fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS)
+ if (p_read(p->pack_fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS)
goto cleanup;
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
@@ -810,7 +810,7 @@ static int packfile_open(struct pack_file *p)
return GIT_SUCCESS;
cleanup:
- gitfo_close(p->pack_fd);
+ p_close(p->pack_fd);
p->pack_fd = -1;
return git__throw(GIT_EPACKCORRUPTED, "Failed to packfile. Pack is corrupted");
}
@@ -838,11 +838,11 @@ static int packfile_check(struct pack_file **pack_out, const char *path)
memcpy(p->pack_name, path, path_len);
strcpy(p->pack_name + path_len, ".keep");
- if (gitfo_exists(p->pack_name) == GIT_SUCCESS)
+ if (git_futils_exists(p->pack_name) == GIT_SUCCESS)
p->pack_keep = 1;
strcpy(p->pack_name + path_len, ".pack");
- if (gitfo_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) {
+ if (p_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) {
free(p);
return git__throw(GIT_ENOTFOUND, "Failed to check packfile. File not found");
}
@@ -899,7 +899,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
if (backend->pack_folder == NULL)
return GIT_SUCCESS;
- if (gitfo_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
+ if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
return git__throw(GIT_ENOTFOUND, "Failed to refresh packfiles. Backend not found");
if (st.st_mtime != backend->pack_folder_mtime) {
@@ -907,7 +907,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
strcpy(path, backend->pack_folder);
/* reload all packs */
- error = gitfo_dirent(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend);
+ error = git_futils_direach(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to refresh packfiles");
@@ -1549,8 +1549,8 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
backend->window_size = DEFAULT_WINDOW_SIZE;
backend->mapped_limit = DEFAULT_MAPPED_LIMIT;
- git__joinpath(path, objects_dir, "pack");
- if (gitfo_isdir(path) == GIT_SUCCESS) {
+ git_path_join(path, objects_dir, "pack");
+ if (git_futils_isdir(path) == GIT_SUCCESS) {
backend->pack_folder = git__strdup(path);
backend->pack_folder_mtime = 0;
diff --git a/src/path.c b/src/path.c
new file mode 100644
index 0000000..766f674
--- /dev/null
+++ b/src/path.c
@@ -0,0 +1,204 @@
+#include "common.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <ctype.h>
+
+/*
+ * Based on the Android implementation, BSD licensed.
+ * Check http://android.git.kernel.org/
+ */
+int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
+{
+ const char *endp, *startp;
+ int len, result;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ startp = ".";
+ len = 1;
+ goto Exit;
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* All slashes becomes "/" */
+ if (endp == path && *endp == '/') {
+ startp = "/";
+ len = 1;
+ goto Exit;
+ }
+
+ /* Find the start of the base */
+ startp = endp;
+ while (startp > path && *(startp - 1) != '/')
+ startp--;
+
+ len = endp - startp +1;
+
+Exit:
+ result = len;
+ if (buffer == NULL) {
+ return result;
+ }
+ if (len > (int)bufflen-1) {
+ len = (int)bufflen-1;
+ result = GIT_ENOMEM;
+ }
+
+ if (len >= 0) {
+ memmove(buffer, startp, len);
+ buffer[len] = 0;
+ }
+ return result;
+}
+
+/*
+ * Based on the Android implementation, BSD licensed.
+ * Check http://android.git.kernel.org/
+ */
+int git_path_dirname_r(char *buffer, size_t bufflen, const char *path)
+{
+ const char *endp;
+ int result, len;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ path = ".";
+ len = 1;
+ goto Exit;
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* Find the start of the dir */
+ while (endp > path && *endp != '/')
+ endp--;
+
+ /* Either the dir is "/" or there are no slashes */
+ if (endp == path) {
+ path = (*endp == '/') ? "/" : ".";
+ len = 1;
+ goto Exit;
+ }
+
+ do {
+ endp--;
+ } while (endp > path && *endp == '/');
+
+ len = endp - path +1;
+
+Exit:
+ result = len;
+ if (len+1 > GIT_PATH_MAX) {
+ return GIT_ENOMEM;
+ }
+ if (buffer == NULL)
+ return result;
+
+ if (len > (int)bufflen-1) {
+ len = (int)bufflen-1;
+ result = GIT_ENOMEM;
+ }
+
+ if (len >= 0) {
+ memmove(buffer, path, len);
+ buffer[len] = 0;
+ }
+ return result;
+}
+
+
+char *git_path_dirname(const char *path)
+{
+ char *dname = NULL;
+ int len;
+
+ len = (path ? strlen(path) : 0) + 2;
+ dname = (char *)git__malloc(len);
+ if (dname == NULL)
+ return NULL;
+
+ if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
+ free(dname);
+ return NULL;
+ }
+
+ return dname;
+}
+
+char *git_path_basename(const char *path)
+{
+ char *bname = NULL;
+ int len;
+
+ len = (path ? strlen(path) : 0) + 2;
+ bname = (char *)git__malloc(len);
+ if (bname == NULL)
+ return NULL;
+
+ if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
+ free(bname);
+ return NULL;
+ }
+
+ return bname;
+}
+
+
+const char *git_path_topdir(const char *path)
+{
+ size_t len;
+ int i;
+
+ assert(path);
+ len = strlen(path);
+
+ if (!len || path[len - 1] != '/')
+ return NULL;
+
+ for (i = len - 2; i >= 0; --i)
+ if (path[i] == '/')
+ break;
+
+ return &path[i + 1];
+}
+
+void git_path_join_n(char *buffer_out, int count, ...)
+{
+ va_list ap;
+ int i;
+ char *buffer_start = buffer_out;
+
+ va_start(ap, count);
+ for (i = 0; i < count; ++i) {
+ const char *path;
+ int len;
+
+ path = va_arg(ap, const char *);
+
+ assert((i == 0) || path != buffer_start);
+
+ if (i > 0 && *path == '/' && buffer_out > buffer_start && buffer_out[-1] == '/')
+ path++;
+
+ if (!*path)
+ continue;
+
+ len = strlen(path);
+ memmove(buffer_out, path, len);
+ buffer_out = buffer_out + len;
+
+ if (i < count - 1 && buffer_out[-1] != '/')
+ *buffer_out++ = '/';
+ }
+ va_end(ap);
+
+ *buffer_out = '\0';
+}
+
diff --git a/src/path.h b/src/path.h
new file mode 100644
index 0000000..1bae9df
--- /dev/null
+++ b/src/path.h
@@ -0,0 +1,76 @@
+/*
+ * posix.h - Path management methods
+ */
+#ifndef INCLUDE_path_h__
+#define INCLUDE_path_h__
+
+#include "common.h"
+
+/*
+ * The dirname() function shall take a pointer to a character string
+ * that contains a pathname, and return a pointer to a string that is a
+ * pathname of the parent directory of that file. Trailing '/' characters
+ * in the path are not counted as part of the path.
+ *
+ * If path does not contain a '/', then dirname() shall return a pointer to
+ * the string ".". If path is a null pointer or points to an empty string,
+ * dirname() shall return a pointer to the string "." .
+ *
+ * The `git_path_dirname` implementation is thread safe. The returned
+ * string must be manually free'd.
+ *
+ * The `git_path_dirname_r` implementation expects a string allocated
+ * by the user with big enough size.
+ */
+extern char *git_path_dirname(const char *path);
+extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path);
+
+/*
+ * This function returns the basename of the file, which is the last
+ * part of its full name given by fname, with the drive letter and
+ * leading directories stripped off. For example, the basename of
+ * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
+ *
+ * Trailing slashes and backslashes are significant: the basename of
+ * c:/foo/bar/ is an empty string after the rightmost slash.
+ *
+ * The `git_path_basename` implementation is thread safe. The returned
+ * string must be manually free'd.
+ *
+ * The `git_path_basename_r` implementation expects a string allocated
+ * by the user with big enough size.
+ */
+extern char *git_path_basename(const char *path);
+extern int git_path_basename_r(char *buffer, size_t bufflen, const char *path);
+
+extern const char *git_path_topdir(const char *path);
+
+/**
+ * Join two paths together. Takes care of properly fixing the
+ * middle slashes and everything
+ *
+ * The paths are joined together into buffer_out; this is expected
+ * to be an user allocated buffer of `GIT_PATH_MAX` size
+ */
+extern void git_path_join_n(char *buffer_out, int npath, ...);
+
+GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char *path_b)
+{
+ git_path_join_n(buffer_out, 2, path_a, path_b);
+}
+
+#ifdef GIT_WIN32
+GIT_INLINE(void) git_path_mkposix(char *path)
+{
+ while (*path) {
+ if (*path == '\\')
+ *path = '/';
+
+ path++;
+ }
+}
+#else
+# define git_path_mkposix(p) /* blank */
+#endif
+
+#endif
diff --git a/src/posix.c b/src/posix.c
new file mode 100644
index 0000000..9dbebbd
--- /dev/null
+++ b/src/posix.c
@@ -0,0 +1,74 @@
+#include "common.h"
+#include "posix.h"
+#include "path.h"
+#include <stdio.h>
+#include <ctype.h>
+
+int p_open(const char *path, int flags)
+{
+ return open(path, flags | O_BINARY);
+}
+
+int p_creat(const char *path, int mode)
+{
+ return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
+}
+
+int p_read(git_file fd, void *buf, size_t cnt)
+{
+ char *b = buf;
+ while (cnt) {
+ ssize_t r = read(fd, b, cnt);
+ if (r < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return GIT_EOSERR;
+ }
+ if (!r)
+ break;
+ cnt -= r;
+ b += r;
+ }
+ return (int)(b - (char *)buf);
+}
+
+int p_write(git_file fd, void *buf, size_t cnt)
+{
+ char *b = buf;
+ while (cnt) {
+ ssize_t r = write(fd, b, cnt);
+ if (r < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return GIT_EOSERR;
+ }
+ if (!r) {
+ errno = EPIPE;
+ return GIT_EOSERR;
+ }
+ cnt -= r;
+ b += r;
+ }
+ return GIT_SUCCESS;
+}
+
+int p_getcwd(char *buffer_out, size_t size)
+{
+ char *cwd_buffer;
+
+ assert(buffer_out && size > 0);
+
+#ifdef GIT_WIN32
+ cwd_buffer = _getcwd(buffer_out, size);
+#else
+ cwd_buffer = getcwd(buffer_out, size);
+#endif
+
+ if (cwd_buffer == NULL)
+ return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");
+
+ git_path_mkposix(buffer_out);
+
+ git_path_join(buffer_out, buffer_out, ""); //Ensure the path ends with a trailing slash
+ return GIT_SUCCESS;
+}
diff --git a/src/posix.h b/src/posix.h
new file mode 100644
index 0000000..eaa8938
--- /dev/null
+++ b/src/posix.h
@@ -0,0 +1,54 @@
+/*
+ * posix.h - OS agnostic POSIX calls
+ */
+#ifndef INCLUDE_posix_h__
+#define INCLUDE_posix_h__
+
+#include "common.h"
+#include <fcntl.h>
+#include <time.h>
+
+#ifdef GIT_WIN32
+# include "win32/posix.h"
+#else
+# include "unix/posix.h"
+#endif
+
+#define S_IFGITLINK 0160000
+#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
+
+#if !defined(O_BINARY)
+#define O_BINARY 0
+#endif
+
+typedef int git_file;
+
+
+/**
+ * Standard POSIX Methods
+ *
+ * All the methods starting with the `p_` prefix are
+ * direct ports of the standard POSIX methods.
+ *
+ * Some of the methods are slightly wrapped to provide
+ * saner defaults. Some of these methods are emulated
+ * in Windows platforns.
+ *
+ * Use your manpages to check the docs on these.
+ * Straightforward
+ */
+extern int p_open(const char *path, int flags);
+extern int p_creat(const char *path, int mode);
+extern int p_read(git_file fd, void *buf, size_t cnt);
+extern int p_write(git_file fd, void *buf, size_t cnt);
+extern int p_getcwd(char *buffer_out, size_t size);
+
+#define p_lseek(f,n,w) lseek(f, n, w)
+#define p_stat(p,b) stat(p, b)
+#define p_fstat(f,b) fstat(f, b)
+#define p_chdir(p) chdir(p)
+#define p_rmdir(p) rmdir(p)
+#define p_chmod(p,m) chmod(p, m)
+#define p_close(fd) close(fd)
+
+#endif
diff --git a/src/refs.c b/src/refs.c
index ad81bb3..eea96ad 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -59,11 +59,11 @@ static uint32_t reftable_hash(const void *key, int hash_id)
static void reference_free(git_reference *reference);
static int reference_create(git_reference **ref_out, git_repository *repo, const char *name, git_rtype type);
-static int reference_read(gitfo_buf *file_content, time_t *mtime, const char *repo_path, const char *ref_name);
+static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *repo_path, const char *ref_name);
/* loose refs */
-static int loose_parse_symbolic(git_reference *ref, gitfo_buf *file_content);
-static int loose_parse_oid(git_reference *ref, gitfo_buf *file_content);
+static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content);
+static int loose_parse_oid(git_reference *ref, git_fbuffer *file_content);
static int loose_lookup(git_reference **ref_out, git_repository *repo, const char *name, int skip_symbolic);
static int loose_write(git_reference *ref);
static int loose_update(git_reference *ref);
@@ -150,15 +150,15 @@ cleanup:
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create reference");
}
-static int reference_read(gitfo_buf *file_content, time_t *mtime, const char *repo_path, const char *ref_name)
+static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *repo_path, const char *ref_name)
{
struct stat st;
char path[GIT_PATH_MAX];
/* Determine the full path of the file */
- git__joinpath(path, repo_path, ref_name);
+ git_path_join(path, repo_path, ref_name);
- if (gitfo_stat(path, &st) < 0 || S_ISDIR(st.st_mode))
+ if (p_stat(path, &st) < 0 || S_ISDIR(st.st_mode))
return git__throw(GIT_ENOTFOUND,
"Cannot read reference file '%s'", ref_name);
@@ -166,7 +166,7 @@ static int reference_read(gitfo_buf *file_content, time_t *mtime, const char *re
*mtime = st.st_mtime;
if (file_content)
- return gitfo_read_file(file_content, path);
+ return git_futils_readbuffer(file_content, path);
return GIT_SUCCESS;
}
@@ -181,7 +181,7 @@ static int loose_update(git_reference *ref)
{
int error;
time_t ref_time;
- gitfo_buf ref_file = GITFO_BUF_INIT;
+ git_fbuffer ref_file = GIT_FBUFFER_INIT;
if (ref->type & GIT_REF_PACKED)
return packed_load(ref->owner);
@@ -205,7 +205,7 @@ static int loose_update(git_reference *ref)
error = git__throw(GIT_EOBJCORRUPTED,
"Invalid reference type (%d) for loose reference", ref->type);
- gitfo_free_buf(&ref_file);
+ git_futils_freebuffer(&ref_file);
cleanup:
if (error != GIT_SUCCESS) {
@@ -216,7 +216,7 @@ cleanup:
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to update loose reference");
}
-static int loose_parse_symbolic(git_reference *ref, gitfo_buf *file_content)
+static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content)
{
const unsigned int header_len = strlen(GIT_SYMREF);
const char *refname_start;
@@ -255,7 +255,7 @@ static int loose_parse_symbolic(git_reference *ref, gitfo_buf *file_content)
return GIT_SUCCESS;
}
-static int loose_parse_oid(git_reference *ref, gitfo_buf *file_content)
+static int loose_parse_oid(git_reference *ref, git_fbuffer *file_content)
{
int error;
reference_oid *ref_oid;
@@ -286,19 +286,19 @@ static int loose_parse_oid(git_reference *ref, gitfo_buf *file_content)
static git_rtype loose_guess_rtype(const char *full_path)
{
- gitfo_buf ref_file = GITFO_BUF_INIT;
+ git_fbuffer ref_file = GIT_FBUFFER_INIT;
git_rtype type;
type = GIT_REF_INVALID;
- if (gitfo_read_file(&ref_file, full_path) == GIT_SUCCESS) {
+ if (git_futils_readbuffer(&ref_file, full_path) == GIT_SUCCESS) {
if (git__prefixcmp((const char *)(ref_file.data), GIT_SYMREF) == 0)
type = GIT_REF_SYMBOLIC;
else
type = GIT_REF_OID;
}
- gitfo_free_buf(&ref_file);
+ git_futils_freebuffer(&ref_file);
return type;
}
@@ -309,7 +309,7 @@ static int loose_lookup(
int skip_symbolic)
{
int error = GIT_SUCCESS;
- gitfo_buf ref_file = GITFO_BUF_INIT;
+ git_fbuffer ref_file = GIT_FBUFFER_INIT;
git_reference *ref = NULL;
time_t ref_time;
@@ -341,11 +341,11 @@ static int loose_lookup(
ref->mtime = ref_time;
*ref_out = ref;
- gitfo_free_buf(&ref_file);
+ git_futils_freebuffer(&ref_file);
return GIT_SUCCESS;
cleanup:
- gitfo_free_buf(&ref_file);
+ git_futils_freebuffer(&ref_file);
reference_free(ref);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to lookup loose reference");
}
@@ -357,7 +357,7 @@ static int loose_write(git_reference *ref)
int error;
struct stat st;
- git__joinpath(ref_path, ref->owner->path_repository, ref->name);
+ git_path_join(ref_path, ref->owner->path_repository, ref->name);
if ((error = git_filebuf_open(&file, ref_path, GIT_FILEBUF_FORCE)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write loose reference");
@@ -384,7 +384,7 @@ static int loose_write(git_reference *ref)
error = git_filebuf_commit(&file);
- if (gitfo_stat(ref_path, &st) == GIT_SUCCESS)
+ if (p_stat(ref_path, &st) == GIT_SUCCESS)
ref->mtime = st.st_mtime;
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write loose reference");
@@ -501,7 +501,7 @@ cleanup:
static int packed_load(git_repository *repo)
{
int error = GIT_SUCCESS;
- gitfo_buf packfile = GITFO_BUF_INIT;
+ git_fbuffer packfile = GIT_FBUFFER_INIT;
const char *buffer_start, *buffer_end;
git_refcache *ref_cache = &repo->references;
@@ -580,13 +580,13 @@ static int packed_load(git_repository *repo)
}
}
- gitfo_free_buf(&packfile);
+ git_futils_freebuffer(&packfile);
return GIT_SUCCESS;
cleanup:
git_hashtable_free(ref_cache->packfile);
ref_cache->packfile = NULL;
- gitfo_free_buf(&packfile);
+ git_futils_freebuffer(&packfile);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to load packed references");
}
@@ -607,8 +607,8 @@ static int _dirent_loose_listall(void *_data, char *full_path)
struct dirent_list_data *data = (struct dirent_list_data *)_data;
char *file_path = full_path + data->repo_path_len;
- if (gitfo_isdir(full_path) == GIT_SUCCESS)
- return gitfo_dirent(full_path, GIT_PATH_MAX, _dirent_loose_listall, _data);
+ if (git_futils_isdir(full_path) == GIT_SUCCESS)
+ return git_futils_direach(full_path, GIT_PATH_MAX, _dirent_loose_listall, _data);
/* do not add twice a reference that exists already in the packfile */
if ((data->list_flags & GIT_REF_PACKED) != 0 &&
@@ -630,8 +630,8 @@ static int _dirent_loose_load(void *data, char *full_path)
char *file_path;
int error;
- if (gitfo_isdir(full_path) == GIT_SUCCESS)
- return gitfo_dirent(full_path, GIT_PATH_MAX, _dirent_loose_load, repository);
+ if (git_futils_isdir(full_path) == GIT_SUCCESS)
+ return git_futils_direach(full_path, GIT_PATH_MAX, _dirent_loose_load, repository);
file_path = full_path + strlen(repository->path_repository);
error = loose_lookup(&reference, repository, file_path, 1);
@@ -663,7 +663,7 @@ static int packed_loadloose(git_repository *repository)
/* the packfile must have been previously loaded! */
assert(repository->references.packfile);
- git__joinpath(refs_path, repository->path_repository, GIT_REFS_DIR);
+ git_path_join(refs_path, repository->path_repository, GIT_REFS_DIR);
/* Remove any loose references from the cache */
{
@@ -682,7 +682,7 @@ static int packed_loadloose(git_repository *repository)
* This will overwrite any old packed entries with their
* updated loose versions
*/
- return gitfo_dirent(refs_path, GIT_PATH_MAX, _dirent_loose_load, repository);
+ return git_futils_direach(refs_path, GIT_PATH_MAX, _dirent_loose_load, repository);
}
/*
@@ -803,10 +803,10 @@ static int packed_remove_loose(git_repository *repo, git_vector *packing_list)
if (reference != NULL)
continue;
- git__joinpath(full_path, repo->path_repository, ref->name);
+ git_path_join(full_path, repo->path_repository, ref->name);
- if (gitfo_exists(full_path) == GIT_SUCCESS &&
- gitfo_unlink(full_path) < GIT_SUCCESS)
+ if (git_futils_exists(full_path) == GIT_SUCCESS &&
+ p_unlink(full_path) < GIT_SUCCESS)
error = GIT_EOSERR;
/*
@@ -864,7 +864,7 @@ static int packed_write(git_repository *repo)
git_vector_sort(&packing_list);
/* Now we can open the file! */
- git__joinpath(pack_file_path, repo->path_repository, GIT_PACKEDREFS_FILE);
+ git_path_join(pack_file_path, repo->path_repository, GIT_PACKEDREFS_FILE);
if ((error = git_filebuf_open(&pack_file, pack_file_path, 0)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write packed reference");
@@ -904,7 +904,7 @@ cleanup:
error = packed_remove_loose(repo, &packing_list);
- if (gitfo_stat(pack_file_path, &st) == GIT_SUCCESS)
+ if (p_stat(pack_file_path, &st) == GIT_SUCCESS)
repo->references.packfile_time = st.st_mtime;
}
}
@@ -1367,10 +1367,10 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
goto rename_loose_to_old_name;
} else {
- git__joinpath(old_path, ref->owner->path_repository, old_name);
- git__joinpath(new_path, ref->owner->path_repository, ref->name);
+ git_path_join(old_path, ref->owner->path_repository, old_name);
+ git_path_join(new_path, ref->owner->path_repository, ref->name);
- error = gitfo_mv_force(old_path, new_path);
+ error = git_futils_mv_withpath(old_path, new_path);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -1405,11 +1405,11 @@ rename_loose_to_old_name:
* for good. :-/
*/
- git__joinpath(old_path, ref->owner->path_repository, ref->name);
- git__joinpath(new_path, ref->owner->path_repository, old_name);
+ git_path_join(old_path, ref->owner->path_repository, ref->name);
+ git_path_join(new_path, ref->owner->path_repository, old_name);
/* No error checking. We'll return the initial error */
- gitfo_mv_force(old_path, new_path);
+ git_futils_mv_withpath(old_path, new_path);
/* restore the old name */
free(ref->name);
@@ -1452,9 +1452,9 @@ int git_reference_delete(git_reference *ref)
error = packed_write(ref->owner);
} else {
char full_path[GIT_PATH_MAX];
- git__joinpath(full_path, ref->owner->path_repository, ref->name);
+ git_path_join(full_path, ref->owner->path_repository, ref->name);
git_hashtable_remove(ref->owner->references.loose_cache, ref->name);
- error = gitfo_unlink(full_path);
+ error = p_unlink(full_path);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -1547,8 +1547,8 @@ int git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*c
data.callback_payload = payload;
- git__joinpath(refs_path, repo->path_repository, GIT_REFS_DIR);
- return gitfo_dirent(refs_path, GIT_PATH_MAX, _dirent_loose_listall, &data);
+ git_path_join(refs_path, repo->path_repository, GIT_REFS_DIR);
+ return git_futils_direach(refs_path, GIT_PATH_MAX, _dirent_loose_listall, &data);
}
int cb__reflist_add(const char *ref, void *data)
diff --git a/src/repository.c b/src/repository.c
index 8ebfd67..a8ead3a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -68,7 +68,7 @@ static int assign_repository_dirs(
if (git_dir == NULL)
return git__throw(GIT_ENOTFOUND, "Failed to open repository. Git dir not found");
- error = gitfo_prettify_dir_path(path_aux, sizeof(path_aux), git_dir, NULL);
+ error = git_futils_prettify_dir(path_aux, sizeof(path_aux), git_dir, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to open repository");
@@ -79,9 +79,9 @@ static int assign_repository_dirs(
/* path to GIT_OBJECT_DIRECTORY */
if (git_object_directory == NULL)
- git__joinpath(path_aux, repo->path_repository, GIT_OBJECTS_DIR);
+ git_path_join(path_aux, repo->path_repository, GIT_OBJECTS_DIR);
else {
- error = gitfo_prettify_dir_path(path_aux, sizeof(path_aux), git_object_directory, NULL);
+ error = git_futils_prettify_dir(path_aux, sizeof(path_aux), git_object_directory, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to open repository");
}
@@ -95,7 +95,7 @@ static int assign_repository_dirs(
if (git_work_tree == NULL)
repo->is_bare = 1;
else {
- error = gitfo_prettify_dir_path(path_aux, sizeof(path_aux), git_work_tree, NULL);
+ error = git_futils_prettify_dir(path_aux, sizeof(path_aux), git_work_tree, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to open repository");
@@ -106,9 +106,9 @@ static int assign_repository_dirs(
/* Path to GIT_INDEX_FILE */
if (git_index_file == NULL)
- git__joinpath(path_aux, repo->path_repository, GIT_INDEX_FILE);
+ git_path_join(path_aux, repo->path_repository, GIT_INDEX_FILE);
else {
- error = gitfo_prettify_file_path(path_aux, sizeof(path_aux), git_index_file, NULL);
+ error = git_futils_prettyify_file(path_aux, sizeof(path_aux), git_index_file, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to open repository");
}
@@ -126,16 +126,16 @@ static int check_repository_dirs(git_repository *repo)
{
char path_aux[GIT_PATH_MAX];
- if (gitfo_isdir(repo->path_repository) < GIT_SUCCESS)
+ if (git_futils_isdir(repo->path_repository) < GIT_SUCCESS)
return git__throw(GIT_ENOTAREPO, "`%s` is not a folder", repo->path_repository);
/* Ensure GIT_OBJECT_DIRECTORY exists */
- if (gitfo_isdir(repo->path_odb) < GIT_SUCCESS)
+ if (git_futils_isdir(repo->path_odb) < GIT_SUCCESS)
return git__throw(GIT_ENOTAREPO, "`%s` does not exist", repo->path_odb);
/* Ensure HEAD file exists */
- git__joinpath(path_aux, repo->path_repository, GIT_HEAD_FILE);
- if (gitfo_exists(path_aux) < 0)
+ git_path_join(path_aux, repo->path_repository, GIT_HEAD_FILE);
+ if (git_futils_exists(path_aux) < 0)
return git__throw(GIT_ENOTAREPO, "HEAD file is missing");
return GIT_SUCCESS;
@@ -147,12 +147,12 @@ static int guess_repository_dirs(git_repository *repo, const char *repository_pa
const char *path_work_tree = NULL;
/* Git directory name */
- if (git__basename_r(buffer, sizeof(buffer), repository_path) < 0)
+ if (git_path_basename_r(buffer, sizeof(buffer), repository_path) < 0)
return git__throw(GIT_EINVALIDPATH, "Unable to parse folder name from `%s`", repository_path);
if (strcmp(buffer, DOT_GIT) == 0) {
/* Path to working dir */
- if (git__dirname_r(buffer, sizeof(buffer), repository_path) < 0)
+ if (git_path_dirname_r(buffer, sizeof(buffer), repository_path) < 0)
return git__throw(GIT_EINVALIDPATH, "Unable to parse parent folder name from `%s`", repository_path);
path_work_tree = buffer;
}
@@ -286,7 +286,7 @@ int git_repository_config(
if (error < GIT_SUCCESS)
return error;
- git__joinpath(config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO);
+ git_path_join(config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO);
error = git_config_add_file_ondisk(*out, config_path, 3);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -364,7 +364,7 @@ static int abspath(char *buffer_out, size_t size, const char *path)
return git__throw(GIT_EOSERR, "Failed to retrieve real path: %s causing errors", buffer_out);
#endif
- gitfo_posixify_path(buffer_out);
+ git_path_mkposix(buffer_out);
return GIT_SUCCESS;
}
@@ -375,7 +375,7 @@ static int retrieve_device(dev_t *device_out, const char *path)
assert(device_out);
- if (gitfo_stat(path, &path_info))
+ if (p_stat(path, &path_info))
return git__throw(GIT_EOSERR, "Failed to get file informations: %s", path);
*device_out = path_info.st_dev;
@@ -393,7 +393,7 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
assert(path);
- min_len = gitfo_retrieve_path_root_offset(path) + 1;
+ min_len = git_futils_root_offset(path) + 1;
if (ceiling_directories == NULL || min_len == 0)
return min_len;
@@ -402,7 +402,7 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
len = sep - ceil;
- if (len == 0 || len > GIT_PATH_MAX || gitfo_retrieve_path_root_offset(ceil) == -1)
+ if (len == 0 || len > GIT_PATH_MAX || git_futils_root_offset(ceil) == -1)
continue;
strncpy(buf, ceil, len);
@@ -428,13 +428,13 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
static int read_gitfile(char *path_out, size_t size, const char *file_path, const char *base_path)
{
- gitfo_buf file;
+ git_fbuffer file;
int error, end_offset;
char *data;
assert(file_path && path_out && size > 0);
- error = gitfo_read_file(&file, file_path);
+ error = git_futils_readbuffer(&file, file_path);
if (error < GIT_SUCCESS)
return error;
@@ -442,7 +442,7 @@ static int read_gitfile(char *path_out, size_t size, const char *file_path, cons
data = (char*)(file.data);
if (git__prefixcmp(data, GIT_FILE_CONTENT_PREFIX)) {
- gitfo_free_buf(&file);
+ git_futils_freebuffer(&file);
return git__throw(GIT_ENOTFOUND, "Invalid gitfile format `%s`", file_path);
}
@@ -452,11 +452,11 @@ static int read_gitfile(char *path_out, size_t size, const char *file_path, cons
data[end_offset + 1] = '\0';
if (GIT_FILE_CONTENT_PREFIX_LENGTH == end_offset + 1) {
- gitfo_free_buf(&file);
+ git_futils_freebuffer(&file);
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
}
- error = gitfo_prettify_dir_path(path_out, size, data + GIT_FILE_CONTENT_PREFIX_LENGTH, base_path);
+ error = git_futils_prettify_dir(path_out, size, data + GIT_FILE_CONTENT_PREFIX_LENGTH, base_path);
if (error == GIT_SUCCESS) {
end_offset = strlen(path_out);
@@ -464,7 +464,7 @@ static int read_gitfile(char *path_out, size_t size, const char *file_path, cons
path_out[end_offset - 1 ] = '\0';
}
- gitfo_free_buf(&file);
+ git_futils_freebuffer(&file);
return error;
}
@@ -521,11 +521,11 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
}
ceiling_offset = retrieve_ceiling_directories_offset(bare_path, ceiling_dirs);
- git__joinpath(normal_path, bare_path, DOT_GIT);
+ git_path_join(normal_path, bare_path, DOT_GIT);
while(1){
//look for .git file
- if (gitfo_isfile(normal_path) == GIT_SUCCESS) {
+ if (git_futils_isfile(normal_path) == GIT_SUCCESS) {
error = read_gitfile(repository_path, size, normal_path, bare_path);
if (error < GIT_SUCCESS) {
@@ -566,7 +566,7 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
git_repository__free_dirs(&repo);
- if (git__dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS)
+ if (git_path_dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS)
goto cleanup;
if (!across_fs) {
@@ -585,7 +585,7 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
}
strcpy(bare_path, normal_path);
- git__joinpath(normal_path, bare_path, DOT_GIT);
+ git_path_join(normal_path, bare_path, DOT_GIT);
//nothing has been found, lets try the parent directory
if (bare_path[ceiling_offset] == '\0') {
@@ -633,8 +633,8 @@ static int repo_init_check_head_existence(char * repository_path)
{
char temp_path[GIT_PATH_MAX];
- git__joinpath(temp_path, repository_path, GIT_HEAD_FILE);
- return gitfo_exists(temp_path);
+ git_path_join(temp_path, repository_path, GIT_HEAD_FILE);
+ return git_futils_exists(temp_path);
}
static int repo_init_structure(repo_init *results)
@@ -645,39 +645,39 @@ static int repo_init_structure(repo_init *results)
char temp_path[GIT_PATH_MAX];
char *git_dir = results->path_repository;
- if (gitfo_mkdir_recurs(git_dir, mode))
+ if (git_futils_mkdir_r(git_dir, mode))
return git__throw(GIT_ERROR, "Failed to initialize repository structure. Could not mkdir");
#ifdef GIT_WIN32
/* Hides the ".git" directory */
if (!results->is_bare) {
- error = gitfo_hide_directory__w32(git_dir);
+ error = p_hide_directory__w32(git_dir);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to initialize repository structure");
}
#endif
/* Creates the '/objects/info/' directory */
- git__joinpath(temp_path, git_dir, GIT_OBJECTS_INFO_DIR);
- error = gitfo_mkdir_recurs(temp_path, mode);
+ git_path_join(temp_path, git_dir, GIT_OBJECTS_INFO_DIR);
+ error = git_futils_mkdir_r(temp_path, mode);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to initialize repository structure");
/* Creates the '/objects/pack/' directory */
- git__joinpath(temp_path, git_dir, GIT_OBJECTS_PACK_DIR);
- error = gitfo_mkdir(temp_path, mode);
+ git_path_join(temp_path, git_dir, GIT_OBJECTS_PACK_DIR);
+ error = p_mkdir(temp_path, mode);
if (error < GIT_SUCCESS)
return git__throw(error, "Unable to create `%s` folder", temp_path);
/* Creates the '/refs/heads/' directory */
- git__joinpath(temp_path, git_dir, GIT_REFS_HEADS_DIR);
- error = gitfo_mkdir_recurs(temp_path, mode);
+ git_path_join(temp_path, git_dir, GIT_REFS_HEADS_DIR);
+ error = git_futils_mkdir_r(temp_path, mode);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to initialize repository structure");
/* Creates the '/refs/tags/' directory */
- git__joinpath(temp_path, git_dir, GIT_REFS_TAGS_DIR);
- error = gitfo_mkdir(temp_path, mode);
+ git_path_join(temp_path, git_dir, GIT_REFS_TAGS_DIR);
+ error = p_mkdir(temp_path, mode);
if (error < GIT_SUCCESS)
return git__throw(error, "Unable to create `%s` folder", temp_path);
@@ -691,12 +691,12 @@ static int repo_init_find_dir(repo_init *results, const char* path)
char temp_path[GIT_PATH_MAX];
int error = GIT_SUCCESS;
- error = gitfo_prettify_dir_path(temp_path, sizeof(temp_path), path, NULL);
+ error = git_futils_prettify_dir(temp_path, sizeof(temp_path), path, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to find directory to initialize repository");
if (!results->is_bare) {
- git__joinpath(temp_path, temp_path, GIT_DIR);
+ git_path_join(temp_path, temp_path, GIT_DIR);
}
results->path_repository = git__strdup(temp_path);
diff --git a/src/tag.c b/src/tag.c
index 53e28f5..de70c50 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -170,7 +170,7 @@ static int retreive_tag_reference(git_reference **tag_reference_out, char *ref_n
git_reference *tag_ref;
int error;
- git__joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name);
+ git_path_join(ref_name_out, GIT_REFS_TAGS_DIR, tag_name);
error = git_reference_lookup(&tag_ref, repo, ref_name_out);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to retrieve tag reference");
diff --git a/src/tree.c b/src/tree.c
index 6a21709..51b19f5 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -56,7 +56,7 @@ int entry_sort_cmp(const void *a, const void *b)
const git_tree_entry *entry_a = *(const git_tree_entry **)(a);
const git_tree_entry *entry_b = *(const git_tree_entry **)(b);
- return gitfo_cmp_path(entry_a->filename, strlen(entry_a->filename),
+ return git_futils_cmp_path(entry_a->filename, strlen(entry_a->filename),
entry_a->attr & 040000,
entry_b->filename, strlen(entry_b->filename),
entry_b->attr & 040000);
diff --git a/src/unix/map.c b/src/unix/map.c
index 1f50bcf..5192c8e 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -6,7 +6,7 @@
#include <sys/mman.h>
#include <errno.h>
-int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
{
int mprot = 0;
int mflag = 0;
@@ -48,7 +48,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o
return GIT_SUCCESS;
}
-int git__munmap(git_map *map)
+int p_munmap(git_map *map)
{
assert(map != NULL);
diff --git a/src/unix/posix.h b/src/unix/posix.h
new file mode 100644
index 0000000..ab98c45
--- /dev/null
+++ b/src/unix/posix.h
@@ -0,0 +1,14 @@
+#ifndef INCLUDE_posix__w32_h__
+#define INCLUDE_posix__w32_h__
+
+#include "common.h"
+
+#define p_lstat(p,b) lstat(p,b)
+#define p_readlink(a, b, c) readlink(a, b, c)
+#define p_link(o,n) link(o, n)
+#define p_unlink(p) unlink(p)
+#define p_mkdir(p,m) mkdir(p, m)
+#define p_fsync(fd) fsync(fd)
+#define p_realpath(p, r) realpath(p, r)
+
+#endif
diff --git a/src/util.c b/src/util.c
index b654e08..7dc8d3b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,3 @@
-#define GIT__NO_HIDE_MALLOC
#include <git2.h>
#include "common.h"
#include <stdarg.h>
@@ -146,205 +145,6 @@ int git__suffixcmp(const char *str, const char *suffix)
return strcmp(str + (a - b), suffix);
}
-/*
- * Based on the Android implementation, BSD licensed.
- * Check http://android.git.kernel.org/
- */
-int git__basename_r(char *buffer, size_t bufflen, const char *path)
-{
- const char *endp, *startp;
- int len, result;
-
- /* Empty or NULL string gets treated as "." */
- if (path == NULL || *path == '\0') {
- startp = ".";
- len = 1;
- goto Exit;
- }
-
- /* Strip trailing slashes */
- endp = path + strlen(path) - 1;
- while (endp > path && *endp == '/')
- endp--;
-
- /* All slashes becomes "/" */
- if (endp == path && *endp == '/') {
- startp = "/";
- len = 1;
- goto Exit;
- }
-
- /* Find the start of the base */
- startp = endp;
- while (startp > path && *(startp - 1) != '/')
- startp--;
-
- len = endp - startp +1;
-
-Exit:
- result = len;
- if (buffer == NULL) {
- return result;
- }
- if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
- result = GIT_ENOMEM;
- }
-
- if (len >= 0) {
- memmove(buffer, startp, len);
- buffer[len] = 0;
- }
- return result;
-}
-
-/*
- * Based on the Android implementation, BSD licensed.
- * Check http://android.git.kernel.org/
- */
-int git__dirname_r(char *buffer, size_t bufflen, const char *path)
-{
- const char *endp;
- int result, len;
-
- /* Empty or NULL string gets treated as "." */
- if (path == NULL || *path == '\0') {
- path = ".";
- len = 1;
- goto Exit;
- }
-
- /* Strip trailing slashes */
- endp = path + strlen(path) - 1;
- while (endp > path && *endp == '/')
- endp--;
-
- /* Find the start of the dir */
- while (endp > path && *endp != '/')
- endp--;
-
- /* Either the dir is "/" or there are no slashes */
- if (endp == path) {
- path = (*endp == '/') ? "/" : ".";
- len = 1;
- goto Exit;
- }
-
- do {
- endp--;
- } while (endp > path && *endp == '/');
-
- len = endp - path +1;
-
-Exit:
- result = len;
- if (len+1 > GIT_PATH_MAX) {
- return GIT_ENOMEM;
- }
- if (buffer == NULL)
- return result;
-
- if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
- result = GIT_ENOMEM;
- }
-
- if (len >= 0) {
- memmove(buffer, path, len);
- buffer[len] = 0;
- }
- return result;
-}
-
-
-char *git__dirname(const char *path)
-{
- char *dname = NULL;
- int len;
-
- len = (path ? strlen(path) : 0) + 2;
- dname = (char *)git__malloc(len);
- if (dname == NULL)
- return NULL;
-
- if (git__dirname_r(dname, len, path) < GIT_SUCCESS) {
- free(dname);
- return NULL;
- }
-
- return dname;
-}
-
-char *git__basename(const char *path)
-{
- char *bname = NULL;
- int len;
-
- len = (path ? strlen(path) : 0) + 2;
- bname = (char *)git__malloc(len);
- if (bname == NULL)
- return NULL;
-
- if (git__basename_r(bname, len, path) < GIT_SUCCESS) {
- free(bname);
- return NULL;
- }
-
- return bname;
-}
-
-
-const char *git__topdir(const char *path)
-{
- size_t len;
- int i;
-
- assert(path);
- len = strlen(path);
-
- if (!len || path[len - 1] != '/')
- return NULL;
-
- for (i = len - 2; i >= 0; --i)
- if (path[i] == '/')
- break;
-
- return &path[i + 1];
-}
-
-void git__joinpath_n(char *buffer_out, int count, ...)
-{
- va_list ap;
- int i;
- char *buffer_start = buffer_out;
-
- va_start(ap, count);
- for (i = 0; i < count; ++i) {
- const char *path;
- int len;
-
- path = va_arg(ap, const char *);
-
- assert((i == 0) || path != buffer_start);
-
- if (i > 0 && *path == '/' && buffer_out > buffer_start && buffer_out[-1] == '/')
- path++;
-
- if (!*path)
- continue;
-
- len = strlen(path);
- memmove(buffer_out, path, len);
- buffer_out = buffer_out + len;
-
- if (i < count - 1 && buffer_out[-1] != '/')
- *buffer_out++ = '/';
- }
- va_end(ap);
-
- *buffer_out = '\0';
-}
-
char *git__strtok(char **end, const char *sep)
{
char *ptr = *end;
diff --git a/src/util.h b/src/util.h
index 999c3b8..eac6151 100644
--- a/src/util.h
+++ b/src/util.h
@@ -68,63 +68,9 @@ extern int git__suffixcmp(const char *str, const char *suffix);
extern int git__strtol32(long *n, const char *buff, const char **end_buf, int base);
-/*
- * The dirname() function shall take a pointer to a character string
- * that contains a pathname, and return a pointer to a string that is a
- * pathname of the parent directory of that file. Trailing '/' characters
- * in the path are not counted as part of the path.
- *
- * If path does not contain a '/', then dirname() shall return a pointer to
- * the string ".". If path is a null pointer or points to an empty string,
- * dirname() shall return a pointer to the string "." .
- *
- * The `git__dirname` implementation is thread safe. The returned
- * string must be manually free'd.
- *
- * The `git__dirname_r` implementation expects a string allocated
- * by the user with big enough size.
- */
-extern char *git__dirname(const char *path);
-extern int git__dirname_r(char *buffer, size_t bufflen, const char *path);
-
-/*
- * This function returns the basename of the file, which is the last
- * part of its full name given by fname, with the drive letter and
- * leading directories stripped off. For example, the basename of
- * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
- *
- * Trailing slashes and backslashes are significant: the basename of
- * c:/foo/bar/ is an empty string after the rightmost slash.
- *
- * The `git__basename` implementation is thread safe. The returned
- * string must be manually free'd.
- *
- * The `git__basename_r` implementation expects a string allocated
- * by the user with big enough size.
- */
-extern char *git__basename(const char *path);
-extern int git__basename_r(char *buffer, size_t bufflen, const char *path);
-
-extern const char *git__topdir(const char *path);
-
-/**
- * Join two paths together. Takes care of properly fixing the
- * middle slashes and everything
- *
- * The paths are joined together into buffer_out; this is expected
- * to be an user allocated buffer of `GIT_PATH_MAX` size
- */
-extern void git__joinpath_n(char *buffer_out, int npath, ...);
-
-GIT_INLINE(void) git__joinpath(char *buffer_out, const char *path_a, const char *path_b)
-{
- git__joinpath_n(buffer_out, 2, path_a, path_b);
-}
-
extern void git__hexdump(const char *buffer, size_t n);
extern uint32_t git__hash(const void *key, int len, uint32_t seed);
-
/** @return true if p fits into the range of a size_t */
GIT_INLINE(int) git__is_sizet(git_off_t p)
{
diff --git a/src/win32/fileops.c b/src/win32/fileops.c
deleted file mode 100644
index d435e70..0000000
--- a/src/win32/fileops.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#define GIT__WIN32_NO_HIDE_FILEOPS
-#include "fileops.h"
-#include <errno.h>
-
-int git__unlink(const char *path)
-{
- chmod(path, 0666);
- return unlink(path);
-}
-
-int git__mkstemp(char *template)
-{
- char *file = mktemp(template);
- if (file == NULL)
- return -1;
- return open(file, O_RDWR | O_CREAT | O_BINARY, 0600);
-}
-
-int git__fsync(int fd)
-{
- HANDLE fh = (HANDLE)_get_osfhandle(fd);
-
- if (fh == INVALID_HANDLE_VALUE) {
- errno = EBADF;
- return -1;
- }
-
- if (!FlushFileBuffers(fh)) {
- DWORD code = GetLastError();
-
- if (code == ERROR_INVALID_HANDLE)
- errno = EINVAL;
- else
- errno = EIO;
-
- return -1;
- }
-
- return 0;
-}
-
diff --git a/src/win32/map.c b/src/win32/map.c
index c7a39fc..76b9264 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -16,7 +16,7 @@ static DWORD get_page_size(void)
return page_size;
}
-int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
DWORD page_size = get_page_size();
@@ -92,7 +92,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o
return GIT_SUCCESS;
}
-int git__munmap(git_map *map)
+int p_munmap(git_map *map)
{
assert(map != NULL);
diff --git a/src/win32/posix.c b/src/win32/posix.c
new file mode 100644
index 0000000..003ce1f
--- /dev/null
+++ b/src/win32/posix.c
@@ -0,0 +1,191 @@
+#include "posix.h"
+#include <errno.h>
+
+int p_unlink(const char *path)
+{
+ chmod(path, 0666);
+ return unlink(path);
+}
+
+int p_fsync(int fd)
+{
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+
+ if (fh == INVALID_HANDLE_VALUE) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (!FlushFileBuffers(fh)) {
+ DWORD code = GetLastError();
+
+ if (code == ERROR_INVALID_HANDLE)
+ errno = EINVAL;
+ else
+ errno = EIO;
+
+ return -1;
+ }
+
+ return 0;
+}
+
+GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft)
+{
+ long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
+ winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
+ winTime /= 10000000; /* Nano to seconds resolution */
+ return (time_t)winTime;
+}
+
+static int do_lstat(const char *file_name, struct stat *buf)
+{
+ WIN32_FILE_ATTRIBUTE_DATA fdata;
+
+ if (GetFileAttributesExA(file_name, GetFileExInfoStandard, &fdata)) {
+ int fMode = S_IREAD;
+
+ if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ fMode |= S_IFDIR;
+ else
+ fMode |= S_IFREG;
+
+ if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
+ fMode |= S_IWRITE;
+
+ if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
+ fMode |= S_IFLNK;
+
+ buf->st_ino = 0;
+ buf->st_gid = 0;
+ buf->st_uid = 0;
+ buf->st_nlink = 1;
+ buf->st_mode = (mode_t)fMode;
+ buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
+ buf->st_dev = buf->st_rdev = (_getdrive() - 1);
+ buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
+ buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
+ buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
+ return GIT_SUCCESS;
+ }
+
+ switch (GetLastError()) {
+ case ERROR_ACCESS_DENIED:
+ case ERROR_SHARING_VIOLATION:
+ case ERROR_LOCK_VIOLATION:
+ case ERROR_SHARING_BUFFER_EXCEEDED:
+ return GIT_EOSERR;
+
+ case ERROR_BUFFER_OVERFLOW:
+ case ERROR_NOT_ENOUGH_MEMORY:
+ return GIT_ENOMEM;
+
+ default:
+ return GIT_EINVALIDPATH;
+ }
+}
+
+int p_lstat(const char *file_name, struct stat *buf)
+{
+ int namelen, error;
+ char alt_name[GIT_PATH_MAX];
+
+ if ((error = do_lstat(file_name, buf)) == GIT_SUCCESS)
+ return GIT_SUCCESS;
+
+ /* if file_name ended in a '/', Windows returned ENOENT;
+ * try again without trailing slashes
+ */
+ if (error != GIT_EINVALIDPATH)
+ return git__throw(GIT_EOSERR, "Failed to lstat file");
+
+ namelen = strlen(file_name);
+ if (namelen && file_name[namelen-1] != '/')
+ return git__throw(GIT_EOSERR, "Failed to lstat file");
+
+ while (namelen && file_name[namelen-1] == '/')
+ --namelen;
+
+ if (!namelen || namelen >= GIT_PATH_MAX)
+ return git__throw(GIT_ENOMEM, "Failed to lstat file");
+
+ memcpy(alt_name, file_name, namelen);
+ alt_name[namelen] = 0;
+ return do_lstat(alt_name, buf);
+}
+
+int p_readlink(const char *link, char *target, size_t target_len)
+{
+ typedef DWORD (WINAPI *fpath_func)(HANDLE, LPTSTR, DWORD, DWORD);
+ static fpath_func pGetFinalPath = NULL;
+ HANDLE hFile;
+ DWORD dwRet;
+
+ /*
+ * Try to load the pointer to pGetFinalPath dynamically, because
+ * it is not available in platforms older than Vista
+ */
+ if (pGetFinalPath == NULL) {
+ HINSTANCE library = LoadLibrary("kernel32");
+
+ if (library != NULL)
+ pGetFinalPath = (fpath_func)GetProcAddress(library, "GetFinalPathNameByHandleA");
+
+ if (pGetFinalPath == NULL)
+ return git__throw(GIT_EOSERR,
+ "'GetFinalPathNameByHandleA' is not available in this platform");
+ }
+
+ hFile = CreateFile(link, // file to open
+ GENERIC_READ, // open for reading
+ FILE_SHARE_READ, // share for reading
+ NULL, // default security
+ OPEN_EXISTING, // existing file only
+ FILE_FLAG_BACKUP_SEMANTICS, // normal file
+ NULL); // no attr. template
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ return GIT_EOSERR;
+
+ dwRet = pGetFinalPath(hFile, target, target_len, 0x0);
+ if (dwRet >= target_len)
+ return GIT_ENOMEM;
+
+ CloseHandle(hFile);
+
+ if (dwRet > 4) {
+ /* Skip first 4 characters if they are "\\?\" */
+ if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
+ char tmp[GIT_PATH_MAX];
+ unsigned int offset = 4;
+ dwRet -= 4;
+
+ /* \??\UNC\ */
+ if (dwRet > 7 && target[4] == 'U' && target[5] == 'N' && target[6] == 'C') {
+ offset += 2;
+ dwRet -= 2;
+ target[offset] = '\\';
+ }
+
+ memcpy(tmp, target + offset, dwRet);
+ memcpy(target, tmp, dwRet);
+ }
+ }
+
+ target[dwRet] = '\0';
+ return dwRet;
+}
+
+int p_hide_directory__w32(const char *path)
+{
+ int error;
+
+ error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ?
+ GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
+
+ if (error < GIT_SUCCESS)
+ error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path);
+
+ return error;
+}
+
diff --git a/src/win32/posix.h b/src/win32/posix.h
new file mode 100644
index 0000000..31ee720
--- /dev/null
+++ b/src/win32/posix.h
@@ -0,0 +1,25 @@
+#ifndef INCLUDE_posix__w32_h__
+#define INCLUDE_posix__w32_h__
+
+#include "common.h"
+
+GIT_INLINE(int) p_link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new))
+{
+ GIT_UNUSED_ARG(old)
+ GIT_UNUSED_ARG(new)
+ errno = ENOSYS;
+ return -1;
+}
+
+GIT_INLINE(int) p_mkdir(const char *path, int GIT_UNUSED(mode))
+{
+ GIT_UNUSED_ARG(mode)
+ return mkdir(path);
+}
+
+extern int p_unlink(const char *path);
+extern int p_lstat(const char *file_name, struct stat *buf);
+extern int p_readlink(const char *link, char *target, size_t target_len);
+extern int p_hide_directory__w32(const char *path);
+
+#endif
diff --git a/tests/t00-core.c b/tests/t00-core.c
index e1aa6b8..7ce51a7 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -78,9 +78,9 @@ BEGIN_TEST(path0, "get the dirname of a path")
char dir[64], *dir2;
#define DIRNAME_TEST(A, B) { \
- must_be_true(git__dirname_r(dir, sizeof(dir), A) >= 0); \
+ must_be_true(git_path_dirname_r(dir, sizeof(dir), A) >= 0); \
must_be_true(strcmp(dir, B) == 0); \
- must_be_true((dir2 = git__dirname(A)) != NULL); \
+ must_be_true((dir2 = git_path_dirname(A)) != NULL); \
must_be_true(strcmp(dir2, B) == 0); \
free(dir2); \
}
@@ -107,9 +107,9 @@ BEGIN_TEST(path1, "get the base name of a path")
char base[64], *base2;
#define BASENAME_TEST(A, B) { \
- must_be_true(git__basename_r(base, sizeof(base), A) >= 0); \
+ must_be_true(git_path_basename_r(base, sizeof(base), A) >= 0); \
must_be_true(strcmp(base, B) == 0); \
- must_be_true((base2 = git__basename(A)) != NULL); \
+ must_be_true((base2 = git_path_basename(A)) != NULL); \
must_be_true(strcmp(base2, B) == 0); \
free(base2); \
}
@@ -132,7 +132,7 @@ BEGIN_TEST(path2, "get the latest component in a path")
const char *dir;
#define TOPDIR_TEST(A, B) { \
- must_be_true((dir = git__topdir(A)) != NULL); \
+ must_be_true((dir = git_path_topdir(A)) != NULL); \
must_be_true(strcmp(dir, B) == 0); \
}
@@ -144,10 +144,10 @@ BEGIN_TEST(path2, "get the latest component in a path")
TOPDIR_TEST("/", "/");
TOPDIR_TEST("a/", "a/");
- must_be_true(git__topdir("/usr/.git") == NULL);
- must_be_true(git__topdir(".") == NULL);
- must_be_true(git__topdir("") == NULL);
- must_be_true(git__topdir("a") == NULL);
+ must_be_true(git_path_topdir("/usr/.git") == NULL);
+ must_be_true(git_path_topdir(".") == NULL);
+ must_be_true(git_path_topdir("") == NULL);
+ must_be_true(git_path_topdir("a") == NULL);
#undef TOPDIR_TEST
END_TEST
@@ -165,7 +165,7 @@ static int ensure_normalized(const char *input_path, const char *expected_path,
char buffer_out[GIT_PATH_MAX];
char current_workdir[GIT_PATH_MAX];
- error = gitfo_getcwd(current_workdir, sizeof(current_workdir));
+ error = p_getcwd(current_workdir, sizeof(current_workdir));
if (error < GIT_SUCCESS)
return error;
@@ -193,12 +193,12 @@ static int ensure_normalized(const char *input_path, const char *expected_path,
static int ensure_dir_path_normalized(const char *input_path, const char *expected_path, int assert_flags)
{
- return ensure_normalized(input_path, expected_path, gitfo_prettify_dir_path, assert_flags);
+ return ensure_normalized(input_path, expected_path, git_futils_prettify_dir, assert_flags);
}
static int ensure_file_path_normalized(const char *input_path, const char *expected_path, int assert_flags)
{
- return ensure_normalized(input_path, expected_path, gitfo_prettify_file_path, assert_flags);
+ return ensure_normalized(input_path, expected_path, git_futils_prettyify_file, assert_flags);
}
BEGIN_TEST(path3, "prettify and validate a path to a file")
@@ -355,7 +355,7 @@ END_TEST
static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{
char joined_path[GIT_PATH_MAX];
- git__joinpath(joined_path, path_a, path_b);
+ git_path_join(joined_path, path_a, path_b);
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
}
@@ -377,7 +377,7 @@ END_TEST
static int ensure_joinpath_n(const char *path_a, const char *path_b, const char *path_c, const char *path_d, const char *expected_path)
{
char joined_path[GIT_PATH_MAX];
- git__joinpath_n(joined_path, 4, path_a, path_b, path_c, path_d);
+ git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d);
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
}
@@ -411,14 +411,14 @@ BEGIN_TEST(path7, "prevent a path which escapes the root directory from being pr
char prettified[GIT_PATH_MAX];
int i = 0, number_to_escape;
- must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir)));
+ must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
number_to_escape = count_number_of_path_segments(current_workdir);
for (i = 0; i < number_to_escape + 1; i++)
- git__joinpath(current_workdir, current_workdir, "../");
+ git_path_join(current_workdir, current_workdir, "../");
- must_fail(gitfo_prettify_dir_path(prettified, sizeof(prettified), current_workdir, NULL));
+ must_fail(git_futils_prettify_dir(prettified, sizeof(prettified), current_workdir, NULL));
END_TEST
typedef struct name_data {
@@ -451,24 +451,24 @@ static int setup(walk_data *d)
{
name_data *n;
- if (gitfo_mkdir(top_dir, 0755) < 0)
+ if (p_mkdir(top_dir, 0755) < 0)
return error("can't mkdir(\"%s\")", top_dir);
- if (gitfo_chdir(top_dir) < 0)
+ if (p_chdir(top_dir) < 0)
return error("can't chdir(\"%s\")", top_dir);
if (strcmp(d->sub, ".") != 0)
- if (gitfo_mkdir(d->sub, 0755) < 0)
+ if (p_mkdir(d->sub, 0755) < 0)
return error("can't mkdir(\"%s\")", d->sub);
strcpy(path_buffer, d->sub);
state_loc = d;
for (n = d->names; n->name; n++) {
- git_file fd = gitfo_creat(n->name, 0600);
+ git_file fd = p_creat(n->name, 0600);
if (fd < 0)
return GIT_ERROR;
- gitfo_close(fd);
+ p_close(fd);
n->count = 0;
}
@@ -480,18 +480,18 @@ static int knockdown(walk_data *d)
name_data *n;
for (n = d->names; n->name; n++) {
- if (gitfo_unlink(n->name) < 0)
+ if (p_unlink(n->name) < 0)
return error("can't unlink(\"%s\")", n->name);
}
if (strcmp(d->sub, ".") != 0)
- if (gitfo_rmdir(d->sub) < 0)
+ if (p_rmdir(d->sub) < 0)
return error("can't rmdir(\"%s\")", d->sub);
- if (gitfo_chdir("..") < 0)
+ if (p_chdir("..") < 0)
return error("can't chdir(\"..\")");
- if (gitfo_rmdir(top_dir) < 0)
+ if (p_rmdir(top_dir) < 0)
return error("can't rmdir(\"%s\")", top_dir);
return 0;
@@ -546,7 +546,7 @@ BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed")
must_pass(setup(&dot));
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
one_entry,
&dot));
@@ -571,7 +571,7 @@ BEGIN_TEST(dirent1, "traverse a subfolder")
must_pass(setup(&sub));
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
one_entry,
&sub));
@@ -590,7 +590,7 @@ BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder")
must_pass(setup(&sub_slash));
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
one_entry,
&sub_slash));
@@ -619,7 +619,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed")
must_pass(setup(&empty));
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
one_entry,
&empty));
@@ -627,7 +627,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed")
must_pass(check_counts(&empty));
/* make sure callback not called */
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
dont_call_me,
&empty));
@@ -652,7 +652,7 @@ BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traver
must_pass(setup(&odd));
- must_pass(gitfo_dirent(path_buffer,
+ must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer),
one_entry,
&odd));
@@ -667,12 +667,12 @@ BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock
int fd;
char test[] = "test", testlock[] = "test.lock";
- fd = gitfo_creat(testlock, 0744);
+ fd = p_creat(testlock, 0744);
must_pass(fd);
- must_pass(gitfo_close(fd));
+ must_pass(p_close(fd));
must_fail(git_filebuf_open(&file, test, 0));
- must_pass(gitfo_exists(testlock));
- must_pass(gitfo_unlink(testlock));
+ must_pass(git_futils_exists(testlock));
+ must_pass(p_unlink(testlock));
END_TEST
BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
@@ -680,16 +680,16 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
int fd;
char test[] = "test";
- fd = gitfo_creat(test, 0644);
+ fd = p_creat(test, 0644);
must_pass(fd);
- must_pass(gitfo_write(fd, "libgit2 rocks\n", 14));
- must_pass(gitfo_close(fd));
+ must_pass(p_write(fd, "libgit2 rocks\n", 14));
+ must_pass(p_close(fd));
must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
must_pass(git_filebuf_commit(&file));
- must_pass(gitfo_unlink(test));
+ must_pass(p_unlink(test));
END_TEST
BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly")
@@ -702,7 +702,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly"
must_pass(git_filebuf_write(&file, buf, sizeof(buf)));
must_pass(git_filebuf_commit(&file));
- must_pass(gitfo_unlink(test));
+ must_pass(p_unlink(test));
END_TEST
BEGIN_SUITE(core)
diff --git a/tests/t03-objwrite.c b/tests/t03-objwrite.c
index 08ddc0f..31f611a 100644
--- a/tests/t03-objwrite.c
+++ b/tests/t03-objwrite.c
@@ -31,7 +31,7 @@ static char *odb_dir = "test-objects";
static int make_odb_dir(void)
{
- if (gitfo_mkdir(odb_dir, 0755) < 0) {
+ if (p_mkdir(odb_dir, 0755) < 0) {
int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST)
@@ -44,9 +44,9 @@ static int make_odb_dir(void)
static int check_object_files(object_data *d)
{
- if (gitfo_exists(d->dir) < 0)
+ if (git_futils_exists(d->dir) < 0)
return -1;
- if (gitfo_exists(d->file) < 0)
+ if (git_futils_exists(d->file) < 0)
return -1;
return 0;
}
@@ -64,16 +64,16 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2)
static int remove_object_files(object_data *d)
{
- if (gitfo_unlink(d->file) < 0) {
+ if (p_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
- if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
+ if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1;
}
- if (gitfo_rmdir(odb_dir) < 0) {
+ if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
diff --git a/tests/t06-index.c b/tests/t06-index.c
index 6a46719..3cbb5a9 100644
--- a/tests/t06-index.c
+++ b/tests/t06-index.c
@@ -146,7 +146,7 @@ BEGIN_TEST(write0, "write an index back to disk")
git_index_free(index);
- gitfo_unlink("index_rewrite");
+ p_unlink("index_rewrite");
END_TEST
BEGIN_TEST(sort0, "sort the entires in an index")
@@ -187,7 +187,7 @@ BEGIN_TEST(add0, "add a new file to the index")
must_pass(git_index_entrycount(index) == 0);
/* Create a new file in the working directory */
- must_pass(gitfo_mkdir_2file(TEMP_REPO_FOLDER "myrepo/test.txt"));
+ must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt"));
must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0));
must_pass(git_filebuf_write(&file, "hey there\n", 10));
must_pass(git_filebuf_commit(&file));
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index f975c8f..fb252f4 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -48,7 +48,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
must_be_true(git_object_type(object) == GIT_OBJ_TAG);
/* Ensure the name of the tag matches the name of the reference */
- git__joinpath(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object));
+ git_path_join(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object));
must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0);
git_object_close(object);
@@ -209,7 +209,7 @@ BEGIN_TEST(create0, "create a new symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */
- git__joinpath(ref_path, repo->path_repository, new_head_tracker);
+ git_path_join(ref_path, repo->path_repository, new_head_tracker);
/* Create and write the new symbolic reference */
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0));
@@ -251,7 +251,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
- git__joinpath(ref_path, repo->path_repository, new_head_tracker);
+ git_path_join(ref_path, repo->path_repository, new_head_tracker);
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0));
must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker));
must_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
@@ -273,7 +273,7 @@ BEGIN_TEST(create2, "create a new OID reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */
- git__joinpath(ref_path, repo->path_repository, new_head);
+ git_path_join(ref_path, repo->path_repository, new_head);
/* Create and write the new object id reference */
must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0));
@@ -432,8 +432,8 @@ BEGIN_TEST(pack0, "create a packfile for an empty folder")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
- git__joinpath_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir");
- must_pass(gitfo_mkdir_recurs(temp_path, mode));
+ git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir");
+ must_pass(git_futils_mkdir_r(temp_path, mode));
must_pass(git_reference_packall(repo));
@@ -460,8 +460,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(git_reference_packall(repo));
/* Ensure the packed-refs file exists */
- git__joinpath(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE);
- must_pass(gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE);
+ must_pass(git_futils_exists(temp_path));
/* Ensure the known ref can still be looked up but is now packed */
must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
@@ -469,8 +469,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
/* Ensure the known ref has been removed from the loose folder structure */
- git__joinpath(temp_path, repo->path_repository, loose_tag_ref_name);
- must_pass(!gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, loose_tag_ref_name);
+ must_pass(!git_futils_exists(temp_path));
close_temp_repo(repo);
END_TEST
@@ -484,8 +484,8 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
- git__joinpath(temp_path, repo->path_repository, new_name);
- must_pass(!gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, new_name);
+ must_pass(!git_futils_exists(temp_path));
/* Retrieval of the reference to rename */
must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name));
@@ -509,8 +509,8 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
/* ...and the ref can be found in the file system */
- git__joinpath(temp_path, repo->path_repository, new_name);
- must_pass(gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, new_name);
+ must_pass(git_futils_exists(temp_path));
close_temp_repo(repo);
END_TEST
@@ -524,8 +524,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
- git__joinpath(temp_path, repo->path_repository, packed_head_name);
- must_pass(!gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, packed_head_name);
+ must_pass(!git_futils_exists(temp_path));
/* The reference can however be looked-up... */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
@@ -549,8 +549,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
/* ...and the ref now happily lives in the file system */
- git__joinpath(temp_path, repo->path_repository, brand_new_name);
- must_pass(gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, brand_new_name);
+ must_pass(git_futils_exists(temp_path));
close_temp_repo(repo);
END_TEST
@@ -564,8 +564,8 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the other reference exists on the file system */
- git__joinpath(temp_path, repo->path_repository, packed_test_head_name);
- must_pass(gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, packed_test_head_name);
+ must_pass(git_futils_exists(temp_path));
/* Lookup the other reference */
must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
@@ -589,7 +589,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0);
/* Ensure the other ref still exists on the file system */
- must_pass(gitfo_exists(temp_path));
+ must_pass(git_futils_exists(temp_path));
close_temp_repo(repo);
END_TEST
@@ -694,8 +694,8 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the loose reference exists on the file system */
- git__joinpath(temp_path, repo->path_repository, packed_test_head_name);
- must_pass(gitfo_exists(temp_path));
+ git_path_join(temp_path, repo->path_repository, packed_test_head_name);
+ must_pass(git_futils_exists(temp_path));
/* Lookup the reference */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
@@ -710,7 +710,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure the loose reference doesn't exist any longer on the file system */
- must_pass(!gitfo_exists(temp_path));
+ must_pass(!git_futils_exists(temp_path));
close_temp_repo(repo);
END_TEST
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 3b010c8..3b3c7c0 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -104,10 +104,10 @@ static int ensure_repository_init(
char path_odb[GIT_PATH_MAX];
git_repository *repo;
- if (gitfo_isdir(working_directory) == GIT_SUCCESS)
+ if (git_futils_isdir(working_directory) == GIT_SUCCESS)
return GIT_ERROR;
- git__joinpath(path_odb, expected_path_repository, GIT_OBJECTS_DIR);
+ git_path_join(path_odb, expected_path_repository, GIT_OBJECTS_DIR);
if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS)
return GIT_ERROR;
@@ -154,8 +154,8 @@ cleanup:
BEGIN_TEST(init0, "initialize a standard repo")
char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX];
- git__joinpath(path_repository, TEMP_REPO_FOLDER, GIT_DIR);
- git__joinpath(path_index, path_repository, GIT_INDEX_FILE);
+ git_path_join(path_repository, TEMP_REPO_FOLDER, GIT_DIR);
+ git_path_join(path_index, path_repository, GIT_INDEX_FILE);
must_pass(ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER));
must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER));
@@ -164,7 +164,7 @@ END_TEST
BEGIN_TEST(init1, "initialize a bare repo")
char path_repository[GIT_PATH_MAX];
- git__joinpath(path_repository, TEMP_REPO_FOLDER, "");
+ git_path_join(path_repository, TEMP_REPO_FOLDER, "");
must_pass(ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL));
must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL));
@@ -176,10 +176,10 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping
const int mode = 0755; /* or 0777 ? */
git_repository* repo;
- must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir)));
+ must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- git__joinpath(path_repository, TEMP_REPO_FOLDER, "a/b/c/");
- must_pass(gitfo_mkdir_recurs(path_repository, mode));
+ git_path_join(path_repository, TEMP_REPO_FOLDER, "a/b/c/");
+ must_pass(git_futils_mkdir_r(path_repository, mode));
must_pass(chdir(path_repository));
@@ -242,14 +242,14 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
git_repository* repo;
/* Setup the repository to open */
- must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir)));
+ must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
strcpy(path_repository, current_workdir);
- git__joinpath_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git");
+ git_path_join_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git");
must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository));
/* Change the current working directory */
- git__joinpath(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/");
- must_pass(gitfo_mkdir_recurs(new_current_workdir, mode));
+ git_path_join(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/");
+ must_pass(git_futils_mkdir_r(new_current_workdir, mode));
must_pass(chdir(new_current_workdir));
must_pass(git_repository_open(&repo, "../../d/e.git"));
@@ -350,20 +350,20 @@ static int write_file(const char *path, const char *content)
int error;
git_file file;
- if (gitfo_exists(path) == GIT_SUCCESS) {
- error = gitfo_unlink(path);
+ if (git_futils_exists(path) == GIT_SUCCESS) {
+ error = p_unlink(path);
if (error < GIT_SUCCESS)
return error;
}
- file = gitfo_creat_force(path, 0644);
+ file = git_futils_creat_withpath(path, 0644);
if (file < GIT_SUCCESS)
return file;
- error = gitfo_write(file, (void*)content, strlen(content) * sizeof(char));
+ error = p_write(file, (void*)content, strlen(content) * sizeof(char));
- gitfo_close(file);
+ p_close(file);
return error;
}
@@ -374,7 +374,7 @@ static int append_ceiling_dir(char *ceiling_dirs, const char *path)
int len = strlen(ceiling_dirs);
int error;
- error = gitfo_prettify_dir_path(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL);
+ error = git_futils_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to append ceiling directory.");
@@ -394,7 +394,7 @@ BEGIN_TEST(discover0, "test discover")
rmdir_recurs(DISCOVER_FOLDER);
must_pass(append_ceiling_dir(ceiling_dirs,TEST_RESOURCES));
- gitfo_mkdir_recurs(DISCOVER_FOLDER, mode);
+ git_futils_mkdir_r(DISCOVER_FOLDER, mode);
must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO);
@@ -403,15 +403,15 @@ BEGIN_TEST(discover0, "test discover")
git_repository_free(repo);
must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
- must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
+ must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
- must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
+ must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path));
- must_pass(gitfo_mkdir_recurs(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode));
+ must_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../"));
@@ -420,13 +420,13 @@ BEGIN_TEST(discover0, "test discover")
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path));
- must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER1, mode));
+ must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:"));
- must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER2, mode));
+ must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:"));
- must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER3, mode));
+ must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n"));
- must_pass(gitfo_mkdir_recurs(ALTERNATE_NOT_FOUND_FOLDER, mode));
+ must_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode));
must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist"));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 760de23..5c2ccee 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -32,17 +32,17 @@ int write_object_data(char *file, void *data, size_t len)
git_file fd;
int ret;
- if ((fd = gitfo_creat(file, S_IREAD | S_IWRITE)) < 0)
+ if ((fd = p_creat(file, S_IREAD | S_IWRITE)) < 0)
return -1;
- ret = gitfo_write(fd, data, len);
- gitfo_close(fd);
+ ret = p_write(fd, data, len);
+ p_close(fd);
return ret;
}
int write_object_files(const char *odb_dir, object_data *d)
{
- if (gitfo_mkdir(odb_dir, 0755) < 0) {
+ if (p_mkdir(odb_dir, 0755) < 0) {
int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST)
@@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d)
return -1;
}
- if ((gitfo_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
+ if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
fprintf(stderr, "can't make object directory \"%s\"\n", d->dir);
return -1;
}
@@ -65,16 +65,16 @@ int write_object_files(const char *odb_dir, object_data *d)
int remove_object_files(const char *odb_dir, object_data *d)
{
- if (gitfo_unlink(d->file) < 0) {
+ if (p_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
- if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
+ if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir);
return -1;
}
- if (gitfo_rmdir(odb_dir) < 0) {
+ if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
@@ -104,14 +104,14 @@ int remove_loose_object(const char *repository_folder, git_object *object)
ptr += GIT_OID_HEXSZ + 1;
*ptr = 0;
- if (gitfo_unlink(full_path) < 0) {
+ if (p_unlink(full_path) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", full_path);
return -1;
}
*top_folder = 0;
- if ((gitfo_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) {
+ if ((p_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", full_path);
return -1;
}
@@ -134,44 +134,44 @@ int cmp_objects(git_rawobj *o, object_data *d)
int copy_file(const char *src, const char *dst)
{
- gitfo_buf source_buf;
+ git_fbuffer source_buf;
git_file dst_fd;
int error = GIT_ERROR;
- if (gitfo_read_file(&source_buf, src) < GIT_SUCCESS)
+ if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS)
return GIT_ENOTFOUND;
- dst_fd = gitfo_creat_force(dst, 0644);
+ dst_fd = git_futils_creat_withpath(dst, 0644);
if (dst_fd < 0)
goto cleanup;
- error = gitfo_write(dst_fd, source_buf.data, source_buf.len);
+ error = p_write(dst_fd, source_buf.data, source_buf.len);
cleanup:
- gitfo_free_buf(&source_buf);
- gitfo_close(dst_fd);
+ git_futils_freebuffer(&source_buf);
+ p_close(dst_fd);
return error;
}
int cmp_files(const char *a, const char *b)
{
- gitfo_buf buf_a, buf_b;
+ git_fbuffer buf_a, buf_b;
int error = GIT_ERROR;
- if (gitfo_read_file(&buf_a, a) < GIT_SUCCESS)
+ if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS)
return GIT_ERROR;
- if (gitfo_read_file(&buf_b, b) < GIT_SUCCESS) {
- gitfo_free_buf(&buf_a);
+ if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) {
+ git_futils_freebuffer(&buf_a);
return GIT_ERROR;
}
if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len))
error = GIT_SUCCESS;
- gitfo_free_buf(&buf_a);
- gitfo_free_buf(&buf_b);
+ git_futils_freebuffer(&buf_a);
+ git_futils_freebuffer(&buf_b);
return error;
}
@@ -182,11 +182,11 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path)
GIT_UNUSED_ARG(nil);
- error = gitfo_isdir(path);
+ error = git_futils_isdir(path);
if (error == GIT_SUCCESS) {
size_t root_size = strlen(path);
- error = gitfo_dirent(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL);
+ error = git_futils_direach(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL);
if (error < GIT_SUCCESS)
return error;
@@ -194,7 +194,7 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path)
return rmdir(path);
}
- return gitfo_unlink(path);
+ return p_unlink(path);
}
int rmdir_recurs(const char *directory_path)
@@ -214,10 +214,10 @@ static int copy_filesystem_element_recurs(void *_data, char *source)
copydir_data *data = (copydir_data *)_data;
data->dst[data->dst_len] = 0;
- git__joinpath(data->dst, data->dst, source + data->src_len);
+ git_path_join(data->dst, data->dst, source + data->src_len);
- if (gitfo_isdir(source) == GIT_SUCCESS)
- return gitfo_dirent(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data);
+ if (git_futils_isdir(source) == GIT_SUCCESS)
+ return git_futils_direach(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data);
return copy_file(source, data->dst);
}
@@ -229,13 +229,14 @@ int copydir_recurs(const char *source_directory_path, const char *destination_di
copydir_data data;
/* Source has to exist, Destination hast to _not_ exist */
- if (gitfo_isdir(source_directory_path) || !gitfo_isdir(destination_directory_path))
+ if (git_futils_isdir(source_directory_path) != GIT_SUCCESS ||
+ git_futils_isdir(destination_directory_path) == GIT_SUCCESS)
return GIT_EINVALIDPATH;
- git__joinpath(source_buffer, source_directory_path, "");
+ git_path_join(source_buffer, source_directory_path, "");
data.src_len = strlen(source_buffer);
- git__joinpath(dest_buffer, destination_directory_path, "");
+ git_path_join(dest_buffer, destination_directory_path, "");
data.dst = dest_buffer;
data.dst_len = strlen(dest_buffer);
@@ -262,14 +263,14 @@ static int remove_placeholders_recurs(void *filename, char *path)
char passed_filename[GIT_PATH_MAX];
char *data = (char *)filename;
- if (!gitfo_isdir(path))
- return gitfo_dirent(path, GIT_PATH_MAX, remove_placeholders_recurs, data);
+ if (!git_futils_isdir(path))
+ return git_futils_direach(path, GIT_PATH_MAX, remove_placeholders_recurs, data);
- if (git__basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS)
- return GIT_EINVALIDPATH;
+ if (git_path_basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS)
+ return GIT_EINVALIDPATH;
if (!strcmp(data, passed_filename))
- return gitfo_unlink(path);
+ return p_unlink(path);
return GIT_SUCCESS;
}
@@ -278,7 +279,7 @@ int remove_placeholders(char *directory_path, char *filename)
{
char buffer[GIT_PATH_MAX];
- if (gitfo_isdir(directory_path))
+ if (git_futils_isdir(directory_path))
return GIT_EINVALIDPATH;
strcpy(buffer, directory_path);