1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
|
/* POSIX module implementation */
/* This file is also used for Windows NT/MS-Win. In that case the
module actually calls itself 'nt', not 'posix', and a few
functions are either unimplemented or implemented differently. The source
assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
of the compiler used. Different compilers define their own feature
test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */
#ifdef __APPLE__
/*
* Step 1 of support for weak-linking a number of symbols existing on
* OSX 10.4 and later, see the comment in the #ifdef __APPLE__ block
* at the end of this file for more information.
*/
# pragma weak lchown
# pragma weak statvfs
# pragma weak fstatvfs
#endif /* __APPLE__ */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef MS_WINDOWS
#include "posixmodule.h"
#else
#include "winreparse.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
PyDoc_STRVAR(posix__doc__,
"This module provides access to operating system functionality that is\n\
standardized by the C Standard and the POSIX standard (a thinly\n\
disguised Unix interface). Refer to the library manual and\n\
corresponding Unix manual entries for more information on calls.");
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h> /* For WNOHANG */
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif /* HAVE_FCNTL_H */
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#ifdef HAVE_SYSEXITS_H
#include <sysexits.h>
#endif /* HAVE_SYSEXITS_H */
#ifdef HAVE_SYS_LOADAVG_H
#include <sys/loadavg.h>
#endif
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
#ifdef HAVE_SYS_SENDFILE_H
#include <sys/sendfile.h>
#endif
#ifdef HAVE_SCHED_H
#include <sched.h>
#endif
#if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY)
#undef HAVE_SCHED_SETAFFINITY
#endif
#if defined(HAVE_SYS_XATTR_H) && defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
#define USE_XATTRS
#endif
#ifdef USE_XATTRS
#include <sys/xattr.h>
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#ifdef __hpux
#include <sys/mpctl.h>
#endif
#if defined(__DragonFly__) || \
defined(__OpenBSD__) || \
defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__APPLE__)
#include <sys/sysctl.h>
#endif
#if defined(MS_WINDOWS)
# define TERMSIZE_USE_CONIO
#elif defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
# if defined(HAVE_TERMIOS_H)
# include <termios.h>
# endif
# if defined(TIOCGWINSZ)
# define TERMSIZE_USE_IOCTL
# endif
#endif /* MS_WINDOWS */
/* Various compilers have only certain posix functions */
/* XXX Gosh I wish these were all moved into pyconfig.h */
#if defined(__WATCOMC__) && !defined(__QNX__) /* Watcom compiler */
#define HAVE_OPENDIR 1
#define HAVE_SYSTEM 1
#include <process.h>
#else
#ifdef __BORLANDC__ /* Borland compiler */
#define HAVE_EXECV 1
#define HAVE_OPENDIR 1
#define HAVE_PIPE 1
#define HAVE_SYSTEM 1
#define HAVE_WAIT 1
#else
#ifdef _MSC_VER /* Microsoft compiler */
#define HAVE_GETPPID 1
#define HAVE_GETLOGIN 1
#define HAVE_SPAWNV 1
#define HAVE_EXECV 1
#define HAVE_PIPE 1
#define HAVE_SYSTEM 1
#define HAVE_CWAIT 1
#define HAVE_FSYNC 1
#define fsync _commit
#else
/* Unix functions that the configure script doesn't check for */
#define HAVE_EXECV 1
#define HAVE_FORK 1
#if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
#define HAVE_FORK1 1
#endif
#define HAVE_GETEGID 1
#define HAVE_GETEUID 1
#define HAVE_GETGID 1
#define HAVE_GETPPID 1
#define HAVE_GETUID 1
#define HAVE_KILL 1
#define HAVE_OPENDIR 1
#define HAVE_PIPE 1
#define HAVE_SYSTEM 1
#define HAVE_WAIT 1
#define HAVE_TTYNAME 1
#endif /* _MSC_VER */
#endif /* __BORLANDC__ */
#endif /* ! __WATCOMC__ || __QNX__ */
/*[clinic input]
# one of the few times we lie about this name!
module os
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=94a0f0f978acae17]*/
#ifndef _MSC_VER
#if defined(__sgi)&&_COMPILER_VERSION>=700
/* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
(default) */
extern char *ctermid_r(char *);
#endif
#ifndef HAVE_UNISTD_H
#if defined(PYCC_VACPP)
extern int mkdir(char *);
#else
#if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__)
extern int mkdir(const char *);
#else
extern int mkdir(const char *, mode_t);
#endif
#endif
#if defined(__IBMC__) || defined(__IBMCPP__)
extern int chdir(char *);
extern int rmdir(char *);
#else
extern int chdir(const char *);
extern int rmdir(const char *);
#endif
#ifdef __BORLANDC__
extern int chmod(const char *, int);
#else
extern int chmod(const char *, mode_t);
#endif
/*#ifdef HAVE_FCHMOD
extern int fchmod(int, mode_t);
#endif*/
/*#ifdef HAVE_LCHMOD
extern int lchmod(const char *, mode_t);
#endif*/
extern int chown(const char *, uid_t, gid_t);
extern char *getcwd(char *, int);
extern char *strerror(int);
extern int link(const char *, const char *);
extern int rename(const char *, const char *);
extern int stat(const char *, struct stat *);
extern int unlink(const char *);
#ifdef HAVE_SYMLINK
extern int symlink(const char *, const char *);
#endif /* HAVE_SYMLINK */
#ifdef HAVE_LSTAT
extern int lstat(const char *, struct stat *);
#endif /* HAVE_LSTAT */
#endif /* !HAVE_UNISTD_H */
#endif /* !_MSC_VER */
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif /* HAVE_UTIME_H */
#ifdef HAVE_SYS_UTIME_H
#include <sys/utime.h>
#define HAVE_UTIME_H /* pretend we do for the rest of this file */
#endif /* HAVE_SYS_UTIME_H */
#ifdef HAVE_SYS_TIMES_H
#include <sys/times.h>
#endif /* HAVE_SYS_TIMES_H */
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif /* HAVE_SYS_PARAM_H */
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif /* HAVE_SYS_UTSNAME_H */
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#if defined(__WATCOMC__) && !defined(__QNX__)
#include <direct.h>
#define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#define dirent direct
#define NAMLEN(dirent) (dirent)->d_namlen
#endif
#ifdef HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
#include <ndir.h>
#endif
#endif
#ifdef _MSC_VER
#ifdef HAVE_DIRECT_H
#include <direct.h>
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_PROCESS_H
#include <process.h>
#endif
#ifndef VOLUME_NAME_DOS
#define VOLUME_NAME_DOS 0x0
#endif
#ifndef VOLUME_NAME_NT
#define VOLUME_NAME_NT 0x2
#endif
#ifndef IO_REPARSE_TAG_SYMLINK
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
#endif
#ifndef IO_REPARSE_TAG_MOUNT_POINT
#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
#endif
#include "osdefs.h"
#include <malloc.h>
#include <windows.h>
#include <shellapi.h> /* for ShellExecute() */
#include <lmcons.h> /* for UNLEN */
#ifdef SE_CREATE_SYMBOLIC_LINK_NAME /* Available starting with Vista */
#define HAVE_SYMLINK
static int win32_can_symlink = 0;
#endif
#endif /* _MSC_VER */
#ifndef MAXPATHLEN
#if defined(PATH_MAX) && PATH_MAX > 1024
#define MAXPATHLEN PATH_MAX
#else
#define MAXPATHLEN 1024
#endif
#endif /* MAXPATHLEN */
#ifdef UNION_WAIT
/* Emulate some macros on systems that have a union instead of macros */
#ifndef WIFEXITED
#define WIFEXITED(u_wait) (!(u_wait).w_termsig && !(u_wait).w_coredump)
#endif
#ifndef WEXITSTATUS
#define WEXITSTATUS(u_wait) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1)
#endif
#ifndef WTERMSIG
#define WTERMSIG(u_wait) ((u_wait).w_termsig)
#endif
#define WAIT_TYPE union wait
#define WAIT_STATUS_INT(s) (s.w_status)
#else /* !UNION_WAIT */
#define WAIT_TYPE int
#define WAIT_STATUS_INT(s) (s)
#endif /* UNION_WAIT */
/* Don't use the "_r" form if we don't need it (also, won't have a
prototype for it, at least on Solaris -- maybe others as well?). */
#if defined(HAVE_CTERMID_R) && defined(WITH_THREAD)
#define USE_CTERMID_R
#endif
/* choose the appropriate stat and fstat functions and return structs */
#undef STAT
#undef FSTAT
#undef STRUCT_STAT
#ifdef MS_WINDOWS
# define STAT win32_stat
# define LSTAT win32_lstat
# define FSTAT win32_fstat
# define STRUCT_STAT struct win32_stat
#else
# define STAT stat
# define LSTAT lstat
# define FSTAT fstat
# define STRUCT_STAT struct stat
#endif
#if defined(MAJOR_IN_MKDEV)
#include <sys/mkdev.h>
#else
#if defined(MAJOR_IN_SYSMACROS)
#include <sys/sysmacros.h>
#endif
#if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H)
#include <sys/mkdev.h>
#endif
#endif
#define DWORD_MAX 4294967295U
#ifdef MS_WINDOWS
static int
win32_warn_bytes_api()
{
return PyErr_WarnEx(PyExc_DeprecationWarning,
"The Windows bytes API has been deprecated, "
"use Unicode filenames instead",
1);
}
#endif
#ifndef MS_WINDOWS
PyObject *
_PyLong_FromUid(uid_t uid)
{
if (uid == (uid_t)-1)
return PyLong_FromLong(-1);
return PyLong_FromUnsignedLong(uid);
}
PyObject *
_PyLong_FromGid(gid_t gid)
{
if (gid == (gid_t)-1)
return PyLong_FromLong(-1);
return PyLong_FromUnsignedLong(gid);
}
int
_Py_Uid_Converter(PyObject *obj, void *p)
{
uid_t uid;
PyObject *index;
int overflow;
long result;
unsigned long uresult;
index = PyNumber_Index(obj);
if (index == NULL) {
PyErr_Format(PyExc_TypeError,
"uid should be integer, not %.200s",
Py_TYPE(obj)->tp_name);
return 0;
}
/*
* Handling uid_t is complicated for two reasons:
* * Although uid_t is (always?) unsigned, it still
* accepts -1.
* * We don't know its size in advance--it may be
* bigger than an int, or it may be smaller than
* a long.
*
* So a bit of defensive programming is in order.
* Start with interpreting the value passed
* in as a signed long and see if it works.
*/
result = PyLong_AsLongAndOverflow(index, &overflow);
if (!overflow) {
uid = (uid_t)result;
if (result == -1) {
if (PyErr_Occurred())
goto fail;
/* It's a legitimate -1, we're done. */
goto success;
}
/* Any other negative number is disallowed. */
if (result < 0)
goto underflow;
/* Ensure the value wasn't truncated. */
if (sizeof(uid_t) < sizeof(long) &&
(long)uid != result)
goto underflow;
goto success;
}
if (overflow < 0)
goto underflow;
/*
* Okay, the value overflowed a signed long. If it
* fits in an *unsigned* long, it may still be okay,
* as uid_t may be unsigned long on this platform.
*/
uresult = PyLong_AsUnsignedLong(index);
if (PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
goto overflow;
goto fail;
}
uid = (uid_t)uresult;
/*
* If uid == (uid_t)-1, the user actually passed in ULONG_MAX,
* but this value would get interpreted as (uid_t)-1 by chown
* and its siblings. That's not what the user meant! So we
* throw an overflow exception instead. (We already
* handled a real -1 with PyLong_AsLongAndOverflow() above.)
*/
if (uid == (uid_t)-1)
goto overflow;
/* Ensure the value wasn't truncated. */
if (sizeof(uid_t) < sizeof(long) &&
(unsigned long)uid != uresult)
goto overflow;
/* fallthrough */
success:
Py_DECREF(index);
*(uid_t *)p = uid;
return 1;
underflow:
PyErr_SetString(PyExc_OverflowError,
"uid is less than minimum");
goto fail;
overflow:
PyErr_SetString(PyExc_OverflowError,
"uid is greater than maximum");
/* fallthrough */
fail:
Py_DECREF(index);
return 0;
}
int
_Py_Gid_Converter(PyObject *obj, void *p)
{
gid_t gid;
PyObject *index;
int overflow;
long result;
unsigned long uresult;
index = PyNumber_Index(obj);
if (index == NULL) {
PyErr_Format(PyExc_TypeError,
"gid should be integer, not %.200s",
Py_TYPE(obj)->tp_name);
return 0;
}
/*
* Handling gid_t is complicated for two reasons:
* * Although gid_t is (always?) unsigned, it still
* accepts -1.
* * We don't know its size in advance--it may be
* bigger than an int, or it may be smaller than
* a long.
*
* So a bit of defensive programming is in order.
* Start with interpreting the value passed
* in as a signed long and see if it works.
*/
result = PyLong_AsLongAndOverflow(index, &overflow);
if (!overflow) {
gid = (gid_t)result;
if (result == -1) {
if (PyErr_Occurred())
goto fail;
/* It's a legitimate -1, we're done. */
goto success;
}
/* Any other negative number is disallowed. */
if (result < 0) {
goto underflow;
}
/* Ensure the value wasn't truncated. */
if (sizeof(gid_t) < sizeof(long) &&
(long)gid != result)
goto underflow;
goto success;
}
if (overflow < 0)
goto underflow;
/*
* Okay, the value overflowed a signed long. If it
* fits in an *unsigned* long, it may still be okay,
* as gid_t may be unsigned long on this platform.
*/
uresult = PyLong_AsUnsignedLong(index);
if (PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
goto overflow;
goto fail;
}
gid = (gid_t)uresult;
/*
* If gid == (gid_t)-1, the user actually passed in ULONG_MAX,
* but this value would get interpreted as (gid_t)-1 by chown
* and its siblings. That's not what the user meant! So we
* throw an overflow exception instead. (We already
* handled a real -1 with PyLong_AsLongAndOverflow() above.)
*/
if (gid == (gid_t)-1)
goto overflow;
/* Ensure the value wasn't truncated. */
if (sizeof(gid_t) < sizeof(long) &&
(unsigned long)gid != uresult)
goto overflow;
/* fallthrough */
success:
Py_DECREF(index);
*(gid_t *)p = gid;
return 1;
underflow:
PyErr_SetString(PyExc_OverflowError,
"gid is less than minimum");
goto fail;
overflow:
PyErr_SetString(PyExc_OverflowError,
"gid is greater than maximum");
/* fallthrough */
fail:
Py_DECREF(index);
return 0;
}
#endif /* MS_WINDOWS */
#ifdef AT_FDCWD
/*
* Why the (int) cast? Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965);
* without the int cast, the value gets interpreted as uint (4291925331),
* which doesn't play nicely with all the initializer lines in this file that
* look like this:
* int dir_fd = DEFAULT_DIR_FD;
*/
#define DEFAULT_DIR_FD (int)AT_FDCWD
#else
#define DEFAULT_DIR_FD (-100)
#endif
static int
_fd_converter(PyObject *o, int *p, const char *allowed)
{
int overflow;
long long_value;
PyObject *index = PyNumber_Index(o);
if (index == NULL) {
PyErr_Format(PyExc_TypeError,
"argument should be %s, not %.200s",
allowed, Py_TYPE(o)->tp_name);
return 0;
}
long_value = PyLong_AsLongAndOverflow(index, &overflow);
Py_DECREF(index);
if (overflow > 0 || long_value > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"fd is greater than maximum");
return 0;
}
if (overflow < 0 || long_value < INT_MIN) {
PyErr_SetString(PyExc_OverflowError,
"fd is less than minimum");
return 0;
}
*p = (int)long_value;
return 1;
}
static int
dir_fd_converter(PyObject *o, void *p)
{
if (o == Py_None) {
*(int *)p = DEFAULT_DIR_FD;
return 1;
}
return _fd_converter(o, (int *)p, "integer");
}
/*
* A PyArg_ParseTuple "converter" function
* that handles filesystem paths in the manner
* preferred by the os module.
*
* path_converter accepts (Unicode) strings and their
* subclasses, and bytes and their subclasses. What
* it does with the argument depends on the platform:
*
* * On Windows, if we get a (Unicode) string we
* extract the wchar_t * and return it; if we get
* bytes we extract the char * and return that.
*
* * On all other platforms, strings are encoded
* to bytes using PyUnicode_FSConverter, then we
* extract the char * from the bytes object and
* return that.
*
* path_converter also optionally accepts signed
* integers (representing open file descriptors) instead
* of path strings.
*
* Input fields:
* path.nullable
* If nonzero, the path is permitted to be None.
* path.allow_fd
* If nonzero, the path is permitted to be a file handle
* (a signed int) instead of a string.
* path.function_name
* If non-NULL, path_converter will use that as the name
* of the function in error messages.
* (If path.function_name is NULL it omits the function name.)
* path.argument_name
* If non-NULL, path_converter will use that as the name
* of the parameter in error messages.
* (If path.argument_name is NULL it uses "path".)
*
* Output fields:
* path.wide
* Points to the path if it was expressed as Unicode
* and was not encoded. (Only used on Windows.)
* path.narrow
* Points to the path if it was expressed as bytes,
* or it was Unicode and was encoded to bytes.
* path.fd
* Contains a file descriptor if path.accept_fd was true
* and the caller provided a signed integer instead of any
* sort of string.
*
* WARNING: if your "path" parameter is optional, and is
* unspecified, path_converter will never get called.
* So if you set allow_fd, you *MUST* initialize path.fd = -1
* yourself!
* path.length
* The length of the path in characters, if specified as
* a string.
* path.object
* The original object passed in.
* path.cleanup
* For internal use only. May point to a temporary object.
* (Pay no attention to the man behind the curtain.)
*
* At most one of path.wide or path.narrow will be non-NULL.
* If path was None and path.nullable was set,
* or if path was an integer and path.allow_fd was set,
* both path.wide and path.narrow will be NULL
* and path.length will be 0.
*
* path_converter takes care to not write to the path_t
* unless it's successful. However it must reset the
* "cleanup" field each time it's called.
*
* Use as follows:
* path_t path;
* memset(&path, 0, sizeof(path));
* PyArg_ParseTuple(args, "O&", path_converter, &path);
* // ... use values from path ...
* path_cleanup(&path);
*
* (Note that if PyArg_Parse fails you don't need to call
* path_cleanup(). However it is safe to do so.)
*/
typedef struct {
const char *function_name;
const char *argument_name;
int nullable;
int allow_fd;
wchar_t *wide;
char *narrow;
int fd;
Py_ssize_t length;
PyObject *object;
PyObject *cleanup;
} path_t;
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \
{function_name, argument_name, nullable, allow_fd, NULL, NULL, -1, 0, NULL, NULL}
static void
path_cleanup(path_t *path) {
if (path->cleanup) {
Py_CLEAR(path->cleanup);
}
}
static int
path_converter(PyObject *o, void *p) {
path_t *path = (path_t *)p;
PyObject *unicode, *bytes;
Py_ssize_t length;
char *narrow;
#define FORMAT_EXCEPTION(exc, fmt) \
PyErr_Format(exc, "%s%s" fmt, \
path->function_name ? path->function_name : "", \
path->function_name ? ": " : "", \
path->argument_name ? path->argument_name : "path")
/* Py_CLEANUP_SUPPORTED support */
if (o == NULL) {
path_cleanup(path);
return 1;
}
/* ensure it's always safe to call path_cleanup() */
path->cleanup = NULL;
if (o == Py_None) {
if (!path->nullable) {
FORMAT_EXCEPTION(PyExc_TypeError,
"can't specify None for %s argument");
return 0;
}
path->wide = NULL;
path->narrow = NULL;
path->length = 0;
path->object = o;
path->fd = -1;
return 1;
}
unicode = PyUnicode_FromObject(o);
if (unicode) {
#ifdef MS_WINDOWS
wchar_t *wide;
wide = PyUnicode_AsUnicodeAndSize(unicode, &length);
if (!wide) {
Py_DECREF(unicode);
return 0;
}
if (length > 32767) {
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
Py_DECREF(unicode);
return 0;
}
path->wide = wide;
path->narrow = NULL;
path->length = length;
path->object = o;
path->fd = -1;
path->cleanup = unicode;
return Py_CLEANUP_SUPPORTED;
#else
int converted = PyUnicode_FSConverter(unicode, &bytes);
Py_DECREF(unicode);
if (!converted)
bytes = NULL;
#endif
}
else {
PyErr_Clear();
if (PyObject_CheckBuffer(o))
bytes = PyBytes_FromObject(o);
else
bytes = NULL;
if (!bytes) {
PyErr_Clear();
if (path->allow_fd) {
int fd;
int result = _fd_converter(o, &fd,
"string, bytes or integer");
if (result) {
path->wide = NULL;
path->narrow = NULL;
path->length = 0;
path->object = o;
path->fd = fd;
return result;
}
}
}
}
if (!bytes) {
if (!PyErr_Occurred())
FORMAT_EXCEPTION(PyExc_TypeError, "illegal type for %s parameter");
return 0;
}
#ifdef MS_WINDOWS
if (win32_warn_bytes_api()) {
Py_DECREF(bytes);
return 0;
}
#endif
length = PyBytes_GET_SIZE(bytes);
#ifdef MS_WINDOWS
if (length > MAX_PATH-1) {
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
Py_DECREF(bytes);
return 0;
}
#endif
narrow = PyBytes_AS_STRING(bytes);
if ((size_t)length != strlen(narrow)) {
FORMAT_EXCEPTION(PyExc_ValueError, "embedded NUL character in %s");
Py_DECREF(bytes);
return 0;
}
path->wide = NULL;
path->narrow = narrow;
path->length = length;
path->object = o;
path->fd = -1;
path->cleanup = bytes;
return Py_CLEANUP_SUPPORTED;
}
static void
argument_unavailable_error(char *function_name, char *argument_name) {
PyErr_Format(PyExc_NotImplementedError,
"%s%s%s unavailable on this platform",
(function_name != NULL) ? function_name : "",
(function_name != NULL) ? ": ": "",
argument_name);
}
static int
dir_fd_unavailable(PyObject *o, void *p)
{
int dir_fd;
if (!dir_fd_converter(o, &dir_fd))
return 0;
if (dir_fd != DEFAULT_DIR_FD) {
argument_unavailable_error(NULL, "dir_fd");
return 0;
}
*(int *)p = dir_fd;
return 1;
}
static int
fd_specified(char *function_name, int fd) {
if (fd == -1)
return 0;
argument_unavailable_error(function_name, "fd");
return 1;
}
static int
follow_symlinks_specified(char *function_name, int follow_symlinks) {
if (follow_symlinks)
return 0;
argument_unavailable_error(function_name, "follow_symlinks");
return 1;
}
static int
path_and_dir_fd_invalid(char *function_name, path_t *path, int dir_fd) {
if (!path->narrow && !path->wide && (dir_fd != DEFAULT_DIR_FD)) {
PyErr_Format(PyExc_ValueError,
"%s: can't specify dir_fd without matching path",
function_name);
return 1;
}
return 0;
}
static int
dir_fd_and_fd_invalid(char *function_name, int dir_fd, int fd) {
if ((dir_fd != DEFAULT_DIR_FD) && (fd != -1)) {
PyErr_Format(PyExc_ValueError,
"%s: can't specify both dir_fd and fd",
function_name);
return 1;
}
return 0;
}
static int
fd_and_follow_symlinks_invalid(char *function_name, int fd,
int follow_symlinks) {
if ((fd > 0) && (!follow_symlinks)) {
PyErr_Format(PyExc_ValueError,
"%s: cannot use fd and follow_symlinks together",
function_name);
return 1;
}
return 0;
}
static int
dir_fd_and_follow_symlinks_invalid(char *function_name, int dir_fd,
int follow_symlinks) {
if ((dir_fd != DEFAULT_DIR_FD) && (!follow_symlinks)) {
PyErr_Format(PyExc_ValueError,
"%s: cannot use dir_fd and follow_symlinks together",
function_name);
return 1;
}
return 0;
}
#ifdef MS_WINDOWS
typedef PY_LONG_LONG Py_off_t;
#else
typedef off_t Py_off_t;
#endif
static int
Py_off_t_converter(PyObject *arg, void *addr)
{
#ifdef HAVE_LARGEFILE_SUPPORT
*((Py_off_t *)addr) = PyLong_AsLongLong(arg);
#else
*((Py_off_t *)addr) = PyLong_AsLong(arg);
#endif
if (PyErr_Occurred())
return 0;
return 1;
}
static PyObject *
PyLong_FromPy_off_t(Py_off_t offset)
{
#ifdef HAVE_LARGEFILE_SUPPORT
return PyLong_FromLongLong(offset);
#else
return PyLong_FromLong(offset);
#endif
}
#if defined _MSC_VER && _MSC_VER >= 1400
/* Microsoft CRT in VS2005 and higher will verify that a filehandle is
* valid and raise an assertion if it isn't.
* Normally, an invalid fd is likely to be a C program error and therefore
* an assertion can be useful, but it does contradict the POSIX standard
* which for write(2) states:
* "Otherwise, -1 shall be returned and errno set to indicate the error."
* "[EBADF] The fildes argument is not a valid file descriptor open for
* writing."
* Furthermore, python allows the user to enter any old integer
* as a fd and should merely raise a python exception on error.
* The Microsoft CRT doesn't provide an official way to check for the
* validity of a file descriptor, but we can emulate its internal behaviour
* by using the exported __pinfo data member and knowledge of the
* internal structures involved.
* The structures below must be updated for each version of visual studio
* according to the file internal.h in the CRT source, until MS comes
* up with a less hacky way to do this.
* (all of this is to avoid globally modifying the CRT behaviour using
* _set_invalid_parameter_handler() and _CrtSetReportMode())
*/
/* The actual size of the structure is determined at runtime.
* Only the first items must be present.
*/
typedef struct {
intptr_t osfhnd;
char osfile;
} my_ioinfo;
extern __declspec(dllimport) char * __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define IOINFO_ARRAYS 64
#define _NHANDLE_ (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)
#define FOPEN 0x01
#define _NO_CONSOLE_FILENO (intptr_t)-2
/* This function emulates what the windows CRT does to validate file handles */
int
_PyVerify_fd(int fd)
{
const int i1 = fd >> IOINFO_L2E;
const int i2 = fd & ((1 << IOINFO_L2E) - 1);
static size_t sizeof_ioinfo = 0;
/* Determine the actual size of the ioinfo structure,
* as used by the CRT loaded in memory
*/
if (sizeof_ioinfo == 0 && __pioinfo[0] != NULL) {
sizeof_ioinfo = _msize(__pioinfo[0]) / IOINFO_ARRAY_ELTS;
}
if (sizeof_ioinfo == 0) {
/* This should not happen... */
goto fail;
}
/* See that it isn't a special CLEAR fileno */
if (fd != _NO_CONSOLE_FILENO) {
/* Microsoft CRT would check that 0<=fd<_nhandle but we can't do that. Instead
* we check pointer validity and other info
*/
if (0 <= i1 && i1 < IOINFO_ARRAYS && __pioinfo[i1] != NULL) {
/* finally, check that the file is open */
my_ioinfo* info = (my_ioinfo*)(__pioinfo[i1] + i2 * sizeof_ioinfo);
if (info->osfile & FOPEN) {
return 1;
}
}
}
fail:
errno = EBADF;
return 0;
}
/* the special case of checking dup2. The target fd must be in a sensible range */
static int
_PyVerify_fd_dup2(int fd1, int fd2)
{
if (!_PyVerify_fd(fd1))
return 0;
if (fd2 == _NO_CONSOLE_FILENO)
return 0;
if ((unsigned)fd2 < _NHANDLE_)
return 1;
else
return 0;
}
#else
/* dummy version. _PyVerify_fd() is already defined in fileobject.h */
#define _PyVerify_fd_dup2(A, B) (1)
#endif
#ifdef MS_WINDOWS
static int
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
{
char target_buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER *)target_buffer;
DWORD n_bytes_returned;
if (0 == DeviceIoControl(
reparse_point_handle,
FSCTL_GET_REPARSE_POINT,
NULL, 0, /* in buffer */
target_buffer, sizeof(target_buffer),
&n_bytes_returned,
NULL)) /* we're not using OVERLAPPED_IO */
return FALSE;
if (reparse_tag)
*reparse_tag = rdb->ReparseTag;
return TRUE;
}
#endif /* MS_WINDOWS */
/* Return a dictionary corresponding to the POSIX environment table */
#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
/* On Darwin/MacOSX a shared library or framework has no access to
** environ directly, we must obtain it with _NSGetEnviron(). See also
** man environ(7).
*/
#include <crt_externs.h>
static char **environ;
#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
extern char **environ;
#endif /* !_MSC_VER */
static PyObject *
convertenviron(void)
{
PyObject *d;
#ifdef MS_WINDOWS
wchar_t **e;
#else
char **e;
#endif
d = PyDict_New();
if (d == NULL)
return NULL;
#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
if (environ == NULL)
environ = *_NSGetEnviron();
#endif
#ifdef MS_WINDOWS
/* _wenviron must be initialized in this way if the program is started
through main() instead of wmain(). */
_wgetenv(L"");
if (_wenviron == NULL)
return d;
/* This part ignores errors */
for (e = _wenviron; *e != NULL; e++) {
PyObject *k;
PyObject *v;
wchar_t *p = wcschr(*e, L'=');
if (p == NULL)
continue;
k = PyUnicode_FromWideChar(*e, (Py_ssize_t)(p-*e));
if (k == NULL) {
PyErr_Clear();
continue;
}
v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
if (v == NULL) {
PyErr_Clear();
Py_DECREF(k);
continue;
}
if (PyDict_GetItem(d, k) == NULL) {
if (PyDict_SetItem(d, k, v) != 0)
PyErr_Clear();
}
Py_DECREF(k);
Py_DECREF(v);
}
#else
if (environ == NULL)
return d;
/* This part ignores errors */
for (e = environ; *e != NULL; e++) {
PyObject *k;
PyObject *v;
char *p = strchr(*e, '=');
if (p == NULL)
continue;
k = PyBytes_FromStringAndSize(*e, (int)(p-*e));
if (k == NULL) {
PyErr_Clear();
continue;
}
v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
if (v == NULL) {
PyErr_Clear();
Py_DECREF(k);
continue;
}
if (PyDict_GetItem(d, k) == NULL) {
if (PyDict_SetItem(d, k, v) != 0)
PyErr_Clear();
}
Py_DECREF(k);
Py_DECREF(v);
}
#endif
return d;
}
/* Set a POSIX-specific error from errno, and return NULL */
static PyObject *
posix_error(void)
{
return PyErr_SetFromErrno(PyExc_OSError);
}
#ifdef MS_WINDOWS
static PyObject *
win32_error(char* function, const char* filename)
{
/* XXX We should pass the function name along in the future.
(winreg.c also wants to pass the function name.)
This would however require an additional param to the
Windows error object, which is non-trivial.
*/
errno = GetLastError();
if (filename)
return PyErr_SetFromWindowsErrWithFilename(errno, filename);
else
return PyErr_SetFromWindowsErr(errno);
}
static PyObject *
win32_error_object(char* function, PyObject* filename)
{
/* XXX - see win32_error for comments on 'function' */
errno = GetLastError();
if (filename)
return PyErr_SetExcFromWindowsErrWithFilenameObject(
PyExc_OSError,
errno,
filename);
else
return PyErr_SetFromWindowsErr(errno);
}
#endif /* MS_WINDOWS */
static PyObject *
path_error(path_t *path)
{
#ifdef MS_WINDOWS
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError,
0, path->object);
#else
return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
#endif
}
static PyObject *
path_error2(path_t *path, path_t *path2)
{
#ifdef MS_WINDOWS
return PyErr_SetExcFromWindowsErrWithFilenameObjects(PyExc_OSError,
0, path->object, path2->object);
#else
return PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError,
path->object, path2->object);
#endif
}
/* POSIX generic methods */
static int
fildes_converter(PyObject *o, void *p)
{
int fd;
int *pointer = (int *)p;
fd = PyObject_AsFileDescriptor(o);
if (fd < 0)
return 0;
if (!_PyVerify_fd(fd)) {
posix_error();
return 0;
}
*pointer = fd;
return 1;
}
static PyObject *
posix_fildes_fd(int fd, int (*func)(int))
{
int res;
Py_BEGIN_ALLOW_THREADS
res = (*func)(fd);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
Py_INCREF(Py_None);
return Py_None;
}
#ifdef MS_WINDOWS
/* This is a reimplementation of the C library's chdir function,
but one that produces Win32 errors instead of DOS error codes.
chdir is essentially a wrapper around SetCurrentDirectory; however,
it also needs to set "magic" environment variables indicating
the per-drive current directory, which are of the form =<drive>: */
static BOOL __stdcall
win32_chdir(LPCSTR path)
{
char new_path[MAX_PATH];
int result;
char env[4] = "=x:";
if(!SetCurrentDirectoryA(path))
return FALSE;
result = GetCurrentDirectoryA(Py_ARRAY_LENGTH(new_path), new_path);
if (!result)
return FALSE;
/* In the ANSI API, there should not be any paths longer
than MAX_PATH-1 (not including the final null character). */
assert(result < Py_ARRAY_LENGTH(new_path));
if (strncmp(new_path, "\\\\", 2) == 0 ||
strncmp(new_path, "//", 2) == 0)
/* UNC path, nothing to do. */
return TRUE;
env[1] = new_path[0];
return SetEnvironmentVariableA(env, new_path);
}
/* The Unicode version differs from the ANSI version
since the current directory might exceed MAX_PATH characters */
static BOOL __stdcall
win32_wchdir(LPCWSTR path)
{
wchar_t _new_path[MAX_PATH], *new_path = _new_path;
int result;
wchar_t env[4] = L"=x:";
if(!SetCurrentDirectoryW(path))
return FALSE;
result = GetCurrentDirectoryW(Py_ARRAY_LENGTH(new_path), new_path);
if (!result)
return FALSE;
if (result > Py_ARRAY_LENGTH(new_path)) {
new_path = PyMem_RawMalloc(result * sizeof(wchar_t));
if (!new_path) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
result = GetCurrentDirectoryW(result, new_path);
if (!result) {
PyMem_RawFree(new_path);
return FALSE;
}
}
if (wcsncmp(new_path, L"\\\\", 2) == 0 ||
wcsncmp(new_path, L"//", 2) == 0)
/* UNC path, nothing to do. */
return TRUE;
env[1] = new_path[0];
result = SetEnvironmentVariableW(env, new_path);
if (new_path != _new_path)
PyMem_RawFree(new_path);
return result;
}
#endif
#ifdef MS_WINDOWS
/* The CRT of Windows has a number of flaws wrt. its stat() implementation:
- time stamps are restricted to second resolution
- file modification times suffer from forth-and-back conversions between
UTC and local time
Therefore, we implement our own stat, based on the Win32 API directly.
*/
#define HAVE_STAT_NSEC 1
#define HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES 1
struct win32_stat{
unsigned long st_dev;
__int64 st_ino;
unsigned short st_mode;
int st_nlink;
int st_uid;
int st_gid;
unsigned long st_rdev;
__int64 st_size;
time_t st_atime;
int st_atime_nsec;
time_t st_mtime;
int st_mtime_nsec;
time_t st_ctime;
int st_ctime_nsec;
unsigned long st_file_attributes;
};
static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
static void
FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out)
{
/* XXX endianness. Shouldn't matter, as all Windows implementations are little-endian */
/* Cannot simply cast and dereference in_ptr,
since it might not be aligned properly */
__int64 in;
memcpy(&in, in_ptr, sizeof(in));
*nsec_out = (int)(in % 10000000) * 100; /* FILETIME is in units of 100 nsec. */
*time_out = Py_SAFE_DOWNCAST((in / 10000000) - secs_between_epochs, __int64, time_t);
}
static void
time_t_to_FILE_TIME(time_t time_in, int nsec_in, FILETIME *out_ptr)
{
/* XXX endianness */
__int64 out;
out = time_in + secs_between_epochs;
out = out * 10000000 + nsec_in / 100;
memcpy(out_ptr, &out, sizeof(out));
}
/* Below, we *know* that ugo+r is 0444 */
#if _S_IREAD != 0400
#error Unsupported C library
#endif
static int
attributes_to_mode(DWORD attr)
{
int m = 0;
if (attr & FILE_ATTRIBUTE_DIRECTORY)
m |= _S_IFDIR | 0111; /* IFEXEC for user,group,other */
else
m |= _S_IFREG;
if (attr & FILE_ATTRIBUTE_READONLY)
m |= 0444;
else
m |= 0666;
return m;
}
static int
attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, struct win32_stat *result)
{
memset(result, 0, sizeof(*result));
result->st_mode = attributes_to_mode(info->dwFileAttributes);
result->st_size = (((__int64)info->nFileSizeHigh)<<32) + info->nFileSizeLow;
result->st_dev = info->dwVolumeSerialNumber;
result->st_rdev = result->st_dev;
FILE_TIME_to_time_t_nsec(&info->ftCreationTime, &result->st_ctime, &result->st_ctime_nsec);
FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec);
FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec);
result->st_nlink = info->nNumberOfLinks;
result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow;
if (reparse_tag == IO_REPARSE_TAG_SYMLINK) {
/* first clear the S_IFMT bits */
result->st_mode ^= (result->st_mode & S_IFMT);
/* now set the bits that make this a symlink */
result->st_mode |= S_IFLNK;
}
result->st_file_attributes = info->dwFileAttributes;
return 0;
}
static BOOL
attributes_from_dir(LPCSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag)
{
HANDLE hFindFile;
WIN32_FIND_DATAA FileData;
hFindFile = FindFirstFileA(pszFile, &FileData);
if (hFindFile == INVALID_HANDLE_VALUE)
return FALSE;
FindClose(hFindFile);
memset(info, 0, sizeof(*info));
*reparse_tag = 0;
info->dwFileAttributes = FileData.dwFileAttributes;
info->ftCreationTime = FileData.ftCreationTime;
info->ftLastAccessTime = FileData.ftLastAccessTime;
info->ftLastWriteTime = FileData.ftLastWriteTime;
info->nFileSizeHigh = FileData.nFileSizeHigh;
info->nFileSizeLow = FileData.nFileSizeLow;
/* info->nNumberOfLinks = 1; */
if (FileData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
*reparse_tag = FileData.dwReserved0;
return TRUE;
}
static BOOL
attributes_from_dir_w(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag)
{
HANDLE hFindFile;
WIN32_FIND_DATAW FileData;
hFindFile = FindFirstFileW(pszFile, &FileData);
if (hFindFile == INVALID_HANDLE_VALUE)
return FALSE;
FindClose(hFindFile);
memset(info, 0, sizeof(*info));
*reparse_tag = 0;
info->dwFileAttributes = FileData.dwFileAttributes;
info->ftCreationTime = FileData.ftCreationTime;
info->ftLastAccessTime = FileData.ftLastAccessTime;
info->ftLastWriteTime = FileData.ftLastWriteTime;
info->nFileSizeHigh = FileData.nFileSizeHigh;
info->nFileSizeLow = FileData.nFileSizeLow;
/* info->nNumberOfLinks = 1; */
if (FileData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
*reparse_tag = FileData.dwReserved0;
return TRUE;
}
/* Grab GetFinalPathNameByHandle dynamically from kernel32 */
static int has_GetFinalPathNameByHandle = -1;
static DWORD (CALLBACK *Py_GetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD,
DWORD);
static int
check_GetFinalPathNameByHandle()
{
HINSTANCE hKernel32;
DWORD (CALLBACK *Py_GetFinalPathNameByHandleA)(HANDLE, LPSTR, DWORD,
DWORD);
/* only recheck */
if (-1 == has_GetFinalPathNameByHandle)
{
hKernel32 = GetModuleHandleW(L"KERNEL32");
*(FARPROC*)&Py_GetFinalPathNameByHandleA = GetProcAddress(hKernel32,
"GetFinalPathNameByHandleA");
*(FARPROC*)&Py_GetFinalPathNameByHandleW = GetProcAddress(hKernel32,
"GetFinalPathNameByHandleW");
has_GetFinalPathNameByHandle = Py_GetFinalPathNameByHandleA &&
Py_GetFinalPathNameByHandleW;
}
return has_GetFinalPathNameByHandle;
}
static BOOL
get_target_path(HANDLE hdl, wchar_t **target_path)
{
int buf_size, result_length;
wchar_t *buf;
/* We have a good handle to the target, use it to determine
the target path name (then we'll call lstat on it). */
buf_size = Py_GetFinalPathNameByHandleW(hdl, 0, 0,
VOLUME_NAME_DOS);
if(!buf_size)
return FALSE;
buf = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t));
if (!buf) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
result_length = Py_GetFinalPathNameByHandleW(hdl,
buf, buf_size, VOLUME_NAME_DOS);
if(!result_length) {
PyMem_Free(buf);
return FALSE;
}
if(!CloseHandle(hdl)) {
PyMem_Free(buf);
return FALSE;
}
buf[result_length] = 0;
*target_path = buf;
return TRUE;
}
static int
win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
BOOL traverse);
static int
win32_xstat_impl(const char *path, struct win32_stat *result,
BOOL traverse)
{
int code;
HANDLE hFile, hFile2;
BY_HANDLE_FILE_INFORMATION info;
ULONG reparse_tag = 0;
wchar_t *target_path;
const char *dot;
if(!check_GetFinalPathNameByHandle()) {
/* If the OS doesn't have GetFinalPathNameByHandle, don't
traverse reparse point. */
traverse = FALSE;
}
hFile = CreateFileA(
path,
FILE_READ_ATTRIBUTES, /* desired access */
0, /* share mode */
NULL, /* security attributes */
OPEN_EXISTING,
/* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
/* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink.
Because of this, calls like GetFinalPathNameByHandle will return
the symlink path again and not the actual final path. */
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS|
FILE_FLAG_OPEN_REPARSE_POINT,
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
/* Either the target doesn't exist, or we don't have access to
get a handle to it. If the former, we need to return an error.
If the latter, we can use attributes_from_dir. */
if (GetLastError() != ERROR_SHARING_VIOLATION)
return -1;
/* Could not get attributes on open file. Fall back to
reading the directory. */
if (!attributes_from_dir(path, &info, &reparse_tag))
/* Very strange. This should not fail now */
return -1;
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (traverse) {
/* Should traverse, but could not open reparse point handle */
SetLastError(ERROR_SHARING_VIOLATION);
return -1;
}
}
} else {
if (!GetFileInformationByHandle(hFile, &info)) {
CloseHandle(hFile);
return -1;
}
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (!win32_get_reparse_tag(hFile, &reparse_tag))
return -1;
/* Close the outer open file handle now that we're about to
reopen it with different flags. */
if (!CloseHandle(hFile))
return -1;
if (traverse) {
/* In order to call GetFinalPathNameByHandle we need to open
the file without the reparse handling flag set. */
hFile2 = CreateFileA(
path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if (hFile2 == INVALID_HANDLE_VALUE)
return -1;
if (!get_target_path(hFile2, &target_path))
return -1;
code = win32_xstat_impl_w(target_path, result, FALSE);
PyMem_Free(target_path);
return code;
}
} else
CloseHandle(hFile);
}
attribute_data_to_stat(&info, reparse_tag, result);
/* Set S_IEXEC if it is an .exe, .bat, ... */
dot = strrchr(path, '.');
if (dot) {
if (stricmp(dot, ".bat") == 0 || stricmp(dot, ".cmd") == 0 ||
stricmp(dot, ".exe") == 0 || stricmp(dot, ".com") == 0)
result->st_mode |= 0111;
}
return 0;
}
static int
win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
BOOL traverse)
{
int code;
HANDLE hFile, hFile2;
BY_HANDLE_FILE_INFORMATION info;
ULONG reparse_tag = 0;
wchar_t *target_path;
const wchar_t *dot;
if(!check_GetFinalPathNameByHandle()) {
/* If the OS doesn't have GetFinalPathNameByHandle, don't
traverse reparse point. */
traverse = FALSE;
}
hFile = CreateFileW(
path,
FILE_READ_ATTRIBUTES, /* desired access */
0, /* share mode */
NULL, /* security attributes */
OPEN_EXISTING,
/* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
/* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink.
Because of this, calls like GetFinalPathNameByHandle will return
the symlink path again and not the actual final path. */
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS|
FILE_FLAG_OPEN_REPARSE_POINT,
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
/* Either the target doesn't exist, or we don't have access to
get a handle to it. If the former, we need to return an error.
If the latter, we can use attributes_from_dir. */
if (GetLastError() != ERROR_SHARING_VIOLATION)
return -1;
/* Could not get attributes on open file. Fall back to
reading the directory. */
if (!attributes_from_dir_w(path, &info, &reparse_tag))
/* Very strange. This should not fail now */
return -1;
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (traverse) {
/* Should traverse, but could not open reparse point handle */
SetLastError(ERROR_SHARING_VIOLATION);
return -1;
}
}
} else {
if (!GetFileInformationByHandle(hFile, &info)) {
CloseHandle(hFile);
return -1;
}
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (!win32_get_reparse_tag(hFile, &reparse_tag))
return -1;
/* Close the outer open file handle now that we're about to
reopen it with different flags. */
if (!CloseHandle(hFile))
return -1;
if (traverse) {
/* In order to call GetFinalPathNameByHandle we need to open
the file without the reparse handling flag set. */
hFile2 = CreateFileW(
path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if (hFile2 == INVALID_HANDLE_VALUE)
return -1;
if (!get_target_path(hFile2, &target_path))
return -1;
code = win32_xstat_impl_w(target_path, result, FALSE);
PyMem_Free(target_path);
return code;
}
} else
CloseHandle(hFile);
}
attribute_data_to_stat(&info, reparse_tag, result);
/* Set S_IEXEC if it is an .exe, .bat, ... */
dot = wcsrchr(path, '.');
if (dot) {
if (_wcsicmp(dot, L".bat") == 0 || _wcsicmp(dot, L".cmd") == 0 ||
_wcsicmp(dot, L".exe") == 0 || _wcsicmp(dot, L".com") == 0)
result->st_mode |= 0111;
}
return 0;
}
static int
win32_xstat(const char *path, struct win32_stat *result, BOOL traverse)
{
/* Protocol violation: we explicitly clear errno, instead of
setting it to a POSIX error. Callers should use GetLastError. */
int code = win32_xstat_impl(path, result, traverse);
errno = 0;
return code;
}
static int
win32_xstat_w(const wchar_t *path, struct win32_stat *result, BOOL traverse)
{
/* Protocol violation: we explicitly clear errno, instead of
setting it to a POSIX error. Callers should use GetLastError. */
int code = win32_xstat_impl_w(path, result, traverse);
errno = 0;
return code;
}
/* About the following functions: win32_lstat_w, win32_stat, win32_stat_w
In Posix, stat automatically traverses symlinks and returns the stat
structure for the target. In Windows, the equivalent GetFileAttributes by
default does not traverse symlinks and instead returns attributes for
the symlink.
Therefore, win32_lstat will get the attributes traditionally, and
win32_stat will first explicitly resolve the symlink target and then will
call win32_lstat on that result.
The _w represent Unicode equivalents of the aforementioned ANSI functions. */
static int
win32_lstat(const char* path, struct win32_stat *result)
{
return win32_xstat(path, result, FALSE);
}
static int
win32_lstat_w(const wchar_t* path, struct win32_stat *result)
{
return win32_xstat_w(path, result, FALSE);
}
static int
win32_stat(const char* path, struct win32_stat *result)
{
return win32_xstat(path, result, TRUE);
}
static int
win32_stat_w(const wchar_t* path, struct win32_stat *result)
{
return win32_xstat_w(path, result, TRUE);
}
static int
win32_fstat(int file_number, struct win32_stat *result)
{
BY_HANDLE_FILE_INFORMATION info;
HANDLE h;
int type;
if (!_PyVerify_fd(file_number))
h = INVALID_HANDLE_VALUE;
else
h = (HANDLE)_get_osfhandle(file_number);
/* Protocol violation: we explicitly clear errno, instead of
setting it to a POSIX error. Callers should use GetLastError. */
errno = 0;
if (h == INVALID_HANDLE_VALUE) {
/* This is really a C library error (invalid file handle).
We set the Win32 error to the closes one matching. */
SetLastError(ERROR_INVALID_HANDLE);
return -1;
}
memset(result, 0, sizeof(*result));
type = GetFileType(h);
if (type == FILE_TYPE_UNKNOWN) {
DWORD error = GetLastError();
if (error != 0) {
return -1;
}
/* else: valid but unknown file */
}
if (type != FILE_TYPE_DISK) {
if (type == FILE_TYPE_CHAR)
result->st_mode = _S_IFCHR;
else if (type == FILE_TYPE_PIPE)
result->st_mode = _S_IFIFO;
return 0;
}
if (!GetFileInformationByHandle(h, &info)) {
return -1;
}
attribute_data_to_stat(&info, 0, result);
/* specific to fstat() */
result->st_ino = (((__int64)info.nFileIndexHigh)<<32) + info.nFileIndexLow;
return 0;
}
#endif /* MS_WINDOWS */
PyDoc_STRVAR(stat_result__doc__,
"stat_result: Result from stat, fstat, or lstat.\n\n\
This object may be accessed either as a tuple of\n\
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\
or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\
\n\
Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,\n\
or st_flags, they are available as attributes only.\n\
\n\
See os.stat for more information.");
static PyStructSequence_Field stat_result_fields[] = {
{"st_mode", "protection bits"},
{"st_ino", "inode"},
{"st_dev", "device"},
{"st_nlink", "number of hard links"},
{"st_uid", "user ID of owner"},
{"st_gid", "group ID of owner"},
{"st_size", "total size, in bytes"},
/* The NULL is replaced with PyStructSequence_UnnamedField later. */
{NULL, "integer time of last access"},
{NULL, "integer time of last modification"},
{NULL, "integer time of last change"},
{"st_atime", "time of last access"},
{"st_mtime", "time of last modification"},
{"st_ctime", "time of last change"},
{"st_atime_ns", "time of last access in nanoseconds"},
{"st_mtime_ns", "time of last modification in nanoseconds"},
{"st_ctime_ns", "time of last change in nanoseconds"},
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
{"st_blksize", "blocksize for filesystem I/O"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
{"st_blocks", "number of blocks allocated"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
{"st_rdev", "device type (if inode device)"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
{"st_flags", "user defined flags for file"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
{"st_gen", "generation number"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
{"st_birthtime", "time of creation"},
#endif
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
{"st_file_attributes", "Windows file attribute bits"},
#endif
{0}
};
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
#define ST_BLKSIZE_IDX 16
#else
#define ST_BLKSIZE_IDX 15
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
#define ST_BLOCKS_IDX (ST_BLKSIZE_IDX+1)
#else
#define ST_BLOCKS_IDX ST_BLKSIZE_IDX
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
#define ST_RDEV_IDX (ST_BLOCKS_IDX+1)
#else
#define ST_RDEV_IDX ST_BLOCKS_IDX
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
#define ST_FLAGS_IDX (ST_RDEV_IDX+1)
#else
#define ST_FLAGS_IDX ST_RDEV_IDX
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
#define ST_GEN_IDX (ST_FLAGS_IDX+1)
#else
#define ST_GEN_IDX ST_FLAGS_IDX
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
#define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
#else
#define ST_BIRTHTIME_IDX ST_GEN_IDX
#endif
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
#define ST_FILE_ATTRIBUTES_IDX (ST_BIRTHTIME_IDX+1)
#else
#define ST_FILE_ATTRIBUTES_IDX ST_BIRTHTIME_IDX
#endif
static PyStructSequence_Desc stat_result_desc = {
"stat_result", /* name */
stat_result__doc__, /* doc */
stat_result_fields,
10
};
PyDoc_STRVAR(statvfs_result__doc__,
"statvfs_result: Result from statvfs or fstatvfs.\n\n\
This object may be accessed either as a tuple of\n\
(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),\n\
or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.\n\
\n\
See os.statvfs for more information.");
static PyStructSequence_Field statvfs_result_fields[] = {
{"f_bsize", },
{"f_frsize", },
{"f_blocks", },
{"f_bfree", },
{"f_bavail", },
{"f_files", },
{"f_ffree", },
{"f_favail", },
{"f_flag", },
{"f_namemax",},
{0}
};
static PyStructSequence_Desc statvfs_result_desc = {
"statvfs_result", /* name */
statvfs_result__doc__, /* doc */
statvfs_result_fields,
10
};
#if defined(HAVE_WAITID) && !defined(__APPLE__)
PyDoc_STRVAR(waitid_result__doc__,
"waitid_result: Result from waitid.\n\n\
This object may be accessed either as a tuple of\n\
(si_pid, si_uid, si_signo, si_status, si_code),\n\
or via the attributes si_pid, si_uid, and so on.\n\
\n\
See os.waitid for more information.");
static PyStructSequence_Field waitid_result_fields[] = {
{"si_pid", },
{"si_uid", },
{"si_signo", },
{"si_status", },
{"si_code", },
{0}
};
static PyStructSequence_Desc waitid_result_desc = {
"waitid_result", /* name */
waitid_result__doc__, /* doc */
waitid_result_fields,
5
};
static PyTypeObject WaitidResultType;
#endif
static int initialized;
static PyTypeObject StatResultType;
static PyTypeObject StatVFSResultType;
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
static PyTypeObject SchedParamType;
#endif
static newfunc structseq_new;
static PyObject *
statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyStructSequence *result;
int i;
result = (PyStructSequence*)structseq_new(type, args, kwds);
if (!result)
return NULL;
/* If we have been initialized from a tuple,
st_?time might be set to None. Initialize it
from the int slots. */
for (i = 7; i <= 9; i++) {
if (result->ob_item[i+3] == Py_None) {
Py_DECREF(Py_None);
Py_INCREF(result->ob_item[i]);
result->ob_item[i+3] = result->ob_item[i];
}
}
return (PyObject*)result;
}
/* If true, st_?time is float. */
static int _stat_float_times = 1;
PyDoc_STRVAR(stat_float_times__doc__,
"stat_float_times([newval]) -> oldval\n\n\
Determine whether os.[lf]stat represents time stamps as float objects.\n\
\n\
If value is True, future calls to stat() return floats; if it is False,\n\
future calls return ints.\n\
If value is omitted, return the current setting.\n");
/* AC 3.5: the public default value should be None, not ready for that yet */
static PyObject*
stat_float_times(PyObject* self, PyObject *args)
{
int newval = -1;
if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
return NULL;
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"stat_float_times() is deprecated",
1))
return NULL;
if (newval == -1)
/* Return old value */
return PyBool_FromLong(_stat_float_times);
_stat_float_times = newval;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *billion = NULL;
static void
fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
{
PyObject *s = _PyLong_FromTime_t(sec);
PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
PyObject *s_in_ns = NULL;
PyObject *ns_total = NULL;
PyObject *float_s = NULL;
if (!(s && ns_fractional))
goto exit;
s_in_ns = PyNumber_Multiply(s, billion);
if (!s_in_ns)
goto exit;
ns_total = PyNumber_Add(s_in_ns, ns_fractional);
if (!ns_total)
goto exit;
if (_stat_float_times) {
float_s = PyFloat_FromDouble(sec + 1e-9*nsec);
if (!float_s)
goto exit;
}
else {
float_s = s;
Py_INCREF(float_s);
}
PyStructSequence_SET_ITEM(v, index, s);
PyStructSequence_SET_ITEM(v, index+3, float_s);
PyStructSequence_SET_ITEM(v, index+6, ns_total);
s = NULL;
float_s = NULL;
ns_total = NULL;
exit:
Py_XDECREF(s);
Py_XDECREF(ns_fractional);
Py_XDECREF(s_in_ns);
Py_XDECREF(ns_total);
Py_XDECREF(float_s);
}
/* pack a system stat C structure into the Python stat tuple
(used by posix_stat() and posix_fstat()) */
static PyObject*
_pystat_fromstructstat(STRUCT_STAT *st)
{
unsigned long ansec, mnsec, cnsec;
PyObject *v = PyStructSequence_New(&StatResultType);
if (v == NULL)
return NULL;
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
#ifdef HAVE_LARGEFILE_SUPPORT
PyStructSequence_SET_ITEM(v, 1,
PyLong_FromLongLong((PY_LONG_LONG)st->st_ino));
#else
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
#endif
#ifdef MS_WINDOWS
PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
#elif defined(HAVE_LONG_LONG)
PyStructSequence_SET_ITEM(v, 2,
PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
#else
PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
#endif
PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
#if defined(MS_WINDOWS)
PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong(0));
PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong(0));
#else
PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid));
PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid));
#endif
#ifdef HAVE_LARGEFILE_SUPPORT
PyStructSequence_SET_ITEM(v, 6,
PyLong_FromLongLong((PY_LONG_LONG)st->st_size));
#else
PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size));
#endif
#if defined(HAVE_STAT_TV_NSEC)
ansec = st->st_atim.tv_nsec;
mnsec = st->st_mtim.tv_nsec;
cnsec = st->st_ctim.tv_nsec;
#elif defined(HAVE_STAT_TV_NSEC2)
ansec = st->st_atimespec.tv_nsec;
mnsec = st->st_mtimespec.tv_nsec;
cnsec = st->st_ctimespec.tv_nsec;
#elif defined(HAVE_STAT_NSEC)
ansec = st->st_atime_nsec;
mnsec = st->st_mtime_nsec;
cnsec = st->st_ctime_nsec;
#else
ansec = mnsec = cnsec = 0;
#endif
fill_time(v, 7, st->st_atime, ansec);
fill_time(v, 8, st->st_mtime, mnsec);
fill_time(v, 9, st->st_ctime, cnsec);
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
PyLong_FromLong((long)st->st_blksize));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
PyLong_FromLong((long)st->st_blocks));
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
PyLong_FromLong((long)st->st_rdev));
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
PyLong_FromLong((long)st->st_gen));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
{
PyObject *val;
unsigned long bsec,bnsec;
bsec = (long)st->st_birthtime;
#ifdef HAVE_STAT_TV_NSEC2
bnsec = st->st_birthtimespec.tv_nsec;
#else
bnsec = 0;
#endif
if (_stat_float_times) {
val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
} else {
val = PyLong_FromLong((long)bsec);
}
PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
val);
}
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
PyLong_FromLong((long)st->st_flags));
#endif
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
PyStructSequence_SET_ITEM(v, ST_FILE_ATTRIBUTES_IDX,
PyLong_FromUnsignedLong(st->st_file_attributes));
#endif
if (PyErr_Occurred()) {
Py_DECREF(v);
return NULL;
}
return v;
}
/* POSIX methods */
static PyObject *
posix_do_stat(char *function_name, path_t *path,
int dir_fd, int follow_symlinks)
{
STRUCT_STAT st;
int result;
#if !defined(MS_WINDOWS) && !defined(HAVE_FSTATAT) && !defined(HAVE_LSTAT)
if (follow_symlinks_specified(function_name, follow_symlinks))
return NULL;
#endif
if (path_and_dir_fd_invalid("stat", path, dir_fd) ||
dir_fd_and_fd_invalid("stat", dir_fd, path->fd) ||
fd_and_follow_symlinks_invalid("stat", path->fd, follow_symlinks))
return NULL;
Py_BEGIN_ALLOW_THREADS
if (path->fd != -1)
result = FSTAT(path->fd, &st);
else
#ifdef MS_WINDOWS
if (path->wide) {
if (follow_symlinks)
result = win32_stat_w(path->wide, &st);
else
result = win32_lstat_w(path->wide, &st);
}
else
#endif
#if defined(HAVE_LSTAT) || defined(MS_WINDOWS)
if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
result = LSTAT(path->narrow, &st);
else
#endif
#ifdef HAVE_FSTATAT
if ((dir_fd != DEFAULT_DIR_FD) || !follow_symlinks)
result = fstatat(dir_fd, path->narrow, &st,
follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
else
#endif
result = STAT(path->narrow, &st);
Py_END_ALLOW_THREADS
if (result != 0) {
return path_error(path);
}
return _pystat_fromstructstat(&st);
}
/*[python input]
for s in """
FACCESSAT
FCHMODAT
FCHOWNAT
FSTATAT
LINKAT
MKDIRAT
MKFIFOAT
MKNODAT
OPENAT
READLINKAT
SYMLINKAT
UNLINKAT
""".strip().split():
s = s.strip()
print("""
#ifdef HAVE_{s}
#define {s}_DIR_FD_CONVERTER dir_fd_converter
#else
#define {s}_DIR_FD_CONVERTER dir_fd_unavailable
#endif
""".rstrip().format(s=s))
for s in """
FCHDIR
FCHMOD
FCHOWN
FDOPENDIR
FEXECVE
FPATHCONF
FSTATVFS
FTRUNCATE
""".strip().split():
s = s.strip()
print("""
#ifdef HAVE_{s}
#define PATH_HAVE_{s} 1
#else
#define PATH_HAVE_{s} 0
#endif
""".rstrip().format(s=s))
[python start generated code]*/
#ifdef HAVE_FACCESSAT
#define FACCESSAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define FACCESSAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_FCHMODAT
#define FCHMODAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define FCHMODAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_FCHOWNAT
#define FCHOWNAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define FCHOWNAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_FSTATAT
#define FSTATAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define FSTATAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_LINKAT
#define LINKAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define LINKAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_MKDIRAT
#define MKDIRAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define MKDIRAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_MKFIFOAT
#define MKFIFOAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define MKFIFOAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_MKNODAT
#define MKNODAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define MKNODAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_OPENAT
#define OPENAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define OPENAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_READLINKAT
#define READLINKAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define READLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_SYMLINKAT
#define SYMLINKAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define SYMLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_UNLINKAT
#define UNLINKAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define UNLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#ifdef HAVE_FCHDIR
#define PATH_HAVE_FCHDIR 1
#else
#define PATH_HAVE_FCHDIR 0
#endif
#ifdef HAVE_FCHMOD
#define PATH_HAVE_FCHMOD 1
#else
#define PATH_HAVE_FCHMOD 0
#endif
#ifdef HAVE_FCHOWN
#define PATH_HAVE_FCHOWN 1
#else
#define PATH_HAVE_FCHOWN 0
#endif
#ifdef HAVE_FDOPENDIR
#define PATH_HAVE_FDOPENDIR 1
#else
#define PATH_HAVE_FDOPENDIR 0
#endif
#ifdef HAVE_FEXECVE
#define PATH_HAVE_FEXECVE 1
#else
#define PATH_HAVE_FEXECVE 0
#endif
#ifdef HAVE_FPATHCONF
#define PATH_HAVE_FPATHCONF 1
#else
#define PATH_HAVE_FPATHCONF 0
#endif
#ifdef HAVE_FSTATVFS
#define PATH_HAVE_FSTATVFS 1
#else
#define PATH_HAVE_FSTATVFS 0
#endif
#ifdef HAVE_FTRUNCATE
#define PATH_HAVE_FTRUNCATE 1
#else
#define PATH_HAVE_FTRUNCATE 0
#endif
/*[python end generated code: output=4bd4f6f7d41267f1 input=80b4c890b6774ea5]*/
/*[python input]
class path_t_converter(CConverter):
type = "path_t"
impl_by_reference = True
parse_by_reference = True
converter = 'path_converter'
def converter_init(self, *, allow_fd=False, nullable=False):
# right now path_t doesn't support default values.
# to support a default value, you'll need to override initialize().
if self.default not in (unspecified, None):
fail("Can't specify a default to the path_t converter!")
if self.c_default not in (None, 'Py_None'):
raise RuntimeError("Can't specify a c_default to the path_t converter!")
self.nullable = nullable
self.allow_fd = allow_fd
def pre_render(self):
def strify(value):
if isinstance(value, str):
return value
return str(int(bool(value)))
# add self.py_name here when merging with posixmodule conversion
self.c_default = 'PATH_T_INITIALIZE("{}", "{}", {}, {})'.format(
self.function.name,
self.name,
strify(self.nullable),
strify(self.allow_fd),
)
def cleanup(self):
return "path_cleanup(&" + self.name + ");\n"
class dir_fd_converter(CConverter):
type = 'int'
def converter_init(self, requires=None):
if self.default in (unspecified, None):
self.c_default = 'DEFAULT_DIR_FD'
if isinstance(requires, str):
self.converter = requires.upper() + '_DIR_FD_CONVERTER'
else:
self.converter = 'dir_fd_converter'
class fildes_converter(CConverter):
type = 'int'
converter = 'fildes_converter'
class uid_t_converter(CConverter):
type = "uid_t"
converter = '_Py_Uid_Converter'
class gid_t_converter(CConverter):
type = "gid_t"
converter = '_Py_Gid_Converter'
class FSConverter_converter(CConverter):
type = 'PyObject *'
converter = 'PyUnicode_FSConverter'
def converter_init(self):
if self.default is not unspecified:
fail("FSConverter_converter does not support default values")
self.c_default = 'NULL'
def cleanup(self):
return "Py_XDECREF(" + self.name + ");\n"
class pid_t_converter(CConverter):
type = 'pid_t'
format_unit = '" _Py_PARSE_PID "'
class idtype_t_converter(int_converter):
type = 'idtype_t'
class id_t_converter(CConverter):
type = 'id_t'
format_unit = '" _Py_PARSE_PID "'
class Py_intptr_t_converter(CConverter):
type = 'Py_intptr_t'
format_unit = '" _Py_PARSE_INTPTR "'
class Py_off_t_converter(CConverter):
type = 'Py_off_t'
converter = 'Py_off_t_converter'
class Py_off_t_return_converter(long_return_converter):
type = 'Py_off_t'
conversion_fn = 'PyLong_FromPy_off_t'
class path_confname_converter(CConverter):
type="int"
converter="conv_path_confname"
class confstr_confname_converter(path_confname_converter):
converter='conv_confstr_confname'
class sysconf_confname_converter(path_confname_converter):
converter="conv_sysconf_confname"
class sched_param_converter(CConverter):
type = 'struct sched_param'
converter = 'convert_sched_param'
impl_by_reference = True;
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=147ba8f52a05aca4]*/
/*[clinic input]
os.stat
path : path_t(allow_fd=True)
Path to be examined; can be string, bytes, or open-file-descriptor int.
*
dir_fd : dir_fd(requires='fstatat') = None
If not None, it should be a file descriptor open to a directory,
and path should be a relative string; path will then be relative to
that directory.
follow_symlinks: bool = True
If False, and the last element of the path is a symbolic link,
stat will examine the symbolic link itself instead of the file
the link points to.
Perform a stat system call on the given path.
dir_fd and follow_symlinks may not be implemented
on your platform. If they are unavailable, using them will raise a
NotImplementedError.
It's an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_stat__doc__,
"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
"--\n"
"\n"
"Perform a stat system call on the given path.\n"
"\n"
" path\n"
" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
" dir_fd\n"
" If not None, it should be a file descriptor open to a directory,\n"
" and path should be a relative string; path will then be relative to\n"
" that directory.\n"
" follow_symlinks\n"
" If False, and the last element of the path is a symbolic link,\n"
" stat will examine the symbolic link itself instead of the file\n"
" the link points to.\n"
"\n"
"dir_fd and follow_symlinks may not be implemented\n"
" on your platform. If they are unavailable, using them will raise a\n"
" NotImplementedError.\n"
"\n"
"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
" an open file descriptor.");
#define OS_STAT_METHODDEF \
{"stat", (PyCFunction)os_stat, METH_VARARGS|METH_KEYWORDS, os_stat__doc__},
static PyObject *
os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks);
static PyObject *
os_stat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
int dir_fd = DEFAULT_DIR_FD;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|$O&p:stat", _keywords,
path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
goto exit;
return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks)
/*[clinic end generated code: output=0e9f9508fa0c0607 input=099d356c306fa24a]*/
{
return posix_do_stat("stat", path, dir_fd, follow_symlinks);
}
/*[clinic input]
os.lstat
path : path_t
*
dir_fd : dir_fd(requires='fstatat') = None
Perform a stat system call on the given path, without following symbolic links.
Like stat(), but do not follow symbolic links.
Equivalent to stat(path, follow_symlinks=False).
[clinic start generated code]*/
PyDoc_STRVAR(os_lstat__doc__,
"lstat($module, /, path, *, dir_fd=None)\n"
"--\n"
"\n"
"Perform a stat system call on the given path, without following symbolic links.\n"
"\n"
"Like stat(), but do not follow symbolic links.\n"
"Equivalent to stat(path, follow_symlinks=False).");
#define OS_LSTAT_METHODDEF \
{"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__},
static PyObject *
os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd);
static PyObject *
os_lstat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|$O&:lstat", _keywords,
path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_lstat_impl(module, &path, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd)
/*[clinic end generated code: output=85702247224a2b1c input=0b7474765927b925]*/
{
int follow_symlinks = 0;
return posix_do_stat("lstat", path, dir_fd, follow_symlinks);
}
/*[clinic input]
os.access -> bool
path: path_t(allow_fd=True)
Path to be tested; can be string, bytes, or open-file-descriptor int.
mode: int
Operating-system mode bitfield. Can be F_OK to test existence,
or the inclusive-OR of R_OK, W_OK, and X_OK.
*
dir_fd : dir_fd(requires='faccessat') = None
If not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that
directory.
effective_ids: bool = False
If True, access will use the effective uid/gid instead of
the real uid/gid.
follow_symlinks: bool = True
If False, and the last element of the path is a symbolic link,
access will examine the symbolic link itself instead of the file
the link points to.
Use the real uid/gid to test for access to a path.
{parameters}
dir_fd, effective_ids, and follow_symlinks may not be implemented
on your platform. If they are unavailable, using them will raise a
NotImplementedError.
Note that most operations will use the effective uid/gid, therefore this
routine can be used in a suid/sgid environment to test if the invoking user
has the specified access to the path.
[clinic start generated code]*/
PyDoc_STRVAR(os_access__doc__,
"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
" follow_symlinks=True)\n"
"--\n"
"\n"
"Use the real uid/gid to test for access to a path.\n"
"\n"
" path\n"
" Path to be tested; can be string, bytes, or open-file-descriptor int.\n"
" mode\n"
" Operating-system mode bitfield. Can be F_OK to test existence,\n"
" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
" dir_fd\n"
" If not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that\n"
" directory.\n"
" effective_ids\n"
" If True, access will use the effective uid/gid instead of\n"
" the real uid/gid.\n"
" follow_symlinks\n"
" If False, and the last element of the path is a symbolic link,\n"
" access will examine the symbolic link itself instead of the file\n"
" the link points to.\n"
"\n"
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
" on your platform. If they are unavailable, using them will raise a\n"
" NotImplementedError.\n"
"\n"
"Note that most operations will use the effective uid/gid, therefore this\n"
" routine can be used in a suid/sgid environment to test if the invoking user\n"
" has the specified access to the path.");
#define OS_ACCESS_METHODDEF \
{"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__},
static int
os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks);
static PyObject *
os_access(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("access", "path", 0, 1);
int mode;
int dir_fd = DEFAULT_DIR_FD;
int effective_ids = 0;
int follow_symlinks = 1;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&i|$O&pp:access", _keywords,
path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks))
goto exit;
_return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static int
os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks)
/*[clinic end generated code: output=dfd404666906f012 input=b75a756797af45ec]*/
{
int return_value;
#ifdef MS_WINDOWS
DWORD attr;
#else
int result;
#endif
#ifndef HAVE_FACCESSAT
if (follow_symlinks_specified("access", follow_symlinks))
return -1;
if (effective_ids) {
argument_unavailable_error("access", "effective_ids");
return -1;
}
#endif
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (path->wide != NULL)
attr = GetFileAttributesW(path->wide);
else
attr = GetFileAttributesA(path->narrow);
Py_END_ALLOW_THREADS
/*
* Access is possible if
* * we didn't get a -1, and
* * write access wasn't requested,
* * or the file isn't read-only,
* * or it's a directory.
* (Directories cannot be read-only on Windows.)
*/
return_value = (attr != INVALID_FILE_ATTRIBUTES) &&
(!(mode & 2) ||
!(attr & FILE_ATTRIBUTE_READONLY) ||
(attr & FILE_ATTRIBUTE_DIRECTORY));
#else
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FACCESSAT
if ((dir_fd != DEFAULT_DIR_FD) ||
effective_ids ||
!follow_symlinks) {
int flags = 0;
if (!follow_symlinks)
flags |= AT_SYMLINK_NOFOLLOW;
if (effective_ids)
flags |= AT_EACCESS;
result = faccessat(dir_fd, path->narrow, mode, flags);
}
else
#endif
result = access(path->narrow, mode);
Py_END_ALLOW_THREADS
return_value = !result;
#endif
return return_value;
}
#ifndef F_OK
#define F_OK 0
#endif
#ifndef R_OK
#define R_OK 4
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifndef X_OK
#define X_OK 1
#endif
#ifdef HAVE_TTYNAME
/*[clinic input]
os.ttyname -> DecodeFSDefault
fd: int
Integer file descriptor handle.
/
Return the name of the terminal device connected to 'fd'.
[clinic start generated code]*/
PyDoc_STRVAR(os_ttyname__doc__,
"ttyname($module, fd, /)\n"
"--\n"
"\n"
"Return the name of the terminal device connected to \'fd\'.\n"
"\n"
" fd\n"
" Integer file descriptor handle.");
#define OS_TTYNAME_METHODDEF \
{"ttyname", (PyCFunction)os_ttyname, METH_VARARGS, os_ttyname__doc__},
static char *
os_ttyname_impl(PyModuleDef *module, int fd);
static PyObject *
os_ttyname(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
char *_return_value;
if (!PyArg_ParseTuple(args,
"i:ttyname",
&fd))
goto exit;
_return_value = os_ttyname_impl(module, fd);
if (_return_value == NULL)
goto exit;
return_value = PyUnicode_DecodeFSDefault(_return_value);
exit:
return return_value;
}
static char *
os_ttyname_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=cee7bc4cffec01a2 input=5f72ca83e76b3b45]*/
{
char *ret;
ret = ttyname(fd);
if (ret == NULL)
posix_error();
return ret;
}
#endif
#ifdef HAVE_CTERMID
/*[clinic input]
os.ctermid
Return the name of the controlling terminal for this process.
[clinic start generated code]*/
PyDoc_STRVAR(os_ctermid__doc__,
"ctermid($module, /)\n"
"--\n"
"\n"
"Return the name of the controlling terminal for this process.");
#define OS_CTERMID_METHODDEF \
{"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
static PyObject *
os_ctermid_impl(PyModuleDef *module);
static PyObject *
os_ctermid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_ctermid_impl(module);
}
static PyObject *
os_ctermid_impl(PyModuleDef *module)
/*[clinic end generated code: output=277bf7964ec2d782 input=3b87fdd52556382d]*/
{
char *ret;
char buffer[L_ctermid];
#ifdef USE_CTERMID_R
ret = ctermid_r(buffer);
#else
ret = ctermid(buffer);
#endif
if (ret == NULL)
return posix_error();
return PyUnicode_DecodeFSDefault(buffer);
}
#endif /* HAVE_CTERMID */
/*[clinic input]
os.chdir
path: path_t(allow_fd='PATH_HAVE_FCHDIR')
Change the current working directory to the specified path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
[clinic start generated code]*/
PyDoc_STRVAR(os_chdir__doc__,
"chdir($module, /, path)\n"
"--\n"
"\n"
"Change the current working directory to the specified path.\n"
"\n"
"path may always be specified as a string.\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.");
#define OS_CHDIR_METHODDEF \
{"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__},
static PyObject *
os_chdir_impl(PyModuleDef *module, path_t *path);
static PyObject *
os_chdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:chdir", _keywords,
path_converter, &path))
goto exit;
return_value = os_chdir_impl(module, &path);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_chdir_impl(PyModuleDef *module, path_t *path)
/*[clinic end generated code: output=cc07592dd23ca9e0 input=1a4a15b4d12cb15d]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if (path->wide)
result = win32_wchdir(path->wide);
else
result = win32_chdir(path->narrow);
result = !result; /* on unix, success = 0, on windows, success = !0 */
#else
#ifdef HAVE_FCHDIR
if (path->fd != -1)
result = fchdir(path->fd);
else
#endif
result = chdir(path->narrow);
#endif
Py_END_ALLOW_THREADS
if (result) {
return path_error(path);
}
Py_RETURN_NONE;
}
#ifdef HAVE_FCHDIR
/*[clinic input]
os.fchdir
fd: fildes
Change to the directory of the given file descriptor.
fd must be opened on a directory, not a file.
Equivalent to os.chdir(fd).
[clinic start generated code]*/
PyDoc_STRVAR(os_fchdir__doc__,
"fchdir($module, /, fd)\n"
"--\n"
"\n"
"Change to the directory of the given file descriptor.\n"
"\n"
"fd must be opened on a directory, not a file.\n"
"Equivalent to os.chdir(fd).");
#define OS_FCHDIR_METHODDEF \
{"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__},
static PyObject *
os_fchdir_impl(PyModuleDef *module, int fd);
static PyObject *
os_fchdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:fchdir", _keywords,
fildes_converter, &fd))
goto exit;
return_value = os_fchdir_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_fchdir_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=9f6dbc89b2778834 input=18e816479a2fa985]*/
{
return posix_fildes_fd(fd, fchdir);
}
#endif /* HAVE_FCHDIR */
/*[clinic input]
os.chmod
path: path_t(allow_fd='PATH_HAVE_FCHMOD')
Path to be modified. May always be specified as a str or bytes.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
mode: int
Operating-system mode bitfield.
*
dir_fd : dir_fd(requires='fchmodat') = None
If not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that
directory.
follow_symlinks: bool = True
If False, and the last element of the path is a symbolic link,
chmod will modify the symbolic link itself instead of the file
the link points to.
Change the access permissions of a file.
It is an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
dir_fd and follow_symlinks may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_chmod__doc__,
"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
"--\n"
"\n"
"Change the access permissions of a file.\n"
"\n"
" path\n"
" Path to be modified. May always be specified as a str or bytes.\n"
" On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.\n"
" mode\n"
" Operating-system mode bitfield.\n"
" dir_fd\n"
" If not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that\n"
" directory.\n"
" follow_symlinks\n"
" If False, and the last element of the path is a symbolic link,\n"
" chmod will modify the symbolic link itself instead of the file\n"
" the link points to.\n"
"\n"
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
" an open file descriptor.\n"
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
" If they are unavailable, using them will raise a NotImplementedError.");
#define OS_CHMOD_METHODDEF \
{"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__},
static PyObject *
os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int follow_symlinks);
static PyObject *
os_chmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
int mode;
int dir_fd = DEFAULT_DIR_FD;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&i|$O&p:chmod", _keywords,
path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
goto exit;
return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int follow_symlinks)
/*[clinic end generated code: output=1e9db031aea46422 input=7f1618e5e15cc196]*/
{
int result;
#ifdef MS_WINDOWS
DWORD attr;
#endif
#ifdef HAVE_FCHMODAT
int fchmodat_nofollow_unsupported = 0;
#endif
#if !(defined(HAVE_FCHMODAT) || defined(HAVE_LCHMOD))
if (follow_symlinks_specified("chmod", follow_symlinks))
return NULL;
#endif
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (path->wide)
attr = GetFileAttributesW(path->wide);
else
attr = GetFileAttributesA(path->narrow);
if (attr == INVALID_FILE_ATTRIBUTES)
result = 0;
else {
if (mode & _S_IWRITE)
attr &= ~FILE_ATTRIBUTE_READONLY;
else
attr |= FILE_ATTRIBUTE_READONLY;
if (path->wide)
result = SetFileAttributesW(path->wide, attr);
else
result = SetFileAttributesA(path->narrow, attr);
}
Py_END_ALLOW_THREADS
if (!result) {
return path_error(path);
}
#else /* MS_WINDOWS */
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FCHMOD
if (path->fd != -1)
result = fchmod(path->fd, mode);
else
#endif
#ifdef HAVE_LCHMOD
if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
result = lchmod(path->narrow, mode);
else
#endif
#ifdef HAVE_FCHMODAT
if ((dir_fd != DEFAULT_DIR_FD) || !follow_symlinks) {
/*
* fchmodat() doesn't currently support AT_SYMLINK_NOFOLLOW!
* The documentation specifically shows how to use it,
* and then says it isn't implemented yet.
* (true on linux with glibc 2.15, and openindiana 3.x)
*
* Once it is supported, os.chmod will automatically
* support dir_fd and follow_symlinks=False. (Hopefully.)
* Until then, we need to be careful what exception we raise.
*/
result = fchmodat(dir_fd, path->narrow, mode,
follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
/*
* But wait! We can't throw the exception without allowing threads,
* and we can't do that in this nested scope. (Macro trickery, sigh.)
*/
fchmodat_nofollow_unsupported =
result &&
((errno == ENOTSUP) || (errno == EOPNOTSUPP)) &&
!follow_symlinks;
}
else
#endif
result = chmod(path->narrow, mode);
Py_END_ALLOW_THREADS
if (result) {
#ifdef HAVE_FCHMODAT
if (fchmodat_nofollow_unsupported) {
if (dir_fd != DEFAULT_DIR_FD)
dir_fd_and_follow_symlinks_invalid("chmod",
dir_fd, follow_symlinks);
else
follow_symlinks_specified("chmod", follow_symlinks);
}
else
#endif
return path_error(path);
}
#endif
Py_RETURN_NONE;
}
#ifdef HAVE_FCHMOD
/*[clinic input]
os.fchmod
fd: int
mode: int
Change the access permissions of the file given by file descriptor fd.
Equivalent to os.chmod(fd, mode).
[clinic start generated code]*/
PyDoc_STRVAR(os_fchmod__doc__,
"fchmod($module, /, fd, mode)\n"
"--\n"
"\n"
"Change the access permissions of the file given by file descriptor fd.\n"
"\n"
"Equivalent to os.chmod(fd, mode).");
#define OS_FCHMOD_METHODDEF \
{"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__},
static PyObject *
os_fchmod_impl(PyModuleDef *module, int fd, int mode);
static PyObject *
os_fchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", "mode", NULL};
int fd;
int mode;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"ii:fchmod", _keywords,
&fd, &mode))
goto exit;
return_value = os_fchmod_impl(module, fd, mode);
exit:
return return_value;
}
static PyObject *
os_fchmod_impl(PyModuleDef *module, int fd, int mode)
/*[clinic end generated code: output=3c19fbfd724a8e0f input=8ab11975ca01ee5b]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = fchmod(fd, mode);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_FCHMOD */
#ifdef HAVE_LCHMOD
/*[clinic input]
os.lchmod
path: path_t
mode: int
Change the access permissions of a file, without following symbolic links.
If path is a symlink, this affects the link itself rather than the target.
Equivalent to chmod(path, mode, follow_symlinks=False)."
[clinic start generated code]*/
PyDoc_STRVAR(os_lchmod__doc__,
"lchmod($module, /, path, mode)\n"
"--\n"
"\n"
"Change the access permissions of a file, without following symbolic links.\n"
"\n"
"If path is a symlink, this affects the link itself rather than the target.\n"
"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
#define OS_LCHMOD_METHODDEF \
{"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__},
static PyObject *
os_lchmod_impl(PyModuleDef *module, path_t *path, int mode);
static PyObject *
os_lchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", NULL};
path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
int mode;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&i:lchmod", _keywords,
path_converter, &path, &mode))
goto exit;
return_value = os_lchmod_impl(module, &path, mode);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_lchmod_impl(PyModuleDef *module, path_t *path, int mode)
/*[clinic end generated code: output=2849977d65f8c68c input=90c5663c7465d24f]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = lchmod(path->narrow, mode);
Py_END_ALLOW_THREADS
if (res < 0) {
path_error(path);
return NULL;
}
Py_RETURN_NONE;
}
#endif /* HAVE_LCHMOD */
#ifdef HAVE_CHFLAGS
/*[clinic input]
os.chflags
path: path_t
flags: unsigned_long(bitwise=True)
follow_symlinks: bool=True
Set file flags.
If follow_symlinks is False, and the last element of the path is a symbolic
link, chflags will change flags on the symbolic link itself instead of the
file the link points to.
follow_symlinks may not be implemented on your platform. If it is
unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_chflags__doc__,
"chflags($module, /, path, flags, follow_symlinks=True)\n"
"--\n"
"\n"
"Set file flags.\n"
"\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, chflags will change flags on the symbolic link itself instead of the\n"
" file the link points to.\n"
"follow_symlinks may not be implemented on your platform. If it is\n"
"unavailable, using it will raise a NotImplementedError.");
#define OS_CHFLAGS_METHODDEF \
{"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__},
static PyObject *
os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags, int follow_symlinks);
static PyObject *
os_chflags(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "flags", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
unsigned long flags;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&k|p:chflags", _keywords,
path_converter, &path, &flags, &follow_symlinks))
goto exit;
return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags, int follow_symlinks)
/*[clinic end generated code: output=2767927bf071e3cf input=0327e29feb876236]*/
{
int result;
#ifndef HAVE_LCHFLAGS
if (follow_symlinks_specified("chflags", follow_symlinks))
return NULL;
#endif
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_LCHFLAGS
if (!follow_symlinks)
result = lchflags(path->narrow, flags);
else
#endif
result = chflags(path->narrow, flags);
Py_END_ALLOW_THREADS
if (result)
return path_error(path);
Py_RETURN_NONE;
}
#endif /* HAVE_CHFLAGS */
#ifdef HAVE_LCHFLAGS
/*[clinic input]
os.lchflags
path: path_t
flags: unsigned_long(bitwise=True)
Set file flags.
This function will not follow symbolic links.
Equivalent to chflags(path, flags, follow_symlinks=False).
[clinic start generated code]*/
PyDoc_STRVAR(os_lchflags__doc__,
"lchflags($module, /, path, flags)\n"
"--\n"
"\n"
"Set file flags.\n"
"\n"
"This function will not follow symbolic links.\n"
"Equivalent to chflags(path, flags, follow_symlinks=False).");
#define OS_LCHFLAGS_METHODDEF \
{"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__},
static PyObject *
os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags);
static PyObject *
os_lchflags(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "flags", NULL};
path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
unsigned long flags;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&k:lchflags", _keywords,
path_converter, &path, &flags))
goto exit;
return_value = os_lchflags_impl(module, &path, flags);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags)
/*[clinic end generated code: output=bb93b6b8a5e45aa7 input=f9f82ea8b585ca9d]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = lchflags(path->narrow, flags);
Py_END_ALLOW_THREADS
if (res < 0) {
return path_error(path);
}
Py_RETURN_NONE;
}
#endif /* HAVE_LCHFLAGS */
#ifdef HAVE_CHROOT
/*[clinic input]
os.chroot
path: path_t
Change root directory to path.
[clinic start generated code]*/
PyDoc_STRVAR(os_chroot__doc__,
"chroot($module, /, path)\n"
"--\n"
"\n"
"Change root directory to path.");
#define OS_CHROOT_METHODDEF \
{"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__},
static PyObject *
os_chroot_impl(PyModuleDef *module, path_t *path);
static PyObject *
os_chroot(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:chroot", _keywords,
path_converter, &path))
goto exit;
return_value = os_chroot_impl(module, &path);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_chroot_impl(PyModuleDef *module, path_t *path)
/*[clinic end generated code: output=15b1256cbe4f24a1 input=14822965652c3dc3]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = chroot(path->narrow);
Py_END_ALLOW_THREADS
if (res < 0)
return path_error(path);
Py_RETURN_NONE;
}
#endif /* HAVE_CHROOT */
#ifdef HAVE_FSYNC
/*[clinic input]
os.fsync
fd: fildes
Force write of fd to disk.
[clinic start generated code]*/
PyDoc_STRVAR(os_fsync__doc__,
"fsync($module, /, fd)\n"
"--\n"
"\n"
"Force write of fd to disk.");
#define OS_FSYNC_METHODDEF \
{"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__},
static PyObject *
os_fsync_impl(PyModuleDef *module, int fd);
static PyObject *
os_fsync(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:fsync", _keywords,
fildes_converter, &fd))
goto exit;
return_value = os_fsync_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_fsync_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=59f32d3a0b360133 input=21c3645c056967f2]*/
{
return posix_fildes_fd(fd, fsync);
}
#endif /* HAVE_FSYNC */
#ifdef HAVE_SYNC
/*[clinic input]
os.sync
Force write of everything to disk.
[clinic start generated code]*/
PyDoc_STRVAR(os_sync__doc__,
"sync($module, /)\n"
"--\n"
"\n"
"Force write of everything to disk.");
#define OS_SYNC_METHODDEF \
{"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
static PyObject *
os_sync_impl(PyModuleDef *module);
static PyObject *
os_sync(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_sync_impl(module);
}
static PyObject *
os_sync_impl(PyModuleDef *module)
/*[clinic end generated code: output=526c495683d0bb38 input=84749fe5e9b404ff]*/
{
Py_BEGIN_ALLOW_THREADS
sync();
Py_END_ALLOW_THREADS
Py_RETURN_NONE;
}
#endif /* HAVE_SYNC */
#ifdef HAVE_FDATASYNC
#ifdef __hpux
extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
#endif
/*[clinic input]
os.fdatasync
fd: fildes
Force write of fd to disk without forcing update of metadata.
[clinic start generated code]*/
PyDoc_STRVAR(os_fdatasync__doc__,
"fdatasync($module, /, fd)\n"
"--\n"
"\n"
"Force write of fd to disk without forcing update of metadata.");
#define OS_FDATASYNC_METHODDEF \
{"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__},
static PyObject *
os_fdatasync_impl(PyModuleDef *module, int fd);
static PyObject *
os_fdatasync(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:fdatasync", _keywords,
fildes_converter, &fd))
goto exit;
return_value = os_fdatasync_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_fdatasync_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=2335fdfd37c92180 input=bc74791ee54dd291]*/
{
return posix_fildes_fd(fd, fdatasync);
}
#endif /* HAVE_FDATASYNC */
#ifdef HAVE_CHOWN
/*[clinic input]
os.chown
path : path_t(allow_fd='PATH_HAVE_FCHOWN')
Path to be examined; can be string, bytes, or open-file-descriptor int.
uid: uid_t
gid: gid_t
*
dir_fd : dir_fd(requires='fchownat') = None
If not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that
directory.
follow_symlinks: bool = True
If False, and the last element of the path is a symbolic link,
stat will examine the symbolic link itself instead of the file
the link points to.
Change the owner and group id of path to the numeric uid and gid.\
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, chown will modify the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
dir_fd and follow_symlinks may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_chown__doc__,
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
"--\n"
"\n"
"Change the owner and group id of path to the numeric uid and gid.\\\n"
"\n"
" path\n"
" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
" dir_fd\n"
" If not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that\n"
" directory.\n"
" follow_symlinks\n"
" If False, and the last element of the path is a symbolic link,\n"
" stat will examine the symbolic link itself instead of the file\n"
" the link points to.\n"
"\n"
"path may always be specified as a string.\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, chown will modify the symbolic link itself instead of the file the\n"
" link points to.\n"
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
" an open file descriptor.\n"
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
" If they are unavailable, using them will raise a NotImplementedError.");
#define OS_CHOWN_METHODDEF \
{"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__},
static PyObject *
os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid, int dir_fd, int follow_symlinks);
static PyObject *
os_chown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
uid_t uid;
gid_t gid;
int dir_fd = DEFAULT_DIR_FD;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&O&|$O&p:chown", _keywords,
path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
goto exit;
return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid, int dir_fd, int follow_symlinks)
/*[clinic end generated code: output=22f011e3b4f9ff49 input=a61cc35574814d5d]*/
{
int result;
#if !(defined(HAVE_LCHOWN) || defined(HAVE_FCHOWNAT))
if (follow_symlinks_specified("chown", follow_symlinks))
return NULL;
#endif
if (dir_fd_and_fd_invalid("chown", dir_fd, path->fd) ||
fd_and_follow_symlinks_invalid("chown", path->fd, follow_symlinks))
return NULL;
#ifdef __APPLE__
/*
* This is for Mac OS X 10.3, which doesn't have lchown.
* (But we still have an lchown symbol because of weak-linking.)
* It doesn't have fchownat either. So there's no possibility
* of a graceful failover.
*/
if ((!follow_symlinks) && (lchown == NULL)) {
follow_symlinks_specified("chown", follow_symlinks);
return NULL;
}
#endif
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FCHOWN
if (path->fd != -1)
result = fchown(path->fd, uid, gid);
else
#endif
#ifdef HAVE_LCHOWN
if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
result = lchown(path->narrow, uid, gid);
else
#endif
#ifdef HAVE_FCHOWNAT
if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks))
result = fchownat(dir_fd, path->narrow, uid, gid,
follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
else
#endif
result = chown(path->narrow, uid, gid);
Py_END_ALLOW_THREADS
if (result)
return path_error(path);
Py_RETURN_NONE;
}
#endif /* HAVE_CHOWN */
#ifdef HAVE_FCHOWN
/*[clinic input]
os.fchown
fd: int
uid: uid_t
gid: gid_t
Change the owner and group id of the file specified by file descriptor.
Equivalent to os.chown(fd, uid, gid).
[clinic start generated code]*/
PyDoc_STRVAR(os_fchown__doc__,
"fchown($module, /, fd, uid, gid)\n"
"--\n"
"\n"
"Change the owner and group id of the file specified by file descriptor.\n"
"\n"
"Equivalent to os.chown(fd, uid, gid).");
#define OS_FCHOWN_METHODDEF \
{"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__},
static PyObject *
os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid);
static PyObject *
os_fchown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", "uid", "gid", NULL};
int fd;
uid_t uid;
gid_t gid;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"iO&O&:fchown", _keywords,
&fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid))
goto exit;
return_value = os_fchown_impl(module, fd, uid, gid);
exit:
return return_value;
}
static PyObject *
os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid)
/*[clinic end generated code: output=687781cb7d8974d6 input=3af544ba1b13a0d7]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = fchown(fd, uid, gid);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_FCHOWN */
#ifdef HAVE_LCHOWN
/*[clinic input]
os.lchown
path : path_t
uid: uid_t
gid: gid_t
Change the owner and group id of path to the numeric uid and gid.
This function will not follow symbolic links.
Equivalent to os.chown(path, uid, gid, follow_symlinks=False).
[clinic start generated code]*/
PyDoc_STRVAR(os_lchown__doc__,
"lchown($module, /, path, uid, gid)\n"
"--\n"
"\n"
"Change the owner and group id of path to the numeric uid and gid.\n"
"\n"
"This function will not follow symbolic links.\n"
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
#define OS_LCHOWN_METHODDEF \
{"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__},
static PyObject *
os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid);
static PyObject *
os_lchown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "uid", "gid", NULL};
path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
uid_t uid;
gid_t gid;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&O&:lchown", _keywords,
path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid))
goto exit;
return_value = os_lchown_impl(module, &path, uid, gid);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid)
/*[clinic end generated code: output=bf25fdb0d25130e2 input=b1c6014d563a7161]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = lchown(path->narrow, uid, gid);
Py_END_ALLOW_THREADS
if (res < 0) {
return path_error(path);
}
Py_RETURN_NONE;
}
#endif /* HAVE_LCHOWN */
static PyObject *
posix_getcwd(int use_bytes)
{
char buf[1026];
char *res;
#ifdef MS_WINDOWS
if (!use_bytes) {
wchar_t wbuf[1026];
wchar_t *wbuf2 = wbuf;
PyObject *resobj;
DWORD len;
Py_BEGIN_ALLOW_THREADS
len = GetCurrentDirectoryW(Py_ARRAY_LENGTH(wbuf), wbuf);
/* If the buffer is large enough, len does not include the
terminating \0. If the buffer is too small, len includes
the space needed for the terminator. */
if (len >= Py_ARRAY_LENGTH(wbuf)) {
wbuf2 = PyMem_RawMalloc(len * sizeof(wchar_t));
if (wbuf2)
len = GetCurrentDirectoryW(len, wbuf2);
}
Py_END_ALLOW_THREADS
if (!wbuf2) {
PyErr_NoMemory();
return NULL;
}
if (!len) {
if (wbuf2 != wbuf)
PyMem_RawFree(wbuf2);
return PyErr_SetFromWindowsErr(0);
}
resobj = PyUnicode_FromWideChar(wbuf2, len);
if (wbuf2 != wbuf)
PyMem_RawFree(wbuf2);
return resobj;
}
if (win32_warn_bytes_api())
return NULL;
#endif
Py_BEGIN_ALLOW_THREADS
res = getcwd(buf, sizeof buf);
Py_END_ALLOW_THREADS
if (res == NULL)
return posix_error();
if (use_bytes)
return PyBytes_FromStringAndSize(buf, strlen(buf));
return PyUnicode_DecodeFSDefault(buf);
}
/*[clinic input]
os.getcwd
Return a unicode string representing the current working directory.
[clinic start generated code]*/
PyDoc_STRVAR(os_getcwd__doc__,
"getcwd($module, /)\n"
"--\n"
"\n"
"Return a unicode string representing the current working directory.");
#define OS_GETCWD_METHODDEF \
{"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
static PyObject *
os_getcwd_impl(PyModuleDef *module);
static PyObject *
os_getcwd(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getcwd_impl(module);
}
static PyObject *
os_getcwd_impl(PyModuleDef *module)
/*[clinic end generated code: output=d70b281db5c78ff7 input=f069211bb70e3d39]*/
{
return posix_getcwd(0);
}
/*[clinic input]
os.getcwdb
Return a bytes string representing the current working directory.
[clinic start generated code]*/
PyDoc_STRVAR(os_getcwdb__doc__,
"getcwdb($module, /)\n"
"--\n"
"\n"
"Return a bytes string representing the current working directory.");
#define OS_GETCWDB_METHODDEF \
{"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
static PyObject *
os_getcwdb_impl(PyModuleDef *module);
static PyObject *
os_getcwdb(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getcwdb_impl(module);
}
static PyObject *
os_getcwdb_impl(PyModuleDef *module)
/*[clinic end generated code: output=75da47f2d75f9166 input=f6f6a378dad3d9cb]*/
{
return posix_getcwd(1);
}
#if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
#define HAVE_LINK 1
#endif
#ifdef HAVE_LINK
/*[clinic input]
os.link
src : path_t
dst : path_t
*
src_dir_fd : dir_fd = None
dst_dir_fd : dir_fd = None
follow_symlinks: bool = True
Create a hard link to a file.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
If follow_symlinks is False, and the last element of src is a symbolic
link, link will create a link to the symbolic link itself instead of the
file the link points to.
src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your
platform. If they are unavailable, using them will raise a
NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_link__doc__,
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
" follow_symlinks=True)\n"
"--\n"
"\n"
"Create a hard link to a file.\n"
"\n"
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
" descriptor open to a directory, and the respective path string (src or dst)\n"
" should be relative; the path will then be relative to that directory.\n"
"If follow_symlinks is False, and the last element of src is a symbolic\n"
" link, link will create a link to the symbolic link itself instead of the\n"
" file the link points to.\n"
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
" platform. If they are unavailable, using them will raise a\n"
" NotImplementedError.");
#define OS_LINK_METHODDEF \
{"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__},
static PyObject *
os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int follow_symlinks);
static PyObject *
os_link(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
int src_dir_fd = DEFAULT_DIR_FD;
int dst_dir_fd = DEFAULT_DIR_FD;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|$O&O&p:link", _keywords,
path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks))
goto exit;
return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
exit:
/* Cleanup for src */
path_cleanup(&src);
/* Cleanup for dst */
path_cleanup(&dst);
return return_value;
}
static PyObject *
os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int follow_symlinks)
/*[clinic end generated code: output=53477662fe02e183 input=b0095ebbcbaa7e04]*/
{
#ifdef MS_WINDOWS
BOOL result;
#else
int result;
#endif
#ifndef HAVE_LINKAT
if ((src_dir_fd != DEFAULT_DIR_FD) || (dst_dir_fd != DEFAULT_DIR_FD)) {
argument_unavailable_error("link", "src_dir_fd and dst_dir_fd");
return NULL;
}
#endif
if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
PyErr_SetString(PyExc_NotImplementedError,
"link: src and dst must be the same type");
return NULL;
}
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (src->wide)
result = CreateHardLinkW(dst->wide, src->wide, NULL);
else
result = CreateHardLinkA(dst->narrow, src->narrow, NULL);
Py_END_ALLOW_THREADS
if (!result)
return path_error2(src, dst);
#else
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_LINKAT
if ((src_dir_fd != DEFAULT_DIR_FD) ||
(dst_dir_fd != DEFAULT_DIR_FD) ||
(!follow_symlinks))
result = linkat(src_dir_fd, src->narrow,
dst_dir_fd, dst->narrow,
follow_symlinks ? AT_SYMLINK_FOLLOW : 0);
else
#endif
result = link(src->narrow, dst->narrow);
Py_END_ALLOW_THREADS
if (result)
return path_error2(src, dst);
#endif
Py_RETURN_NONE;
}
#endif
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
static PyObject *
_listdir_windows_no_opendir(path_t *path, PyObject *list)
{
PyObject *v;
HANDLE hFindFile = INVALID_HANDLE_VALUE;
BOOL result;
WIN32_FIND_DATA FileData;
char namebuf[MAX_PATH+4]; /* Overallocate for "\*.*" */
char *bufptr = namebuf;
/* only claim to have space for MAX_PATH */
Py_ssize_t len = Py_ARRAY_LENGTH(namebuf)-4;
PyObject *po = NULL;
wchar_t *wnamebuf = NULL;
if (!path->narrow) {
WIN32_FIND_DATAW wFileData;
wchar_t *po_wchars;
if (!path->wide) { /* Default arg: "." */
po_wchars = L".";
len = 1;
} else {
po_wchars = path->wide;
len = wcslen(path->wide);
}
/* The +5 is so we can append "\\*.*\0" */
wnamebuf = PyMem_Malloc((len + 5) * sizeof(wchar_t));
if (!wnamebuf) {
PyErr_NoMemory();
goto exit;
}
wcscpy(wnamebuf, po_wchars);
if (len > 0) {
wchar_t wch = wnamebuf[len-1];
if (wch != SEP && wch != ALTSEP && wch != L':')
wnamebuf[len++] = SEP;
wcscpy(wnamebuf + len, L"*.*");
}
if ((list = PyList_New(0)) == NULL) {
goto exit;
}
Py_BEGIN_ALLOW_THREADS
hFindFile = FindFirstFileW(wnamebuf, &wFileData);
Py_END_ALLOW_THREADS
if (hFindFile == INVALID_HANDLE_VALUE) {
int error = GetLastError();
if (error == ERROR_FILE_NOT_FOUND)
goto exit;
Py_DECREF(list);
list = path_error(path);
goto exit;
}
do {
/* Skip over . and .. */
if (wcscmp(wFileData.cFileName, L".") != 0 &&
wcscmp(wFileData.cFileName, L"..") != 0) {
v = PyUnicode_FromWideChar(wFileData.cFileName,
wcslen(wFileData.cFileName));
if (v == NULL) {
Py_DECREF(list);
list = NULL;
break;
}
if (PyList_Append(list, v) != 0) {
Py_DECREF(v);
Py_DECREF(list);
list = NULL;
break;
}
Py_DECREF(v);
}
Py_BEGIN_ALLOW_THREADS
result = FindNextFileW(hFindFile, &wFileData);
Py_END_ALLOW_THREADS
/* FindNextFile sets error to ERROR_NO_MORE_FILES if
it got to the end of the directory. */
if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(list);
list = path_error(path);
goto exit;
}
} while (result == TRUE);
goto exit;
}
strcpy(namebuf, path->narrow);
len = path->length;
if (len > 0) {
char ch = namebuf[len-1];
if (ch != '\\' && ch != '/' && ch != ':')
namebuf[len++] = '\\';
strcpy(namebuf + len, "*.*");
}
if ((list = PyList_New(0)) == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
hFindFile = FindFirstFile(namebuf, &FileData);
Py_END_ALLOW_THREADS
if (hFindFile == INVALID_HANDLE_VALUE) {
int error = GetLastError();
if (error == ERROR_FILE_NOT_FOUND)
goto exit;
Py_DECREF(list);
list = path_error(path);
goto exit;
}
do {
/* Skip over . and .. */
if (strcmp(FileData.cFileName, ".") != 0 &&
strcmp(FileData.cFileName, "..") != 0) {
v = PyBytes_FromString(FileData.cFileName);
if (v == NULL) {
Py_DECREF(list);
list = NULL;
break;
}
if (PyList_Append(list, v) != 0) {
Py_DECREF(v);
Py_DECREF(list);
list = NULL;
break;
}
Py_DECREF(v);
}
Py_BEGIN_ALLOW_THREADS
result = FindNextFile(hFindFile, &FileData);
Py_END_ALLOW_THREADS
/* FindNextFile sets error to ERROR_NO_MORE_FILES if
it got to the end of the directory. */
if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(list);
list = path_error(path);
goto exit;
}
} while (result == TRUE);
exit:
if (hFindFile != INVALID_HANDLE_VALUE) {
if (FindClose(hFindFile) == FALSE) {
if (list != NULL) {
Py_DECREF(list);
list = path_error(path);
}
}
}
PyMem_Free(wnamebuf);
return list;
} /* end of _listdir_windows_no_opendir */
#else /* thus POSIX, ie: not (MS_WINDOWS and not HAVE_OPENDIR) */
static PyObject *
_posix_listdir(path_t *path, PyObject *list)
{
PyObject *v;
DIR *dirp = NULL;
struct dirent *ep;
int return_str; /* if false, return bytes */
#ifdef HAVE_FDOPENDIR
int fd = -1;
#endif
errno = 0;
#ifdef HAVE_FDOPENDIR
if (path->fd != -1) {
/* closedir() closes the FD, so we duplicate it */
fd = _Py_dup(path->fd);
if (fd == -1)
return NULL;
return_str = 1;
Py_BEGIN_ALLOW_THREADS
dirp = fdopendir(fd);
Py_END_ALLOW_THREADS
}
else
#endif
{
char *name;
if (path->narrow) {
name = path->narrow;
/* only return bytes if they specified a bytes object */
return_str = !(PyBytes_Check(path->object));
}
else {
name = ".";
return_str = 1;
}
Py_BEGIN_ALLOW_THREADS
dirp = opendir(name);
Py_END_ALLOW_THREADS
}
if (dirp == NULL) {
list = path_error(path);
#ifdef HAVE_FDOPENDIR
if (fd != -1) {
Py_BEGIN_ALLOW_THREADS
close(fd);
Py_END_ALLOW_THREADS
}
#endif
goto exit;
}
if ((list = PyList_New(0)) == NULL) {
goto exit;
}
for (;;) {
errno = 0;
Py_BEGIN_ALLOW_THREADS
ep = readdir(dirp);
Py_END_ALLOW_THREADS
if (ep == NULL) {
if (errno == 0) {
break;
} else {
Py_DECREF(list);
list = path_error(path);
goto exit;
}
}
if (ep->d_name[0] == '.' &&
(NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
continue;
if (return_str)
v = PyUnicode_DecodeFSDefaultAndSize(ep->d_name, NAMLEN(ep));
else
v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
if (v == NULL) {
Py_CLEAR(list);
break;
}
if (PyList_Append(list, v) != 0) {
Py_DECREF(v);
Py_CLEAR(list);
break;
}
Py_DECREF(v);
}
exit:
if (dirp != NULL) {
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FDOPENDIR
if (fd > -1)
rewinddir(dirp);
#endif
closedir(dirp);
Py_END_ALLOW_THREADS
}
return list;
} /* end of _posix_listdir */
#endif /* which OS */
/*[clinic input]
os.listdir
path : path_t(nullable=True, allow_fd='PATH_HAVE_FDOPENDIR') = None
Return a list containing the names of the files in the directory.
path can be specified as either str or bytes. If path is bytes,
the filenames returned will also be bytes; in all other circumstances
the filenames returned will be str.
If path is None, uses the path='.'.
On some platforms, path may also be specified as an open file descriptor;\
the file descriptor must refer to a directory.
If this functionality is unavailable, using it raises NotImplementedError.
The list is in arbitrary order. It does not include the special
entries '.' and '..' even if they are present in the directory.
[clinic start generated code]*/
PyDoc_STRVAR(os_listdir__doc__,
"listdir($module, /, path=None)\n"
"--\n"
"\n"
"Return a list containing the names of the files in the directory.\n"
"\n"
"path can be specified as either str or bytes. If path is bytes,\n"
" the filenames returned will also be bytes; in all other circumstances\n"
" the filenames returned will be str.\n"
"If path is None, uses the path=\'.\'.\n"
"On some platforms, path may also be specified as an open file descriptor;\\\n"
" the file descriptor must refer to a directory.\n"
" If this functionality is unavailable, using it raises NotImplementedError.\n"
"\n"
"The list is in arbitrary order. It does not include the special\n"
"entries \'.\' and \'..\' even if they are present in the directory.");
#define OS_LISTDIR_METHODDEF \
{"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__},
static PyObject *
os_listdir_impl(PyModuleDef *module, path_t *path);
static PyObject *
os_listdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|O&:listdir", _keywords,
path_converter, &path))
goto exit;
return_value = os_listdir_impl(module, &path);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_listdir_impl(PyModuleDef *module, path_t *path)
/*[clinic end generated code: output=e159bd9be6909018 input=09e300416e3cd729]*/
{
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
return _listdir_windows_no_opendir(path, NULL);
#else
return _posix_listdir(path, NULL);
#endif
}
#ifdef MS_WINDOWS
/* A helper function for abspath on win32 */
/* AC 3.5: probably just convert to using path converter */
static PyObject *
posix__getfullpathname(PyObject *self, PyObject *args)
{
const char *path;
char outbuf[MAX_PATH];
char *temp;
PyObject *po;
if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po))
{
wchar_t *wpath;
wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
wchar_t *wtemp;
DWORD result;
PyObject *v;
wpath = PyUnicode_AsUnicode(po);
if (wpath == NULL)
return NULL;
result = GetFullPathNameW(wpath,
Py_ARRAY_LENGTH(woutbuf),
woutbuf, &wtemp);
if (result > Py_ARRAY_LENGTH(woutbuf)) {
woutbufp = PyMem_Malloc(result * sizeof(wchar_t));
if (!woutbufp)
return PyErr_NoMemory();
result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
}
if (result)
v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
else
v = win32_error_object("GetFullPathNameW", po);
if (woutbufp != woutbuf)
PyMem_Free(woutbufp);
return v;
}
/* Drop the argument parsing error as narrow strings
are also valid. */
PyErr_Clear();
if (!PyArg_ParseTuple (args, "y:_getfullpathname",
&path))
return NULL;
if (win32_warn_bytes_api())
return NULL;
if (!GetFullPathName(path, Py_ARRAY_LENGTH(outbuf),
outbuf, &temp)) {
win32_error("GetFullPathName", path);
return NULL;
}
if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
return PyUnicode_Decode(outbuf, strlen(outbuf),
Py_FileSystemDefaultEncoding, NULL);
}
return PyBytes_FromString(outbuf);
}
/*[clinic input]
os._getfinalpathname
path: unicode
/
A helper function for samepath on windows.
[clinic start generated code]*/
PyDoc_STRVAR(os__getfinalpathname__doc__,
"_getfinalpathname($module, path, /)\n"
"--\n"
"\n"
"A helper function for samepath on windows.");
#define OS__GETFINALPATHNAME_METHODDEF \
{"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_VARARGS, os__getfinalpathname__doc__},
static PyObject *
os__getfinalpathname_impl(PyModuleDef *module, PyObject *path);
static PyObject *
os__getfinalpathname(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *path;
if (!PyArg_ParseTuple(args,
"U:_getfinalpathname",
&path))
goto exit;
return_value = os__getfinalpathname_impl(module, path);
exit:
return return_value;
}
static PyObject *
os__getfinalpathname_impl(PyModuleDef *module, PyObject *path)
/*[clinic end generated code: output=4563c6eacf1b0881 input=71d5e89334891bf4]*/
{
HANDLE hFile;
int buf_size;
wchar_t *target_path;
int result_length;
PyObject *result;
wchar_t *path_wchar;
path_wchar = PyUnicode_AsUnicode(path);
if (path_wchar == NULL)
return NULL;
if(!check_GetFinalPathNameByHandle()) {
/* If the OS doesn't have GetFinalPathNameByHandle, return a
NotImplementedError. */
return PyErr_Format(PyExc_NotImplementedError,
"GetFinalPathNameByHandle not available on this platform");
}
hFile = CreateFileW(
path_wchar,
0, /* desired access */
0, /* share mode */
NULL, /* security attributes */
OPEN_EXISTING,
/* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if(hFile == INVALID_HANDLE_VALUE)
return win32_error_object("CreateFileW", path);
/* We have a good handle to the target, use it to determine the
target path name. */
buf_size = Py_GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT);
if(!buf_size)
return win32_error_object("GetFinalPathNameByHandle", path);
target_path = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t));
if(!target_path)
return PyErr_NoMemory();
result_length = Py_GetFinalPathNameByHandleW(hFile, target_path,
buf_size, VOLUME_NAME_DOS);
if(!result_length)
return win32_error_object("GetFinalPathNamyByHandle", path);
if(!CloseHandle(hFile))
return win32_error_object("CloseHandle", path);
target_path[result_length] = 0;
result = PyUnicode_FromWideChar(target_path, result_length);
PyMem_Free(target_path);
return result;
}
PyDoc_STRVAR(posix__isdir__doc__,
"Return true if the pathname refers to an existing directory.");
/* AC 3.5: convert using path converter */
static PyObject *
posix__isdir(PyObject *self, PyObject *args)
{
const char *path;
PyObject *po;
DWORD attributes;
if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
wchar_t *wpath = PyUnicode_AsUnicode(po);
if (wpath == NULL)
return NULL;
attributes = GetFileAttributesW(wpath);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;
goto check;
}
/* Drop the argument parsing error as narrow strings
are also valid. */
PyErr_Clear();
if (!PyArg_ParseTuple(args, "y:_isdir", &path))
return NULL;
if (win32_warn_bytes_api())
return NULL;
attributes = GetFileAttributesA(path);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;
check:
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
/*[clinic input]
os._getvolumepathname
path: unicode
A helper function for ismount on Win32.
[clinic start generated code]*/
PyDoc_STRVAR(os__getvolumepathname__doc__,
"_getvolumepathname($module, /, path)\n"
"--\n"
"\n"
"A helper function for ismount on Win32.");
#define OS__GETVOLUMEPATHNAME_METHODDEF \
{"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__},
static PyObject *
os__getvolumepathname_impl(PyModuleDef *module, PyObject *path);
static PyObject *
os__getvolumepathname(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
PyObject *path;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"U:_getvolumepathname", _keywords,
&path))
goto exit;
return_value = os__getvolumepathname_impl(module, path);
exit:
return return_value;
}
static PyObject *
os__getvolumepathname_impl(PyModuleDef *module, PyObject *path)
/*[clinic end generated code: output=ac0833b6d6da7657 input=7eacadc40acbda6b]*/
{
PyObject *result;
wchar_t *path_wchar, *mountpath=NULL;
size_t buflen;
BOOL ret;
path_wchar = PyUnicode_AsUnicodeAndSize(path, &buflen);
if (path_wchar == NULL)
return NULL;
buflen += 1;
/* Volume path should be shorter than entire path */
buflen = Py_MAX(buflen, MAX_PATH);
if (buflen > DWORD_MAX) {
PyErr_SetString(PyExc_OverflowError, "path too long");
return NULL;
}
mountpath = (wchar_t *)PyMem_Malloc(buflen * sizeof(wchar_t));
if (mountpath == NULL)
return PyErr_NoMemory();
Py_BEGIN_ALLOW_THREADS
ret = GetVolumePathNameW(path_wchar, mountpath,
Py_SAFE_DOWNCAST(buflen, size_t, DWORD));
Py_END_ALLOW_THREADS
if (!ret) {
result = win32_error_object("_getvolumepathname", path);
goto exit;
}
result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
exit:
PyMem_Free(mountpath);
return result;
}
#endif /* MS_WINDOWS */
/*[clinic input]
os.mkdir
path : path_t
mode: int = 0o777
*
dir_fd : dir_fd(requires='mkdirat') = None
# "mkdir(path, mode=0o777, *, dir_fd=None)\n\n\
Create a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
The mode argument is ignored on Windows.
[clinic start generated code]*/
PyDoc_STRVAR(os_mkdir__doc__,
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
"--\n"
"\n"
"Create a directory.\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.\n"
"\n"
"The mode argument is ignored on Windows.");
#define OS_MKDIR_METHODDEF \
{"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__},
static PyObject *
os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd);
static PyObject *
os_mkdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
int mode = 511;
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|i$O&:mkdir", _keywords,
path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_mkdir_impl(module, &path, mode, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd)
/*[clinic end generated code: output=55c6ef2bc1b207e6 input=e965f68377e9b1ce]*/
{
int result;
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (path->wide)
result = CreateDirectoryW(path->wide, NULL);
else
result = CreateDirectoryA(path->narrow, NULL);
Py_END_ALLOW_THREADS
if (!result)
return path_error(path);
#else
Py_BEGIN_ALLOW_THREADS
#if HAVE_MKDIRAT
if (dir_fd != DEFAULT_DIR_FD)
result = mkdirat(dir_fd, path->narrow, mode);
else
#endif
#if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
result = mkdir(path->narrow);
#else
result = mkdir(path->narrow, mode);
#endif
Py_END_ALLOW_THREADS
if (result < 0)
return path_error(path);
#endif
Py_RETURN_NONE;
}
/* sys/resource.h is needed for at least: wait3(), wait4(), broken nice. */
#if defined(HAVE_SYS_RESOURCE_H)
#include <sys/resource.h>
#endif
#ifdef HAVE_NICE
/*[clinic input]
os.nice
increment: int
/
Add increment to the priority of process and return the new priority.
[clinic start generated code]*/
PyDoc_STRVAR(os_nice__doc__,
"nice($module, increment, /)\n"
"--\n"
"\n"
"Add increment to the priority of process and return the new priority.");
#define OS_NICE_METHODDEF \
{"nice", (PyCFunction)os_nice, METH_VARARGS, os_nice__doc__},
static PyObject *
os_nice_impl(PyModuleDef *module, int increment);
static PyObject *
os_nice(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int increment;
if (!PyArg_ParseTuple(args,
"i:nice",
&increment))
goto exit;
return_value = os_nice_impl(module, increment);
exit:
return return_value;
}
static PyObject *
os_nice_impl(PyModuleDef *module, int increment)
/*[clinic end generated code: output=c360dc2a3bd8e3d0 input=864be2d402a21da2]*/
{
int value;
/* There are two flavours of 'nice': one that returns the new
priority (as required by almost all standards out there) and the
Linux/FreeBSD/BSDI one, which returns '0' on success and advices
the use of getpriority() to get the new priority.
If we are of the nice family that returns the new priority, we
need to clear errno before the call, and check if errno is filled
before calling posix_error() on a returnvalue of -1, because the
-1 may be the actual new priority! */
errno = 0;
value = nice(increment);
#if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
if (value == 0)
value = getpriority(PRIO_PROCESS, 0);
#endif
if (value == -1 && errno != 0)
/* either nice() or getpriority() returned an error */
return posix_error();
return PyLong_FromLong((long) value);
}
#endif /* HAVE_NICE */
#ifdef HAVE_GETPRIORITY
/*[clinic input]
os.getpriority
which: int
who: int
Return program scheduling priority.
[clinic start generated code]*/
PyDoc_STRVAR(os_getpriority__doc__,
"getpriority($module, /, which, who)\n"
"--\n"
"\n"
"Return program scheduling priority.");
#define OS_GETPRIORITY_METHODDEF \
{"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__},
static PyObject *
os_getpriority_impl(PyModuleDef *module, int which, int who);
static PyObject *
os_getpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"which", "who", NULL};
int which;
int who;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"ii:getpriority", _keywords,
&which, &who))
goto exit;
return_value = os_getpriority_impl(module, which, who);
exit:
return return_value;
}
static PyObject *
os_getpriority_impl(PyModuleDef *module, int which, int who)
/*[clinic end generated code: output=81639cf765f05dae input=9be615d40e2544ef]*/
{
int retval;
errno = 0;
retval = getpriority(which, who);
if (errno != 0)
return posix_error();
return PyLong_FromLong((long)retval);
}
#endif /* HAVE_GETPRIORITY */
#ifdef HAVE_SETPRIORITY
/*[clinic input]
os.setpriority
which: int
who: int
priority: int
Set program scheduling priority.
[clinic start generated code]*/
PyDoc_STRVAR(os_setpriority__doc__,
"setpriority($module, /, which, who, priority)\n"
"--\n"
"\n"
"Set program scheduling priority.");
#define OS_SETPRIORITY_METHODDEF \
{"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__},
static PyObject *
os_setpriority_impl(PyModuleDef *module, int which, int who, int priority);
static PyObject *
os_setpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"which", "who", "priority", NULL};
int which;
int who;
int priority;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"iii:setpriority", _keywords,
&which, &who, &priority))
goto exit;
return_value = os_setpriority_impl(module, which, who, priority);
exit:
return return_value;
}
static PyObject *
os_setpriority_impl(PyModuleDef *module, int which, int who, int priority)
/*[clinic end generated code: output=ddad62651fb2120c input=710ccbf65b9dc513]*/
{
int retval;
retval = setpriority(which, who, priority);
if (retval == -1)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETPRIORITY */
static PyObject *
internal_rename(path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int is_replace)
{
char *function_name = is_replace ? "replace" : "rename";
int dir_fd_specified;
#ifdef MS_WINDOWS
BOOL result;
int flags = is_replace ? MOVEFILE_REPLACE_EXISTING : 0;
#else
int result;
#endif
dir_fd_specified = (src_dir_fd != DEFAULT_DIR_FD) ||
(dst_dir_fd != DEFAULT_DIR_FD);
#ifndef HAVE_RENAMEAT
if (dir_fd_specified) {
argument_unavailable_error(function_name, "src_dir_fd and dst_dir_fd");
return NULL;
}
#endif
if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
PyErr_Format(PyExc_ValueError,
"%s: src and dst must be the same type", function_name);
return NULL;
}
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (src->wide)
result = MoveFileExW(src->wide, dst->wide, flags);
else
result = MoveFileExA(src->narrow, dst->narrow, flags);
Py_END_ALLOW_THREADS
if (!result)
return path_error2(src, dst);
#else
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_RENAMEAT
if (dir_fd_specified)
result = renameat(src_dir_fd, src->narrow, dst_dir_fd, dst->narrow);
else
#endif
result = rename(src->narrow, dst->narrow);
Py_END_ALLOW_THREADS
if (result)
return path_error2(src, dst);
#endif
Py_RETURN_NONE;
}
/*[clinic input]
os.rename
src : path_t
dst : path_t
*
src_dir_fd : dir_fd = None
dst_dir_fd : dir_fd = None
Rename a file or directory.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_rename__doc__,
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
"--\n"
"\n"
"Rename a file or directory.\n"
"\n"
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
" descriptor open to a directory, and the respective path string (src or dst)\n"
" should be relative; the path will then be relative to that directory.\n"
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
" If they are unavailable, using them will raise a NotImplementedError.");
#define OS_RENAME_METHODDEF \
{"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__},
static PyObject *
os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd);
static PyObject *
os_rename(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
int src_dir_fd = DEFAULT_DIR_FD;
int dst_dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|$O&O&:rename", _keywords,
path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
goto exit;
return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
exit:
/* Cleanup for src */
path_cleanup(&src);
/* Cleanup for dst */
path_cleanup(&dst);
return return_value;
}
static PyObject *
os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd)
/*[clinic end generated code: output=c936bdc81f460a1e input=faa61c847912c850]*/
{
return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 0);
}
/*[clinic input]
os.replace = os.rename
Rename a file or directory, overwriting the destination.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError."
[clinic start generated code]*/
PyDoc_STRVAR(os_replace__doc__,
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
"--\n"
"\n"
"Rename a file or directory, overwriting the destination.\n"
"\n"
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
" descriptor open to a directory, and the respective path string (src or dst)\n"
" should be relative; the path will then be relative to that directory.\n"
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
" If they are unavailable, using them will raise a NotImplementedError.\"");
#define OS_REPLACE_METHODDEF \
{"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__},
static PyObject *
os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd);
static PyObject *
os_replace(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
int src_dir_fd = DEFAULT_DIR_FD;
int dst_dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|$O&O&:replace", _keywords,
path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
goto exit;
return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
exit:
/* Cleanup for src */
path_cleanup(&src);
/* Cleanup for dst */
path_cleanup(&dst);
return return_value;
}
static PyObject *
os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd)
/*[clinic end generated code: output=224e4710d290d171 input=25515dfb107c8421]*/
{
return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 1);
}
/*[clinic input]
os.rmdir
path: path_t
*
dir_fd: dir_fd(requires='unlinkat') = None
Remove a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_rmdir__doc__,
"rmdir($module, /, path, *, dir_fd=None)\n"
"--\n"
"\n"
"Remove a directory.\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_RMDIR_METHODDEF \
{"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__},
static PyObject *
os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd);
static PyObject *
os_rmdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|$O&:rmdir", _keywords,
path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_rmdir_impl(module, &path, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd)
/*[clinic end generated code: output=70b9fdbe3bee0591 input=38c8b375ca34a7e2]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if (path->wide)
result = RemoveDirectoryW(path->wide);
else
result = RemoveDirectoryA(path->narrow);
result = !result; /* Windows, success=1, UNIX, success=0 */
#else
#ifdef HAVE_UNLINKAT
if (dir_fd != DEFAULT_DIR_FD)
result = unlinkat(dir_fd, path->narrow, AT_REMOVEDIR);
else
#endif
result = rmdir(path->narrow);
#endif
Py_END_ALLOW_THREADS
if (result)
return path_error(path);
Py_RETURN_NONE;
}
#ifdef HAVE_SYSTEM
#ifdef MS_WINDOWS
/*[clinic input]
os.system -> long
command: Py_UNICODE
Execute the command in a subshell.
[clinic start generated code]*/
PyDoc_STRVAR(os_system__doc__,
"system($module, /, command)\n"
"--\n"
"\n"
"Execute the command in a subshell.");
#define OS_SYSTEM_METHODDEF \
{"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
static long
os_system_impl(PyModuleDef *module, Py_UNICODE *command);
static PyObject *
os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"command", NULL};
Py_UNICODE *command;
long _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"u:system", _keywords,
&command))
goto exit;
_return_value = os_system_impl(module, command);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong(_return_value);
exit:
return return_value;
}
static long
os_system_impl(PyModuleDef *module, Py_UNICODE *command)
/*[clinic end generated code: output=29fe699c0b2e9d38 input=303f5ce97df606b0]*/
{
long result;
Py_BEGIN_ALLOW_THREADS
result = _wsystem(command);
Py_END_ALLOW_THREADS
return result;
}
#else /* MS_WINDOWS */
/*[clinic input]
os.system -> long
command: FSConverter
Execute the command in a subshell.
[clinic start generated code]*/
PyDoc_STRVAR(os_system__doc__,
"system($module, /, command)\n"
"--\n"
"\n"
"Execute the command in a subshell.");
#define OS_SYSTEM_METHODDEF \
{"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
static long
os_system_impl(PyModuleDef *module, PyObject *command);
static PyObject *
os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"command", NULL};
PyObject *command = NULL;
long _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:system", _keywords,
PyUnicode_FSConverter, &command))
goto exit;
_return_value = os_system_impl(module, command);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong(_return_value);
exit:
/* Cleanup for command */
Py_XDECREF(command);
return return_value;
}
static long
os_system_impl(PyModuleDef *module, PyObject *command)
/*[clinic end generated code: output=5be9f3c40ead3bad input=86a58554ba6094af]*/
{
long result;
char *bytes = PyBytes_AsString(command);
Py_BEGIN_ALLOW_THREADS
result = system(bytes);
Py_END_ALLOW_THREADS
return result;
}
#endif
#endif /* HAVE_SYSTEM */
/*[clinic input]
os.umask
mask: int
/
Set the current numeric umask and return the previous umask.
[clinic start generated code]*/
PyDoc_STRVAR(os_umask__doc__,
"umask($module, mask, /)\n"
"--\n"
"\n"
"Set the current numeric umask and return the previous umask.");
#define OS_UMASK_METHODDEF \
{"umask", (PyCFunction)os_umask, METH_VARARGS, os_umask__doc__},
static PyObject *
os_umask_impl(PyModuleDef *module, int mask);
static PyObject *
os_umask(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int mask;
if (!PyArg_ParseTuple(args,
"i:umask",
&mask))
goto exit;
return_value = os_umask_impl(module, mask);
exit:
return return_value;
}
static PyObject *
os_umask_impl(PyModuleDef *module, int mask)
/*[clinic end generated code: output=90048b39d2d4a961 input=ab6bfd9b24d8a7e8]*/
{
int i = (int)umask(mask);
if (i < 0)
return posix_error();
return PyLong_FromLong((long)i);
}
#ifdef MS_WINDOWS
/* override the default DeleteFileW behavior so that directory
symlinks can be removed with this function, the same as with
Unix symlinks */
BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFileName)
{
WIN32_FILE_ATTRIBUTE_DATA info;
WIN32_FIND_DATAW find_data;
HANDLE find_data_handle;
int is_directory = 0;
int is_link = 0;
if (GetFileAttributesExW(lpFileName, GetFileExInfoStandard, &info)) {
is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
/* Get WIN32_FIND_DATA structure for the path to determine if
it is a symlink */
if(is_directory &&
info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
find_data_handle = FindFirstFileW(lpFileName, &find_data);
if(find_data_handle != INVALID_HANDLE_VALUE) {
/* IO_REPARSE_TAG_SYMLINK if it is a symlink and
IO_REPARSE_TAG_MOUNT_POINT if it is a junction point. */
is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK ||
find_data.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT;
FindClose(find_data_handle);
}
}
}
if (is_directory && is_link)
return RemoveDirectoryW(lpFileName);
return DeleteFileW(lpFileName);
}
#endif /* MS_WINDOWS */
/*[clinic input]
os.unlink
path: path_t
*
dir_fd: dir_fd(requires='unlinkat')=None
Remove a file (same as remove()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_unlink__doc__,
"unlink($module, /, path, *, dir_fd=None)\n"
"--\n"
"\n"
"Remove a file (same as remove()).\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_UNLINK_METHODDEF \
{"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__},
static PyObject *
os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd);
static PyObject *
os_unlink(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|$O&:unlink", _keywords,
path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_unlink_impl(module, &path, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd)
/*[clinic end generated code: output=59a6e66d67ff2e75 input=d7bcde2b1b2a2552]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if (path->wide)
result = Py_DeleteFileW(path->wide);
else
result = DeleteFileA(path->narrow);
result = !result; /* Windows, success=1, UNIX, success=0 */
#else
#ifdef HAVE_UNLINKAT
if (dir_fd != DEFAULT_DIR_FD)
result = unlinkat(dir_fd, path->narrow, 0);
else
#endif /* HAVE_UNLINKAT */
result = unlink(path->narrow);
#endif
Py_END_ALLOW_THREADS
if (result)
return path_error(path);
Py_RETURN_NONE;
}
/*[clinic input]
os.remove = os.unlink
Remove a file (same as unlink()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_remove__doc__,
"remove($module, /, path, *, dir_fd=None)\n"
"--\n"
"\n"
"Remove a file (same as unlink()).\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_REMOVE_METHODDEF \
{"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__},
static PyObject *
os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd);
static PyObject *
os_remove(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|$O&:remove", _keywords,
path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_remove_impl(module, &path, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd)
/*[clinic end generated code: output=cb170cf1e195b8ed input=e05c5ab55cd30983]*/
{
return os_unlink_impl(module, path, dir_fd);
}
static PyStructSequence_Field uname_result_fields[] = {
{"sysname", "operating system name"},
{"nodename", "name of machine on network (implementation-defined)"},
{"release", "operating system release"},
{"version", "operating system version"},
{"machine", "hardware identifier"},
{NULL}
};
PyDoc_STRVAR(uname_result__doc__,
"uname_result: Result from os.uname().\n\n\
This object may be accessed either as a tuple of\n\
(sysname, nodename, release, version, machine),\n\
or via the attributes sysname, nodename, release, version, and machine.\n\
\n\
See os.uname for more information.");
static PyStructSequence_Desc uname_result_desc = {
"uname_result", /* name */
uname_result__doc__, /* doc */
uname_result_fields,
5
};
static PyTypeObject UnameResultType;
#ifdef HAVE_UNAME
/*[clinic input]
os.uname
Return an object identifying the current operating system.
The object behaves like a named tuple with the following fields:
(sysname, nodename, release, version, machine)
[clinic start generated code]*/
PyDoc_STRVAR(os_uname__doc__,
"uname($module, /)\n"
"--\n"
"\n"
"Return an object identifying the current operating system.\n"
"\n"
"The object behaves like a named tuple with the following fields:\n"
" (sysname, nodename, release, version, machine)");
#define OS_UNAME_METHODDEF \
{"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
static PyObject *
os_uname_impl(PyModuleDef *module);
static PyObject *
os_uname(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_uname_impl(module);
}
static PyObject *
os_uname_impl(PyModuleDef *module)
/*[clinic end generated code: output=459a86521ff5041c input=e68bd246db3043ed]*/
{
struct utsname u;
int res;
PyObject *value;
Py_BEGIN_ALLOW_THREADS
res = uname(&u);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
value = PyStructSequence_New(&UnameResultType);
if (value == NULL)
return NULL;
#define SET(i, field) \
{ \
PyObject *o = PyUnicode_DecodeFSDefault(field); \
if (!o) { \
Py_DECREF(value); \
return NULL; \
} \
PyStructSequence_SET_ITEM(value, i, o); \
} \
SET(0, u.sysname);
SET(1, u.nodename);
SET(2, u.release);
SET(3, u.version);
SET(4, u.machine);
#undef SET
return value;
}
#endif /* HAVE_UNAME */
typedef struct {
int now;
time_t atime_s;
long atime_ns;
time_t mtime_s;
long mtime_ns;
} utime_t;
/*
* these macros assume that "utime" is a pointer to a utime_t
* they also intentionally leak the declaration of a pointer named "time"
*/
#define UTIME_TO_TIMESPEC \
struct timespec ts[2]; \
struct timespec *time; \
if (utime->now) \
time = NULL; \
else { \
ts[0].tv_sec = utime->atime_s; \
ts[0].tv_nsec = utime->atime_ns; \
ts[1].tv_sec = utime->mtime_s; \
ts[1].tv_nsec = utime->mtime_ns; \
time = ts; \
} \
#define UTIME_TO_TIMEVAL \
struct timeval tv[2]; \
struct timeval *time; \
if (utime->now) \
time = NULL; \
else { \
tv[0].tv_sec = utime->atime_s; \
tv[0].tv_usec = utime->atime_ns / 1000; \
tv[1].tv_sec = utime->mtime_s; \
tv[1].tv_usec = utime->mtime_ns / 1000; \
time = tv; \
} \
#define UTIME_TO_UTIMBUF \
struct utimbuf u[2]; \
struct utimbuf *time; \
if (utime->now) \
time = NULL; \
else { \
u.actime = utime->atime_s; \
u.modtime = utime->mtime_s; \
time = u; \
}
#define UTIME_TO_TIME_T \
time_t timet[2]; \
struct timet time; \
if (utime->now) \
time = NULL; \
else { \
timet[0] = utime->atime_s; \
timet[1] = utime->mtime_s; \
time = &timet; \
} \
#define UTIME_HAVE_DIR_FD (defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMENSAT))
#if UTIME_HAVE_DIR_FD
static int
utime_dir_fd(utime_t *utime, int dir_fd, char *path, int follow_symlinks)
{
#ifdef HAVE_UTIMENSAT
int flags = follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW;
UTIME_TO_TIMESPEC;
return utimensat(dir_fd, path, time, flags);
#elif defined(HAVE_FUTIMESAT)
UTIME_TO_TIMEVAL;
/*
* follow_symlinks will never be false here;
* we only allow !follow_symlinks and dir_fd together
* if we have utimensat()
*/
assert(follow_symlinks);
return futimesat(dir_fd, path, time);
#endif
}
#define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_converter
#else
#define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_unavailable
#endif
#define UTIME_HAVE_FD (defined(HAVE_FUTIMES) || defined(HAVE_FUTIMENS))
#if UTIME_HAVE_FD
static int
utime_fd(utime_t *utime, int fd)
{
#ifdef HAVE_FUTIMENS
UTIME_TO_TIMESPEC;
return futimens(fd, time);
#else
UTIME_TO_TIMEVAL;
return futimes(fd, time);
#endif
}
#define PATH_UTIME_HAVE_FD 1
#else
#define PATH_UTIME_HAVE_FD 0
#endif
#define UTIME_HAVE_NOFOLLOW_SYMLINKS \
(defined(HAVE_UTIMENSAT) || defined(HAVE_LUTIMES))
#if UTIME_HAVE_NOFOLLOW_SYMLINKS
static int
utime_nofollow_symlinks(utime_t *utime, char *path)
{
#ifdef HAVE_UTIMENSAT
UTIME_TO_TIMESPEC;
return utimensat(DEFAULT_DIR_FD, path, time, AT_SYMLINK_NOFOLLOW);
#else
UTIME_TO_TIMEVAL;
return lutimes(path, time);
#endif
}
#endif
#ifndef MS_WINDOWS
static int
utime_default(utime_t *utime, char *path)
{
#ifdef HAVE_UTIMENSAT
UTIME_TO_TIMESPEC;
return utimensat(DEFAULT_DIR_FD, path, time, 0);
#elif defined(HAVE_UTIMES)
UTIME_TO_TIMEVAL;
return utimes(path, time);
#elif defined(HAVE_UTIME_H)
UTIME_TO_UTIMBUF;
return utime(path, time);
#else
UTIME_TO_TIME_T;
return utime(path, time);
#endif
}
#endif
static int
split_py_long_to_s_and_ns(PyObject *py_long, time_t *s, long *ns)
{
int result = 0;
PyObject *divmod;
divmod = PyNumber_Divmod(py_long, billion);
if (!divmod)
goto exit;
*s = _PyLong_AsTime_t(PyTuple_GET_ITEM(divmod, 0));
if ((*s == -1) && PyErr_Occurred())
goto exit;
*ns = PyLong_AsLong(PyTuple_GET_ITEM(divmod, 1));
if ((*ns == -1) && PyErr_Occurred())
goto exit;
result = 1;
exit:
Py_XDECREF(divmod);
return result;
}
/*[clinic input]
os.utime
path: path_t(allow_fd='PATH_UTIME_HAVE_FD')
times: object = NULL
*
ns: object = NULL
dir_fd: dir_fd(requires='futimensat') = None
follow_symlinks: bool=True
# "utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)\n\
Set the access and modified time of path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
If times is not None, it must be a tuple (atime, mtime);
atime and mtime should be expressed as float seconds since the epoch.
If ns is not None, it must be a tuple (atime_ns, mtime_ns);
atime_ns and mtime_ns should be expressed as integer nanoseconds
since the epoch.
If both times and ns are None, utime uses the current time.
Specifying tuples for both times and ns is an error.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, utime will modify the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path
as an open file descriptor.
dir_fd and follow_symlinks may not be available on your platform.
If they are unavailable, using them will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_utime__doc__,
"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
" follow_symlinks=True)\n"
"--\n"
"\n"
"Set the access and modified time of path.\n"
"\n"
"path may always be specified as a string.\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.\n"
"\n"
"If times is not None, it must be a tuple (atime, mtime);\n"
" atime and mtime should be expressed as float seconds since the epoch.\n"
"If ns is not None, it must be a tuple (atime_ns, mtime_ns);\n"
" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
" since the epoch.\n"
"If both times and ns are None, utime uses the current time.\n"
"Specifying tuples for both times and ns is an error.\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, utime will modify the symbolic link itself instead of the file the\n"
" link points to.\n"
"It is an error to use dir_fd or follow_symlinks when specifying path\n"
" as an open file descriptor.\n"
"dir_fd and follow_symlinks may not be available on your platform.\n"
" If they are unavailable, using them will raise a NotImplementedError.");
#define OS_UTIME_METHODDEF \
{"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__},
static PyObject *
os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times, PyObject *ns, int dir_fd, int follow_symlinks);
static PyObject *
os_utime(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
PyObject *times = NULL;
PyObject *ns = NULL;
int dir_fd = DEFAULT_DIR_FD;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|O$OO&p:utime", _keywords,
path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
goto exit;
return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times, PyObject *ns, int dir_fd, int follow_symlinks)
/*[clinic end generated code: output=891489c35cc68c5d input=1f18c17d5941aa82]*/
{
#ifdef MS_WINDOWS
HANDLE hFile;
FILETIME atime, mtime;
#else
int result;
#endif
PyObject *return_value = NULL;
utime_t utime;
memset(&utime, 0, sizeof(utime_t));
if (times && (times != Py_None) && ns) {
PyErr_SetString(PyExc_ValueError,
"utime: you may specify either 'times'"
" or 'ns' but not both");
goto exit;
}
if (times && (times != Py_None)) {
time_t a_sec, m_sec;
long a_nsec, m_nsec;
if (!PyTuple_CheckExact(times) || (PyTuple_Size(times) != 2)) {
PyErr_SetString(PyExc_TypeError,
"utime: 'times' must be either"
" a tuple of two ints or None");
goto exit;
}
utime.now = 0;
if (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0),
&a_sec, &a_nsec, _PyTime_ROUND_DOWN) == -1 ||
_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1),
&m_sec, &m_nsec, _PyTime_ROUND_DOWN) == -1) {
goto exit;
}
utime.atime_s = a_sec;
utime.atime_ns = a_nsec;
utime.mtime_s = m_sec;
utime.mtime_ns = m_nsec;
}
else if (ns) {
if (!PyTuple_CheckExact(ns) || (PyTuple_Size(ns) != 2)) {
PyErr_SetString(PyExc_TypeError,
"utime: 'ns' must be a tuple of two ints");
goto exit;
}
utime.now = 0;
if (!split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 0),
&utime.atime_s, &utime.atime_ns) ||
!split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 1),
&utime.mtime_s, &utime.mtime_ns)) {
goto exit;
}
}
else {
/* times and ns are both None/unspecified. use "now". */
utime.now = 1;
}
#if !UTIME_HAVE_NOFOLLOW_SYMLINKS
if (follow_symlinks_specified("utime", follow_symlinks))
goto exit;
#endif
if (path_and_dir_fd_invalid("utime", path, dir_fd) ||
dir_fd_and_fd_invalid("utime", dir_fd, path->fd) ||
fd_and_follow_symlinks_invalid("utime", path->fd, follow_symlinks))
goto exit;
#if !defined(HAVE_UTIMENSAT)
if ((dir_fd != DEFAULT_DIR_FD) && (!follow_symlinks)) {
PyErr_SetString(PyExc_ValueError,
"utime: cannot use dir_fd and follow_symlinks "
"together on this platform");
goto exit;
}
#endif
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (path->wide)
hFile = CreateFileW(path->wide, FILE_WRITE_ATTRIBUTES, 0,
NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);
else
hFile = CreateFileA(path->narrow, FILE_WRITE_ATTRIBUTES, 0,
NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);
Py_END_ALLOW_THREADS
if (hFile == INVALID_HANDLE_VALUE) {
path_error(path);
goto exit;
}
if (utime.now) {
GetSystemTimeAsFileTime(&mtime);
atime = mtime;
}
else {
time_t_to_FILE_TIME(utime.atime_s, utime.atime_ns, &atime);
time_t_to_FILE_TIME(utime.mtime_s, utime.mtime_ns, &mtime);
}
if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
/* Avoid putting the file name into the error here,
as that may confuse the user into believing that
something is wrong with the file, when it also
could be the time stamp that gives a problem. */
PyErr_SetFromWindowsErr(0);
goto exit;
}
#else /* MS_WINDOWS */
Py_BEGIN_ALLOW_THREADS
#if UTIME_HAVE_NOFOLLOW_SYMLINKS
if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
result = utime_nofollow_symlinks(&utime, path->narrow);
else
#endif
#if UTIME_HAVE_DIR_FD
if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks))
result = utime_dir_fd(&utime, dir_fd, path->narrow, follow_symlinks);
else
#endif
#if UTIME_HAVE_FD
if (path->fd != -1)
result = utime_fd(&utime, path->fd);
else
#endif
result = utime_default(&utime, path->narrow);
Py_END_ALLOW_THREADS
if (result < 0) {
/* see previous comment about not putting filename in error here */
return_value = posix_error();
goto exit;
}
#endif /* MS_WINDOWS */
Py_INCREF(Py_None);
return_value = Py_None;
exit:
#ifdef MS_WINDOWS
if (hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
#endif
return return_value;
}
/* Process operations */
/*[clinic input]
os._exit
status: int
Exit to the system with specified status, without normal exit processing.
[clinic start generated code]*/
PyDoc_STRVAR(os__exit__doc__,
"_exit($module, /, status)\n"
"--\n"
"\n"
"Exit to the system with specified status, without normal exit processing.");
#define OS__EXIT_METHODDEF \
{"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__},
static PyObject *
os__exit_impl(PyModuleDef *module, int status);
static PyObject *
os__exit(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:_exit", _keywords,
&status))
goto exit;
return_value = os__exit_impl(module, status);
exit:
return return_value;
}
static PyObject *
os__exit_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=4f9858c4cc2dcb89 input=5e6d57556b0c4a62]*/
{
_exit(status);
return NULL; /* Make gcc -Wall happy */
}
#if defined(HAVE_EXECV) || defined(HAVE_SPAWNV)
static void
free_string_array(char **array, Py_ssize_t count)
{
Py_ssize_t i;
for (i = 0; i < count; i++)
PyMem_Free(array[i]);
PyMem_DEL(array);
}
static
int fsconvert_strdup(PyObject *o, char**out)
{
PyObject *bytes;
Py_ssize_t size;
if (!PyUnicode_FSConverter(o, &bytes))
return 0;
size = PyBytes_GET_SIZE(bytes);
*out = PyMem_Malloc(size+1);
if (!*out) {
PyErr_NoMemory();
return 0;
}
memcpy(*out, PyBytes_AsString(bytes), size+1);
Py_DECREF(bytes);
return 1;
}
#endif
#if defined(HAVE_EXECV) || defined (HAVE_FEXECVE)
static char**
parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
{
char **envlist;
Py_ssize_t i, pos, envc;
PyObject *keys=NULL, *vals=NULL;
PyObject *key, *val, *key2, *val2;
char *p, *k, *v;
size_t len;
i = PyMapping_Size(env);
if (i < 0)
return NULL;
envlist = PyMem_NEW(char *, i + 1);
if (envlist == NULL) {
PyErr_NoMemory();
return NULL;
}
envc = 0;
keys = PyMapping_Keys(env);
if (!keys)
goto error;
vals = PyMapping_Values(env);
if (!vals)
goto error;
if (!PyList_Check(keys) || !PyList_Check(vals)) {
PyErr_Format(PyExc_TypeError,
"env.keys() or env.values() is not a list");
goto error;
}
for (pos = 0; pos < i; pos++) {
key = PyList_GetItem(keys, pos);
val = PyList_GetItem(vals, pos);
if (!key || !val)
goto error;
if (PyUnicode_FSConverter(key, &key2) == 0)
goto error;
if (PyUnicode_FSConverter(val, &val2) == 0) {
Py_DECREF(key2);
goto error;
}
k = PyBytes_AsString(key2);
v = PyBytes_AsString(val2);
len = PyBytes_GET_SIZE(key2) + PyBytes_GET_SIZE(val2) + 2;
p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
Py_DECREF(key2);
Py_DECREF(val2);
goto error;
}
PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
Py_DECREF(key2);
Py_DECREF(val2);
}
Py_DECREF(vals);
Py_DECREF(keys);
envlist[envc] = 0;
*envc_ptr = envc;
return envlist;
error:
Py_XDECREF(keys);
Py_XDECREF(vals);
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
return NULL;
}
static char**
parse_arglist(PyObject* argv, Py_ssize_t *argc)
{
int i;
char **argvlist = PyMem_NEW(char *, *argc+1);
if (argvlist == NULL) {
PyErr_NoMemory();
return NULL;
}
for (i = 0; i < *argc; i++) {
PyObject* item = PySequence_ITEM(argv, i);
if (item == NULL)
goto fail;
if (!fsconvert_strdup(item, &argvlist[i])) {
Py_DECREF(item);
goto fail;
}
Py_DECREF(item);
}
argvlist[*argc] = NULL;
return argvlist;
fail:
*argc = i;
free_string_array(argvlist, *argc);
return NULL;
}
#endif
#ifdef HAVE_EXECV
/*[clinic input]
os.execv
path: FSConverter
Path of executable file.
argv: object
Tuple or list of strings.
/
Execute an executable path with arguments, replacing current process.
[clinic start generated code]*/
PyDoc_STRVAR(os_execv__doc__,
"execv($module, path, argv, /)\n"
"--\n"
"\n"
"Execute an executable path with arguments, replacing current process.\n"
"\n"
" path\n"
" Path of executable file.\n"
" argv\n"
" Tuple or list of strings.");
#define OS_EXECV_METHODDEF \
{"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
static PyObject *
os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv);
static PyObject *
os_execv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *path = NULL;
PyObject *argv;
if (!PyArg_ParseTuple(args,
"O&O:execv",
PyUnicode_FSConverter, &path, &argv))
goto exit;
return_value = os_execv_impl(module, path, argv);
exit:
/* Cleanup for path */
Py_XDECREF(path);
return return_value;
}
static PyObject *
os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv)
/*[clinic end generated code: output=b0f5f2caa6097edc input=96041559925e5229]*/
{
char *path_char;
char **argvlist;
Py_ssize_t argc;
/* execv has two arguments: (path, argv), where
argv is a list or tuple of strings. */
path_char = PyBytes_AsString(path);
if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
PyErr_SetString(PyExc_TypeError,
"execv() arg 2 must be a tuple or list");
return NULL;
}
argc = PySequence_Size(argv);
if (argc < 1) {
PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
return NULL;
}
argvlist = parse_arglist(argv, &argc);
if (argvlist == NULL) {
return NULL;
}
execv(path_char, argvlist);
/* If we get here it's definitely an error */
free_string_array(argvlist, argc);
return posix_error();
}
/*[clinic input]
os.execve
path: path_t(allow_fd='PATH_HAVE_FEXECVE')
Path of executable file.
argv: object
Tuple or list of strings.
env: object
Dictionary of strings mapping to strings.
Execute an executable path with arguments, replacing current process.
[clinic start generated code]*/
PyDoc_STRVAR(os_execve__doc__,
"execve($module, /, path, argv, env)\n"
"--\n"
"\n"
"Execute an executable path with arguments, replacing current process.\n"
"\n"
" path\n"
" Path of executable file.\n"
" argv\n"
" Tuple or list of strings.\n"
" env\n"
" Dictionary of strings mapping to strings.");
#define OS_EXECVE_METHODDEF \
{"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__},
static PyObject *
os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv, PyObject *env);
static PyObject *
os_execve(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "argv", "env", NULL};
path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
PyObject *argv;
PyObject *env;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&OO:execve", _keywords,
path_converter, &path, &argv, &env))
goto exit;
return_value = os_execve_impl(module, &path, argv, env);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv, PyObject *env)
/*[clinic end generated code: output=fb283760f5d15ab7 input=626804fa092606d9]*/
{
char **argvlist = NULL;
char **envlist;
Py_ssize_t argc, envc;
/* execve has three arguments: (path, argv, env), where
argv is a list or tuple of strings and env is a dictionary
like posix.environ. */
if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
PyErr_SetString(PyExc_TypeError,
"execve: argv must be a tuple or list");
goto fail;
}
argc = PySequence_Size(argv);
if (!PyMapping_Check(env)) {
PyErr_SetString(PyExc_TypeError,
"execve: environment must be a mapping object");
goto fail;
}
argvlist = parse_arglist(argv, &argc);
if (argvlist == NULL) {
goto fail;
}
envlist = parse_envlist(env, &envc);
if (envlist == NULL)
goto fail;
#ifdef HAVE_FEXECVE
if (path->fd > -1)
fexecve(path->fd, argvlist, envlist);
else
#endif
execve(path->narrow, argvlist, envlist);
/* If we get here it's definitely an error */
path_error(path);
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
fail:
if (argvlist)
free_string_array(argvlist, argc);
return NULL;
}
#endif /* HAVE_EXECV */
#ifdef HAVE_SPAWNV
/*[clinic input]
os.spawnv
mode: int
Mode of process creation.
path: FSConverter
Path of executable file.
argv: object
Tuple or list of strings.
/
Execute the program specified by path in a new process.
[clinic start generated code]*/
PyDoc_STRVAR(os_spawnv__doc__,
"spawnv($module, mode, path, argv, /)\n"
"--\n"
"\n"
"Execute the program specified by path in a new process.\n"
"\n"
" mode\n"
" Mode of process creation.\n"
" path\n"
" Path of executable file.\n"
" argv\n"
" Tuple or list of strings.");
#define OS_SPAWNV_METHODDEF \
{"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
static PyObject *
os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv);
static PyObject *
os_spawnv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int mode;
PyObject *path = NULL;
PyObject *argv;
if (!PyArg_ParseTuple(args,
"iO&O:spawnv",
&mode, PyUnicode_FSConverter, &path, &argv))
goto exit;
return_value = os_spawnv_impl(module, mode, path, argv);
exit:
/* Cleanup for path */
Py_XDECREF(path);
return return_value;
}
static PyObject *
os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv)
/*[clinic end generated code: output=dfee6be062e780e3 input=042c91dfc1e6debc]*/
{
char *path_char;
char **argvlist;
int i;
Py_ssize_t argc;
Py_intptr_t spawnval;
PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnv has three arguments: (mode, path, argv), where
argv is a list or tuple of strings. */
path_char = PyBytes_AsString(path);
if (PyList_Check(argv)) {
argc = PyList_Size(argv);
getitem = PyList_GetItem;
}
else if (PyTuple_Check(argv)) {
argc = PyTuple_Size(argv);
getitem = PyTuple_GetItem;
}
else {
PyErr_SetString(PyExc_TypeError,
"spawnv() arg 2 must be a tuple or list");
return NULL;
}
argvlist = PyMem_NEW(char *, argc+1);
if (argvlist == NULL) {
return PyErr_NoMemory();
}
for (i = 0; i < argc; i++) {
if (!fsconvert_strdup((*getitem)(argv, i),
&argvlist[i])) {
free_string_array(argvlist, i);
PyErr_SetString(
PyExc_TypeError,
"spawnv() arg 2 must contain only strings");
return NULL;
}
}
argvlist[argc] = NULL;
if (mode == _OLD_P_OVERLAY)
mode = _P_OVERLAY;
Py_BEGIN_ALLOW_THREADS
spawnval = _spawnv(mode, path_char, argvlist);
Py_END_ALLOW_THREADS
free_string_array(argvlist, argc);
if (spawnval == -1)
return posix_error();
else
return Py_BuildValue(_Py_PARSE_INTPTR, spawnval);
}
/*[clinic input]
os.spawnve
mode: int
Mode of process creation.
path: FSConverter
Path of executable file.
argv: object
Tuple or list of strings.
env: object
Dictionary of strings mapping to strings.
/
Execute the program specified by path in a new process.
[clinic start generated code]*/
PyDoc_STRVAR(os_spawnve__doc__,
"spawnve($module, mode, path, argv, env, /)\n"
"--\n"
"\n"
"Execute the program specified by path in a new process.\n"
"\n"
" mode\n"
" Mode of process creation.\n"
" path\n"
" Path of executable file.\n"
" argv\n"
" Tuple or list of strings.\n"
" env\n"
" Dictionary of strings mapping to strings.");
#define OS_SPAWNVE_METHODDEF \
{"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
static PyObject *
os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv, PyObject *env);
static PyObject *
os_spawnve(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int mode;
PyObject *path = NULL;
PyObject *argv;
PyObject *env;
if (!PyArg_ParseTuple(args,
"iO&OO:spawnve",
&mode, PyUnicode_FSConverter, &path, &argv, &env))
goto exit;
return_value = os_spawnve_impl(module, mode, path, argv, env);
exit:
/* Cleanup for path */
Py_XDECREF(path);
return return_value;
}
static PyObject *
os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv, PyObject *env)
/*[clinic end generated code: output=6f7df38473f63c7c input=02362fd937963f8f]*/
{
char *path_char;
char **argvlist;
char **envlist;
PyObject *res = NULL;
Py_ssize_t argc, i, envc;
Py_intptr_t spawnval;
PyObject *(*getitem)(PyObject *, Py_ssize_t);
Py_ssize_t lastarg = 0;
/* spawnve has four arguments: (mode, path, argv, env), where
argv is a list or tuple of strings and env is a dictionary
like posix.environ. */
path_char = PyBytes_AsString(path);
if (PyList_Check(argv)) {
argc = PyList_Size(argv);
getitem = PyList_GetItem;
}
else if (PyTuple_Check(argv)) {
argc = PyTuple_Size(argv);
getitem = PyTuple_GetItem;
}
else {
PyErr_SetString(PyExc_TypeError,
"spawnve() arg 2 must be a tuple or list");
goto fail_0;
}
if (!PyMapping_Check(env)) {
PyErr_SetString(PyExc_TypeError,
"spawnve() arg 3 must be a mapping object");
goto fail_0;
}
argvlist = PyMem_NEW(char *, argc+1);
if (argvlist == NULL) {
PyErr_NoMemory();
goto fail_0;
}
for (i = 0; i < argc; i++) {
if (!fsconvert_strdup((*getitem)(argv, i),
&argvlist[i]))
{
lastarg = i;
goto fail_1;
}
}
lastarg = argc;
argvlist[argc] = NULL;
envlist = parse_envlist(env, &envc);
if (envlist == NULL)
goto fail_1;
if (mode == _OLD_P_OVERLAY)
mode = _P_OVERLAY;
Py_BEGIN_ALLOW_THREADS
spawnval = _spawnve(mode, path_char, argvlist, envlist);
Py_END_ALLOW_THREADS
if (spawnval == -1)
(void) posix_error();
else
res = Py_BuildValue(_Py_PARSE_INTPTR, spawnval);
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
fail_1:
free_string_array(argvlist, lastarg);
fail_0:
return res;
}
#endif /* HAVE_SPAWNV */
#ifdef HAVE_FORK1
/*[clinic input]
os.fork1
Fork a child process with a single multiplexed (i.e., not bound) thread.
Return 0 to child process and PID of child to parent process.
[clinic start generated code]*/
PyDoc_STRVAR(os_fork1__doc__,
"fork1($module, /)\n"
"--\n"
"\n"
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
"\n"
"Return 0 to child process and PID of child to parent process.");
#define OS_FORK1_METHODDEF \
{"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
static PyObject *
os_fork1_impl(PyModuleDef *module);
static PyObject *
os_fork1(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_fork1_impl(module);
}
static PyObject *
os_fork1_impl(PyModuleDef *module)
/*[clinic end generated code: output=fa04088d6bc02efa input=12db02167893926e]*/
{
pid_t pid;
int result = 0;
_PyImport_AcquireLock();
pid = fork1();
if (pid == 0) {
/* child: this clobbers and resets the import lock. */
PyOS_AfterFork();
} else {
/* parent: release the import lock. */
result = _PyImport_ReleaseLock();
}
if (pid == -1)
return posix_error();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock");
return NULL;
}
return PyLong_FromPid(pid);
}
#endif /* HAVE_FORK1 */
#ifdef HAVE_FORK
/*[clinic input]
os.fork
Fork a child process.
Return 0 to child process and PID of child to parent process.
[clinic start generated code]*/
PyDoc_STRVAR(os_fork__doc__,
"fork($module, /)\n"
"--\n"
"\n"
"Fork a child process.\n"
"\n"
"Return 0 to child process and PID of child to parent process.");
#define OS_FORK_METHODDEF \
{"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
static PyObject *
os_fork_impl(PyModuleDef *module);
static PyObject *
os_fork(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_fork_impl(module);
}
static PyObject *
os_fork_impl(PyModuleDef *module)
/*[clinic end generated code: output=b3c8e6bdc11eedc6 input=13c956413110eeaa]*/
{
pid_t pid;
int result = 0;
_PyImport_AcquireLock();
pid = fork();
if (pid == 0) {
/* child: this clobbers and resets the import lock. */
PyOS_AfterFork();
} else {
/* parent: release the import lock. */
result = _PyImport_ReleaseLock();
}
if (pid == -1)
return posix_error();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock");
return NULL;
}
return PyLong_FromPid(pid);
}
#endif /* HAVE_FORK */
#ifdef HAVE_SCHED_H
#ifdef HAVE_SCHED_GET_PRIORITY_MAX
/*[clinic input]
os.sched_get_priority_max
policy: int
Get the maximum scheduling priority for policy.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
"sched_get_priority_max($module, /, policy)\n"
"--\n"
"\n"
"Get the maximum scheduling priority for policy.");
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
{"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__},
static PyObject *
os_sched_get_priority_max_impl(PyModuleDef *module, int policy);
static PyObject *
os_sched_get_priority_max(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"policy", NULL};
int policy;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:sched_get_priority_max", _keywords,
&policy))
goto exit;
return_value = os_sched_get_priority_max_impl(module, policy);
exit:
return return_value;
}
static PyObject *
os_sched_get_priority_max_impl(PyModuleDef *module, int policy)
/*[clinic end generated code: output=a580a52f25238c1f input=2097b7998eca6874]*/
{
int max;
max = sched_get_priority_max(policy);
if (max < 0)
return posix_error();
return PyLong_FromLong(max);
}
/*[clinic input]
os.sched_get_priority_min
policy: int
Get the minimum scheduling priority for policy.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
"sched_get_priority_min($module, /, policy)\n"
"--\n"
"\n"
"Get the minimum scheduling priority for policy.");
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
{"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__},
static PyObject *
os_sched_get_priority_min_impl(PyModuleDef *module, int policy);
static PyObject *
os_sched_get_priority_min(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"policy", NULL};
int policy;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:sched_get_priority_min", _keywords,
&policy))
goto exit;
return_value = os_sched_get_priority_min_impl(module, policy);
exit:
return return_value;
}
static PyObject *
os_sched_get_priority_min_impl(PyModuleDef *module, int policy)
/*[clinic end generated code: output=bad8ba10e7d0e977 input=21bc8fa0d70983bf]*/
{
int min = sched_get_priority_min(policy);
if (min < 0)
return posix_error();
return PyLong_FromLong(min);
}
#endif /* HAVE_SCHED_GET_PRIORITY_MAX */
#ifdef HAVE_SCHED_SETSCHEDULER
/*[clinic input]
os.sched_getscheduler
pid: pid_t
/
Get the scheduling policy for the process identifiedy by pid.
Passing 0 for pid returns the scheduling policy for the calling process.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_getscheduler__doc__,
"sched_getscheduler($module, pid, /)\n"
"--\n"
"\n"
"Get the scheduling policy for the process identifiedy by pid.\n"
"\n"
"Passing 0 for pid returns the scheduling policy for the calling process.");
#define OS_SCHED_GETSCHEDULER_METHODDEF \
{"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_VARARGS, os_sched_getscheduler__doc__},
static PyObject *
os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_sched_getscheduler(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID ":sched_getscheduler",
&pid))
goto exit;
return_value = os_sched_getscheduler_impl(module, pid);
exit:
return return_value;
}
static PyObject *
os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=e0d6244207b1d828 input=5f14cfd1f189e1a0]*/
{
int policy;
policy = sched_getscheduler(pid);
if (policy < 0)
return posix_error();
return PyLong_FromLong(policy);
}
#endif /* HAVE_SCHED_SETSCHEDULER */
#if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)
/*[clinic input]
class os.sched_param "PyObject *" "&SchedParamType"
@classmethod
os.sched_param.__new__
sched_priority: object
A scheduling parameter.
Current has only one field: sched_priority");
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_param__doc__,
"sched_param(sched_priority)\n"
"--\n"
"\n"
"Current has only one field: sched_priority\");\n"
"\n"
" sched_priority\n"
" A scheduling parameter.");
static PyObject *
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
static PyObject *
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"sched_priority", NULL};
PyObject *sched_priority;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O:sched_param", _keywords,
&sched_priority))
goto exit;
return_value = os_sched_param_impl(type, sched_priority);
exit:
return return_value;
}
static PyObject *
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
/*[clinic end generated code: output=d3791e345f7fe573 input=73a4c22f7071fc62]*/
{
PyObject *res;
res = PyStructSequence_New(type);
if (!res)
return NULL;
Py_INCREF(sched_priority);
PyStructSequence_SET_ITEM(res, 0, sched_priority);
return res;
}
static PyStructSequence_Field sched_param_fields[] = {
{"sched_priority", "the scheduling priority"},
{0}
};
static PyStructSequence_Desc sched_param_desc = {
"sched_param", /* name */
os_sched_param__doc__, /* doc */
sched_param_fields,
1
};
static int
convert_sched_param(PyObject *param, struct sched_param *res)
{
long priority;
if (Py_TYPE(param) != &SchedParamType) {
PyErr_SetString(PyExc_TypeError, "must have a sched_param object");
return 0;
}
priority = PyLong_AsLong(PyStructSequence_GET_ITEM(param, 0));
if (priority == -1 && PyErr_Occurred())
return 0;
if (priority > INT_MAX || priority < INT_MIN) {
PyErr_SetString(PyExc_OverflowError, "sched_priority out of range");
return 0;
}
res->sched_priority = Py_SAFE_DOWNCAST(priority, long, int);
return 1;
}
#endif /* defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM) */
#ifdef HAVE_SCHED_SETSCHEDULER
/*[clinic input]
os.sched_setscheduler
pid: pid_t
policy: int
param: sched_param
/
Set the scheduling policy for the process identified by pid.
If pid is 0, the calling process is changed.
param is an instance of sched_param.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_setscheduler__doc__,
"sched_setscheduler($module, pid, policy, param, /)\n"
"--\n"
"\n"
"Set the scheduling policy for the process identified by pid.\n"
"\n"
"If pid is 0, the calling process is changed.\n"
"param is an instance of sched_param.");
#define OS_SCHED_SETSCHEDULER_METHODDEF \
{"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
static PyObject *
os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy, struct sched_param *param);
static PyObject *
os_sched_setscheduler(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
int policy;
struct sched_param param;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "iO&:sched_setscheduler",
&pid, &policy, convert_sched_param, ¶m))
goto exit;
return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m);
exit:
return return_value;
}
static PyObject *
os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy, struct sched_param *param)
/*[clinic end generated code: output=36abdb73f81c224f input=c581f9469a5327dd]*/
{
/*
** sched_setscheduler() returns 0 in Linux, but the previous
** scheduling policy under Solaris/Illumos, and others.
** On error, -1 is returned in all Operating Systems.
*/
if (sched_setscheduler(pid, policy, param) == -1)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SCHED_SETSCHEDULER*/
#ifdef HAVE_SCHED_SETPARAM
/*[clinic input]
os.sched_getparam
pid: pid_t
/
Returns scheduling parameters for the process identified by pid.
If pid is 0, returns parameters for the calling process.
Return value is an instance of sched_param.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_getparam__doc__,
"sched_getparam($module, pid, /)\n"
"--\n"
"\n"
"Returns scheduling parameters for the process identified by pid.\n"
"\n"
"If pid is 0, returns parameters for the calling process.\n"
"Return value is an instance of sched_param.");
#define OS_SCHED_GETPARAM_METHODDEF \
{"sched_getparam", (PyCFunction)os_sched_getparam, METH_VARARGS, os_sched_getparam__doc__},
static PyObject *
os_sched_getparam_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_sched_getparam(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID ":sched_getparam",
&pid))
goto exit;
return_value = os_sched_getparam_impl(module, pid);
exit:
return return_value;
}
static PyObject *
os_sched_getparam_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=b33acc8db004a8c9 input=18a1ef9c2efae296]*/
{
struct sched_param param;
PyObject *result;
PyObject *priority;
if (sched_getparam(pid, ¶m))
return posix_error();
result = PyStructSequence_New(&SchedParamType);
if (!result)
return NULL;
priority = PyLong_FromLong(param.sched_priority);
if (!priority) {
Py_DECREF(result);
return NULL;
}
PyStructSequence_SET_ITEM(result, 0, priority);
return result;
}
/*[clinic input]
os.sched_setparam
pid: pid_t
param: sched_param
/
Set scheduling parameters for the process identified by pid.
If pid is 0, sets parameters for the calling process.
param should be an instance of sched_param.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_setparam__doc__,
"sched_setparam($module, pid, param, /)\n"
"--\n"
"\n"
"Set scheduling parameters for the process identified by pid.\n"
"\n"
"If pid is 0, sets parameters for the calling process.\n"
"param should be an instance of sched_param.");
#define OS_SCHED_SETPARAM_METHODDEF \
{"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
static PyObject *
os_sched_setparam_impl(PyModuleDef *module, pid_t pid, struct sched_param *param);
static PyObject *
os_sched_setparam(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
struct sched_param param;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "O&:sched_setparam",
&pid, convert_sched_param, ¶m))
goto exit;
return_value = os_sched_setparam_impl(module, pid, ¶m);
exit:
return return_value;
}
static PyObject *
os_sched_setparam_impl(PyModuleDef *module, pid_t pid, struct sched_param *param)
/*[clinic end generated code: output=488bdf5bcbe0d4e8 input=6b8d6dfcecdc21bd]*/
{
if (sched_setparam(pid, param))
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SCHED_SETPARAM */
#ifdef HAVE_SCHED_RR_GET_INTERVAL
/*[clinic input]
os.sched_rr_get_interval -> double
pid: pid_t
/
Return the round-robin quantum for the process identified by pid, in seconds.
Value returned is a float.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
"sched_rr_get_interval($module, pid, /)\n"
"--\n"
"\n"
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
"\n"
"Value returned is a float.");
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
{"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_VARARGS, os_sched_rr_get_interval__doc__},
static double
os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_sched_rr_get_interval(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
double _return_value;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID ":sched_rr_get_interval",
&pid))
goto exit;
_return_value = os_sched_rr_get_interval_impl(module, pid);
if ((_return_value == -1.0) && PyErr_Occurred())
goto exit;
return_value = PyFloat_FromDouble(_return_value);
exit:
return return_value;
}
static double
os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=5b3b8d1f27fb2c0a input=2a973da15cca6fae]*/
{
struct timespec interval;
if (sched_rr_get_interval(pid, &interval)) {
posix_error();
return -1.0;
}
return (double)interval.tv_sec + 1e-9*interval.tv_nsec;
}
#endif /* HAVE_SCHED_RR_GET_INTERVAL */
/*[clinic input]
os.sched_yield
Voluntarily relinquish the CPU.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_yield__doc__,
"sched_yield($module, /)\n"
"--\n"
"\n"
"Voluntarily relinquish the CPU.");
#define OS_SCHED_YIELD_METHODDEF \
{"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
static PyObject *
os_sched_yield_impl(PyModuleDef *module);
static PyObject *
os_sched_yield(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_sched_yield_impl(module);
}
static PyObject *
os_sched_yield_impl(PyModuleDef *module)
/*[clinic end generated code: output=9d2e5f29f1370324 input=e54d6f98189391d4]*/
{
if (sched_yield())
return posix_error();
Py_RETURN_NONE;
}
#ifdef HAVE_SCHED_SETAFFINITY
/* The minimum number of CPUs allocated in a cpu_set_t */
static const int NCPUS_START = sizeof(unsigned long) * CHAR_BIT;
/*[clinic input]
os.sched_setaffinity
pid: pid_t
mask : object
/
Set the CPU affinity of the process identified by pid to mask.
mask should be an iterable of integers identifying CPUs.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_setaffinity__doc__,
"sched_setaffinity($module, pid, mask, /)\n"
"--\n"
"\n"
"Set the CPU affinity of the process identified by pid to mask.\n"
"\n"
"mask should be an iterable of integers identifying CPUs.");
#define OS_SCHED_SETAFFINITY_METHODDEF \
{"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
static PyObject *
os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask);
static PyObject *
os_sched_setaffinity(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
PyObject *mask;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "O:sched_setaffinity",
&pid, &mask))
goto exit;
return_value = os_sched_setaffinity_impl(module, pid, mask);
exit:
return return_value;
}
static PyObject *
os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask)
/*[clinic end generated code: output=5199929738130196 input=a0791a597c7085ba]*/
{
int ncpus;
size_t setsize;
cpu_set_t *cpu_set = NULL;
PyObject *iterator = NULL, *item;
iterator = PyObject_GetIter(mask);
if (iterator == NULL)
return NULL;
ncpus = NCPUS_START;
setsize = CPU_ALLOC_SIZE(ncpus);
cpu_set = CPU_ALLOC(ncpus);
if (cpu_set == NULL) {
PyErr_NoMemory();
goto error;
}
CPU_ZERO_S(setsize, cpu_set);
while ((item = PyIter_Next(iterator))) {
long cpu;
if (!PyLong_Check(item)) {
PyErr_Format(PyExc_TypeError,
"expected an iterator of ints, "
"but iterator yielded %R",
Py_TYPE(item));
Py_DECREF(item);
goto error;
}
cpu = PyLong_AsLong(item);
Py_DECREF(item);
if (cpu < 0) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_ValueError, "negative CPU number");
goto error;
}
if (cpu > INT_MAX - 1) {
PyErr_SetString(PyExc_OverflowError, "CPU number too large");
goto error;
}
if (cpu >= ncpus) {
/* Grow CPU mask to fit the CPU number */
int newncpus = ncpus;
cpu_set_t *newmask;
size_t newsetsize;
while (newncpus <= cpu) {
if (newncpus > INT_MAX / 2)
newncpus = cpu + 1;
else
newncpus = newncpus * 2;
}
newmask = CPU_ALLOC(newncpus);
if (newmask == NULL) {
PyErr_NoMemory();
goto error;
}
newsetsize = CPU_ALLOC_SIZE(newncpus);
CPU_ZERO_S(newsetsize, newmask);
memcpy(newmask, cpu_set, setsize);
CPU_FREE(cpu_set);
setsize = newsetsize;
cpu_set = newmask;
ncpus = newncpus;
}
CPU_SET_S(cpu, setsize, cpu_set);
}
Py_CLEAR(iterator);
if (sched_setaffinity(pid, setsize, cpu_set)) {
posix_error();
goto error;
}
CPU_FREE(cpu_set);
Py_RETURN_NONE;
error:
if (cpu_set)
CPU_FREE(cpu_set);
Py_XDECREF(iterator);
return NULL;
}
/*[clinic input]
os.sched_getaffinity
pid: pid_t
/
Return the affinity of the process identified by pid.
The affinity is returned as a set of CPU identifiers.
[clinic start generated code]*/
PyDoc_STRVAR(os_sched_getaffinity__doc__,
"sched_getaffinity($module, pid, /)\n"
"--\n"
"\n"
"Return the affinity of the process identified by pid.\n"
"\n"
"The affinity is returned as a set of CPU identifiers.");
#define OS_SCHED_GETAFFINITY_METHODDEF \
{"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_VARARGS, os_sched_getaffinity__doc__},
static PyObject *
os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_sched_getaffinity(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID ":sched_getaffinity",
&pid))
goto exit;
return_value = os_sched_getaffinity_impl(module, pid);
exit:
return return_value;
}
static PyObject *
os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=7b273b0fca9830f0 input=eaf161936874b8a1]*/
{
int cpu, ncpus, count;
size_t setsize;
cpu_set_t *mask = NULL;
PyObject *res = NULL;
ncpus = NCPUS_START;
while (1) {
setsize = CPU_ALLOC_SIZE(ncpus);
mask = CPU_ALLOC(ncpus);
if (mask == NULL)
return PyErr_NoMemory();
if (sched_getaffinity(pid, setsize, mask) == 0)
break;
CPU_FREE(mask);
if (errno != EINVAL)
return posix_error();
if (ncpus > INT_MAX / 2) {
PyErr_SetString(PyExc_OverflowError, "could not allocate "
"a large enough CPU set");
return NULL;
}
ncpus = ncpus * 2;
}
res = PySet_New(NULL);
if (res == NULL)
goto error;
for (cpu = 0, count = CPU_COUNT_S(setsize, mask); count; cpu++) {
if (CPU_ISSET_S(cpu, setsize, mask)) {
PyObject *cpu_num = PyLong_FromLong(cpu);
--count;
if (cpu_num == NULL)
goto error;
if (PySet_Add(res, cpu_num)) {
Py_DECREF(cpu_num);
goto error;
}
Py_DECREF(cpu_num);
}
}
CPU_FREE(mask);
return res;
error:
if (mask)
CPU_FREE(mask);
Py_XDECREF(res);
return NULL;
}
#endif /* HAVE_SCHED_SETAFFINITY */
#endif /* HAVE_SCHED_H */
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
#endif /* OS_SCHED_GET_PRIORITY_MAX_METHODDEF */
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
#endif /* OS_SCHED_GET_PRIORITY_MIN_METHODDEF */
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
#define OS_SCHED_GETSCHEDULER_METHODDEF
#endif /* OS_SCHED_GETSCHEDULER_METHODDEF */
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
#define OS_SCHED_SETSCHEDULER_METHODDEF
#endif /* OS_SCHED_SETSCHEDULER_METHODDEF */
#ifndef OS_SCHED_GETPARAM_METHODDEF
#define OS_SCHED_GETPARAM_METHODDEF
#endif /* OS_SCHED_GETPARAM_METHODDEF */
#ifndef OS_SCHED_SETPARAM_METHODDEF
#define OS_SCHED_SETPARAM_METHODDEF
#endif /* OS_SCHED_SETPARAM_METHODDEF */
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF
#endif /* OS_SCHED_RR_GET_INTERVAL_METHODDEF */
#ifndef OS_SCHED_YIELD_METHODDEF
#define OS_SCHED_YIELD_METHODDEF
#endif /* OS_SCHED_YIELD_METHODDEF */
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
#define OS_SCHED_SETAFFINITY_METHODDEF
#endif /* OS_SCHED_SETAFFINITY_METHODDEF */
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
#define OS_SCHED_GETAFFINITY_METHODDEF
#endif /* OS_SCHED_GETAFFINITY_METHODDEF */
/* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */
/* IRIX has both /dev/ptc and /dev/ptmx, use ptmx */
#if defined(HAVE_DEV_PTC) && !defined(HAVE_DEV_PTMX)
#define DEV_PTY_FILE "/dev/ptc"
#define HAVE_DEV_PTMX
#else
#define DEV_PTY_FILE "/dev/ptmx"
#endif
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
#ifdef HAVE_PTY_H
#include <pty.h>
#else
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#else
#ifdef HAVE_UTIL_H
#include <util.h>
#endif /* HAVE_UTIL_H */
#endif /* HAVE_LIBUTIL_H */
#endif /* HAVE_PTY_H */
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */
#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
/*[clinic input]
os.openpty
Open a pseudo-terminal.
Return a tuple of (master_fd, slave_fd) containing open file descriptors
for both the master and slave ends.
[clinic start generated code]*/
PyDoc_STRVAR(os_openpty__doc__,
"openpty($module, /)\n"
"--\n"
"\n"
"Open a pseudo-terminal.\n"
"\n"
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
"for both the master and slave ends.");
#define OS_OPENPTY_METHODDEF \
{"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
static PyObject *
os_openpty_impl(PyModuleDef *module);
static PyObject *
os_openpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_openpty_impl(module);
}
static PyObject *
os_openpty_impl(PyModuleDef *module)
/*[clinic end generated code: output=b12d3c1735468464 input=f3d99fd99e762907]*/
{
int master_fd = -1, slave_fd = -1;
#ifndef HAVE_OPENPTY
char * slave_name;
#endif
#if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
PyOS_sighandler_t sig_saved;
#ifdef sun
extern char *ptsname(int fildes);
#endif
#endif
#ifdef HAVE_OPENPTY
if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
goto posix_error;
if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
goto error;
if (_Py_set_inheritable(slave_fd, 0, NULL) < 0)
goto error;
#elif defined(HAVE__GETPTY)
slave_name = _getpty(&master_fd, O_RDWR, 0666, 0);
if (slave_name == NULL)
goto posix_error;
if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
goto error;
slave_fd = _Py_open(slave_name, O_RDWR);
if (slave_fd < 0)
goto posix_error;
#else
master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
if (master_fd < 0)
goto posix_error;
sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL);
/* change permission of slave */
if (grantpt(master_fd) < 0) {
PyOS_setsig(SIGCHLD, sig_saved);
goto posix_error;
}
/* unlock slave */
if (unlockpt(master_fd) < 0) {
PyOS_setsig(SIGCHLD, sig_saved);
goto posix_error;
}
PyOS_setsig(SIGCHLD, sig_saved);
slave_name = ptsname(master_fd); /* get name of slave */
if (slave_name == NULL)
goto posix_error;
slave_fd = _Py_open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
if (slave_fd < 0)
goto posix_error;
if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
goto posix_error;
#if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)
ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */
ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */
#ifndef __hpux
ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat */
#endif /* __hpux */
#endif /* HAVE_CYGWIN */
#endif /* HAVE_OPENPTY */
return Py_BuildValue("(ii)", master_fd, slave_fd);
posix_error:
posix_error();
#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY)
error:
#endif
if (master_fd != -1)
close(master_fd);
if (slave_fd != -1)
close(slave_fd);
return NULL;
}
#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
#ifdef HAVE_FORKPTY
/*[clinic input]
os.forkpty
Fork a new process with a new pseudo-terminal as controlling tty.
Returns a tuple of (pid, master_fd).
Like fork(), return pid of 0 to the child process,
and pid of child to the parent process.
To both, return fd of newly opened pseudo-terminal.
[clinic start generated code]*/
PyDoc_STRVAR(os_forkpty__doc__,
"forkpty($module, /)\n"
"--\n"
"\n"
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
"\n"
"Returns a tuple of (pid, master_fd).\n"
"Like fork(), return pid of 0 to the child process,\n"
"and pid of child to the parent process.\n"
"To both, return fd of newly opened pseudo-terminal.");
#define OS_FORKPTY_METHODDEF \
{"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
static PyObject *
os_forkpty_impl(PyModuleDef *module);
static PyObject *
os_forkpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_forkpty_impl(module);
}
static PyObject *
os_forkpty_impl(PyModuleDef *module)
/*[clinic end generated code: output=d4f82958d2ed5cad input=f1f7f4bae3966010]*/
{
int master_fd = -1, result = 0;
pid_t pid;
_PyImport_AcquireLock();
pid = forkpty(&master_fd, NULL, NULL, NULL);
if (pid == 0) {
/* child: this clobbers and resets the import lock. */
PyOS_AfterFork();
} else {
/* parent: release the import lock. */
result = _PyImport_ReleaseLock();
}
if (pid == -1)
return posix_error();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock");
return NULL;
}
return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd);
}
#endif /* HAVE_FORKPTY */
#ifdef HAVE_GETEGID
/*[clinic input]
os.getegid
Return the current process's effective group id.
[clinic start generated code]*/
PyDoc_STRVAR(os_getegid__doc__,
"getegid($module, /)\n"
"--\n"
"\n"
"Return the current process\'s effective group id.");
#define OS_GETEGID_METHODDEF \
{"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
static PyObject *
os_getegid_impl(PyModuleDef *module);
static PyObject *
os_getegid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getegid_impl(module);
}
static PyObject *
os_getegid_impl(PyModuleDef *module)
/*[clinic end generated code: output=fd12c346fa41cccb input=1596f79ad1107d5d]*/
{
return _PyLong_FromGid(getegid());
}
#endif /* HAVE_GETEGID */
#ifdef HAVE_GETEUID
/*[clinic input]
os.geteuid
Return the current process's effective user id.
[clinic start generated code]*/
PyDoc_STRVAR(os_geteuid__doc__,
"geteuid($module, /)\n"
"--\n"
"\n"
"Return the current process\'s effective user id.");
#define OS_GETEUID_METHODDEF \
{"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
static PyObject *
os_geteuid_impl(PyModuleDef *module);
static PyObject *
os_geteuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_geteuid_impl(module);
}
static PyObject *
os_geteuid_impl(PyModuleDef *module)
/*[clinic end generated code: output=03d98e07f4bc03d4 input=4644c662d3bd9f19]*/
{
return _PyLong_FromUid(geteuid());
}
#endif /* HAVE_GETEUID */
#ifdef HAVE_GETGID
/*[clinic input]
os.getgid
Return the current process's group id.
[clinic start generated code]*/
PyDoc_STRVAR(os_getgid__doc__,
"getgid($module, /)\n"
"--\n"
"\n"
"Return the current process\'s group id.");
#define OS_GETGID_METHODDEF \
{"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
static PyObject *
os_getgid_impl(PyModuleDef *module);
static PyObject *
os_getgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getgid_impl(module);
}
static PyObject *
os_getgid_impl(PyModuleDef *module)
/*[clinic end generated code: output=07b0356121b8098d input=58796344cd87c0f6]*/
{
return _PyLong_FromGid(getgid());
}
#endif /* HAVE_GETGID */
/*[clinic input]
os.getpid
Return the current process id.
[clinic start generated code]*/
PyDoc_STRVAR(os_getpid__doc__,
"getpid($module, /)\n"
"--\n"
"\n"
"Return the current process id.");
#define OS_GETPID_METHODDEF \
{"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
static PyObject *
os_getpid_impl(PyModuleDef *module);
static PyObject *
os_getpid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getpid_impl(module);
}
static PyObject *
os_getpid_impl(PyModuleDef *module)
/*[clinic end generated code: output=d63a01a3cebc573d input=5a9a00f0ab68aa00]*/
{
return PyLong_FromPid(getpid());
}
#ifdef HAVE_GETGROUPLIST
/* AC 3.5: funny apple logic below */
PyDoc_STRVAR(posix_getgrouplist__doc__,
"getgrouplist(user, group) -> list of groups to which a user belongs\n\n\
Returns a list of groups to which a user belongs.\n\n\
user: username to lookup\n\
group: base group id of the user");
static PyObject *
posix_getgrouplist(PyObject *self, PyObject *args)
{
#ifdef NGROUPS_MAX
#define MAX_GROUPS NGROUPS_MAX
#else
/* defined to be 16 on Solaris7, so this should be a small number */
#define MAX_GROUPS 64
#endif
const char *user;
int i, ngroups;
PyObject *list;
#ifdef __APPLE__
int *groups, basegid;
#else
gid_t *groups, basegid;
#endif
ngroups = MAX_GROUPS;
#ifdef __APPLE__
if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid))
return NULL;
#else
if (!PyArg_ParseTuple(args, "sO&:getgrouplist", &user,
_Py_Gid_Converter, &basegid))
return NULL;
#endif
#ifdef __APPLE__
groups = PyMem_Malloc(ngroups * sizeof(int));
#else
groups = PyMem_Malloc(ngroups * sizeof(gid_t));
#endif
if (groups == NULL)
return PyErr_NoMemory();
if (getgrouplist(user, basegid, groups, &ngroups) == -1) {
PyMem_Del(groups);
return posix_error();
}
list = PyList_New(ngroups);
if (list == NULL) {
PyMem_Del(groups);
return NULL;
}
for (i = 0; i < ngroups; i++) {
#ifdef __APPLE__
PyObject *o = PyLong_FromUnsignedLong((unsigned long)groups[i]);
#else
PyObject *o = _PyLong_FromGid(groups[i]);
#endif
if (o == NULL) {
Py_DECREF(list);
PyMem_Del(groups);
return NULL;
}
PyList_SET_ITEM(list, i, o);
}
PyMem_Del(groups);
return list;
}
#endif /* HAVE_GETGROUPLIST */
#ifdef HAVE_GETGROUPS
/*[clinic input]
os.getgroups
Return list of supplemental group IDs for the process.
[clinic start generated code]*/
PyDoc_STRVAR(os_getgroups__doc__,
"getgroups($module, /)\n"
"--\n"
"\n"
"Return list of supplemental group IDs for the process.");
#define OS_GETGROUPS_METHODDEF \
{"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
static PyObject *
os_getgroups_impl(PyModuleDef *module);
static PyObject *
os_getgroups(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getgroups_impl(module);
}
static PyObject *
os_getgroups_impl(PyModuleDef *module)
/*[clinic end generated code: output=d9a3559b2e6f4ab8 input=d3f109412e6a155c]*/
{
PyObject *result = NULL;
#ifdef NGROUPS_MAX
#define MAX_GROUPS NGROUPS_MAX
#else
/* defined to be 16 on Solaris7, so this should be a small number */
#define MAX_GROUPS 64
#endif
gid_t grouplist[MAX_GROUPS];
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results
* This is a helper variable to store the intermediate result when
* that happens.
*
* To keep the code readable the OSX behaviour is unconditional,
* according to the POSIX spec this should be safe on all unix-y
* systems.
*/
gid_t* alt_grouplist = grouplist;
int n;
#ifdef __APPLE__
/* Issue #17557: As of OS X 10.8, getgroups(2) no longer raises EINVAL if
* there are more groups than can fit in grouplist. Therefore, on OS X
* always first call getgroups with length 0 to get the actual number
* of groups.
*/
n = getgroups(0, NULL);
if (n < 0) {
return posix_error();
} else if (n <= MAX_GROUPS) {
/* groups will fit in existing array */
alt_grouplist = grouplist;
} else {
alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
if (alt_grouplist == NULL) {
errno = EINVAL;
return posix_error();
}
}
n = getgroups(n, alt_grouplist);
if (n == -1) {
if (alt_grouplist != grouplist) {
PyMem_Free(alt_grouplist);
}
return posix_error();
}
#else
n = getgroups(MAX_GROUPS, grouplist);
if (n < 0) {
if (errno == EINVAL) {
n = getgroups(0, NULL);
if (n == -1) {
return posix_error();
}
if (n == 0) {
/* Avoid malloc(0) */
alt_grouplist = grouplist;
} else {
alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
if (alt_grouplist == NULL) {
errno = EINVAL;
return posix_error();
}
n = getgroups(n, alt_grouplist);
if (n == -1) {
PyMem_Free(alt_grouplist);
return posix_error();
}
}
} else {
return posix_error();
}
}
#endif
result = PyList_New(n);
if (result != NULL) {
int i;
for (i = 0; i < n; ++i) {
PyObject *o = _PyLong_FromGid(alt_grouplist[i]);
if (o == NULL) {
Py_DECREF(result);
result = NULL;
break;
}
PyList_SET_ITEM(result, i, o);
}
}
if (alt_grouplist != grouplist) {
PyMem_Free(alt_grouplist);
}
return result;
}
#endif /* HAVE_GETGROUPS */
#ifdef HAVE_INITGROUPS
PyDoc_STRVAR(posix_initgroups__doc__,
"initgroups(username, gid) -> None\n\n\
Call the system initgroups() to initialize the group access list with all of\n\
the groups of which the specified username is a member, plus the specified\n\
group id.");
/* AC 3.5: funny apple logic */
static PyObject *
posix_initgroups(PyObject *self, PyObject *args)
{
PyObject *oname;
char *username;
int res;
#ifdef __APPLE__
int gid;
#else
gid_t gid;
#endif
#ifdef __APPLE__
if (!PyArg_ParseTuple(args, "O&i:initgroups",
PyUnicode_FSConverter, &oname,
&gid))
#else
if (!PyArg_ParseTuple(args, "O&O&:initgroups",
PyUnicode_FSConverter, &oname,
_Py_Gid_Converter, &gid))
#endif
return NULL;
username = PyBytes_AS_STRING(oname);
res = initgroups(username, gid);
Py_DECREF(oname);
if (res == -1)
return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None);
return Py_None;
}
#endif /* HAVE_INITGROUPS */
#ifdef HAVE_GETPGID
/*[clinic input]
os.getpgid
pid: pid_t
Call the system call getpgid(), and return the result.
[clinic start generated code]*/
PyDoc_STRVAR(os_getpgid__doc__,
"getpgid($module, /, pid)\n"
"--\n"
"\n"
"Call the system call getpgid(), and return the result.");
#define OS_GETPGID_METHODDEF \
{"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__},
static PyObject *
os_getpgid_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_getpgid(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"pid", NULL};
pid_t pid;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"" _Py_PARSE_PID ":getpgid", _keywords,
&pid))
goto exit;
return_value = os_getpgid_impl(module, pid);
exit:
return return_value;
}
static PyObject *
os_getpgid_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=3db4ed686179160d input=39d710ae3baaf1c7]*/
{
pid_t pgid = getpgid(pid);
if (pgid < 0)
return posix_error();
return PyLong_FromPid(pgid);
}
#endif /* HAVE_GETPGID */
#ifdef HAVE_GETPGRP
/*[clinic input]
os.getpgrp
Return the current process group id.
[clinic start generated code]*/
PyDoc_STRVAR(os_getpgrp__doc__,
"getpgrp($module, /)\n"
"--\n"
"\n"
"Return the current process group id.");
#define OS_GETPGRP_METHODDEF \
{"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
static PyObject *
os_getpgrp_impl(PyModuleDef *module);
static PyObject *
os_getpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getpgrp_impl(module);
}
static PyObject *
os_getpgrp_impl(PyModuleDef *module)
/*[clinic end generated code: output=3b0d3663ea054277 input=6846fb2bb9a3705e]*/
{
#ifdef GETPGRP_HAVE_ARG
return PyLong_FromPid(getpgrp(0));
#else /* GETPGRP_HAVE_ARG */
return PyLong_FromPid(getpgrp());
#endif /* GETPGRP_HAVE_ARG */
}
#endif /* HAVE_GETPGRP */
#ifdef HAVE_SETPGRP
/*[clinic input]
os.setpgrp
Make the current process the leader of its process group.
[clinic start generated code]*/
PyDoc_STRVAR(os_setpgrp__doc__,
"setpgrp($module, /)\n"
"--\n"
"\n"
"Make the current process the leader of its process group.");
#define OS_SETPGRP_METHODDEF \
{"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
static PyObject *
os_setpgrp_impl(PyModuleDef *module);
static PyObject *
os_setpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_setpgrp_impl(module);
}
static PyObject *
os_setpgrp_impl(PyModuleDef *module)
/*[clinic end generated code: output=8fbb0ee29ef6fb2d input=1f0619fcb5731e7e]*/
{
#ifdef SETPGRP_HAVE_ARG
if (setpgrp(0, 0) < 0)
#else /* SETPGRP_HAVE_ARG */
if (setpgrp() < 0)
#endif /* SETPGRP_HAVE_ARG */
return posix_error();
Py_INCREF(Py_None);
return Py_None;
}
#endif /* HAVE_SETPGRP */
#ifdef HAVE_GETPPID
#ifdef MS_WINDOWS
#include <tlhelp32.h>
static PyObject*
win32_getppid()
{
HANDLE snapshot;
pid_t mypid;
PyObject* result = NULL;
BOOL have_record;
PROCESSENTRY32 pe;
mypid = getpid(); /* This function never fails */
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
return PyErr_SetFromWindowsErr(GetLastError());
pe.dwSize = sizeof(pe);
have_record = Process32First(snapshot, &pe);
while (have_record) {
if (mypid == (pid_t)pe.th32ProcessID) {
/* We could cache the ulong value in a static variable. */
result = PyLong_FromPid((pid_t)pe.th32ParentProcessID);
break;
}
have_record = Process32Next(snapshot, &pe);
}
/* If our loop exits and our pid was not found (result will be NULL)
* then GetLastError will return ERROR_NO_MORE_FILES. This is an
* error anyway, so let's raise it. */
if (!result)
result = PyErr_SetFromWindowsErr(GetLastError());
CloseHandle(snapshot);
return result;
}
#endif /*MS_WINDOWS*/
/*[clinic input]
os.getppid
Return the parent's process id.
If the parent process has already exited, Windows machines will still
return its id; others systems will return the id of the 'init' process (1).
[clinic start generated code]*/
PyDoc_STRVAR(os_getppid__doc__,
"getppid($module, /)\n"
"--\n"
"\n"
"Return the parent\'s process id.\n"
"\n"
"If the parent process has already exited, Windows machines will still\n"
"return its id; others systems will return the id of the \'init\' process (1).");
#define OS_GETPPID_METHODDEF \
{"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
static PyObject *
os_getppid_impl(PyModuleDef *module);
static PyObject *
os_getppid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getppid_impl(module);
}
static PyObject *
os_getppid_impl(PyModuleDef *module)
/*[clinic end generated code: output=9ff3b387781edf3a input=e637cb87539c030e]*/
{
#ifdef MS_WINDOWS
return win32_getppid();
#else
return PyLong_FromPid(getppid());
#endif
}
#endif /* HAVE_GETPPID */
#ifdef HAVE_GETLOGIN
/*[clinic input]
os.getlogin
Return the actual login name.
[clinic start generated code]*/
PyDoc_STRVAR(os_getlogin__doc__,
"getlogin($module, /)\n"
"--\n"
"\n"
"Return the actual login name.");
#define OS_GETLOGIN_METHODDEF \
{"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
static PyObject *
os_getlogin_impl(PyModuleDef *module);
static PyObject *
os_getlogin(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getlogin_impl(module);
}
static PyObject *
os_getlogin_impl(PyModuleDef *module)
/*[clinic end generated code: output=ab6211dab104cbb2 input=2a21ab1e917163df]*/
{
PyObject *result = NULL;
#ifdef MS_WINDOWS
wchar_t user_name[UNLEN + 1];
DWORD num_chars = Py_ARRAY_LENGTH(user_name);
if (GetUserNameW(user_name, &num_chars)) {
/* num_chars is the number of unicode chars plus null terminator */
result = PyUnicode_FromWideChar(user_name, num_chars - 1);
}
else
result = PyErr_SetFromWindowsErr(GetLastError());
#else
char *name;
int old_errno = errno;
errno = 0;
name = getlogin();
if (name == NULL) {
if (errno)
posix_error();
else
PyErr_SetString(PyExc_OSError, "unable to determine login name");
}
else
result = PyUnicode_DecodeFSDefault(name);
errno = old_errno;
#endif
return result;
}
#endif /* HAVE_GETLOGIN */
#ifdef HAVE_GETUID
/*[clinic input]
os.getuid
Return the current process's user id.
[clinic start generated code]*/
PyDoc_STRVAR(os_getuid__doc__,
"getuid($module, /)\n"
"--\n"
"\n"
"Return the current process\'s user id.");
#define OS_GETUID_METHODDEF \
{"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
static PyObject *
os_getuid_impl(PyModuleDef *module);
static PyObject *
os_getuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getuid_impl(module);
}
static PyObject *
os_getuid_impl(PyModuleDef *module)
/*[clinic end generated code: output=77e0dcf2e37d1e89 input=b53c8b35f110a516]*/
{
return _PyLong_FromUid(getuid());
}
#endif /* HAVE_GETUID */
#ifdef MS_WINDOWS
#define HAVE_KILL
#endif /* MS_WINDOWS */
#ifdef HAVE_KILL
/*[clinic input]
os.kill
pid: pid_t
signal: Py_ssize_t
/
Kill a process with a signal.
[clinic start generated code]*/
PyDoc_STRVAR(os_kill__doc__,
"kill($module, pid, signal, /)\n"
"--\n"
"\n"
"Kill a process with a signal.");
#define OS_KILL_METHODDEF \
{"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
static PyObject *
os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal);
static PyObject *
os_kill(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
Py_ssize_t signal;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "n:kill",
&pid, &signal))
goto exit;
return_value = os_kill_impl(module, pid, signal);
exit:
return return_value;
}
static PyObject *
os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal)
/*[clinic end generated code: output=2f5c77920ed575e6 input=61a36b86ca275ab9]*/
#ifndef MS_WINDOWS
{
if (kill(pid, (int)signal) == -1)
return posix_error();
Py_RETURN_NONE;
}
#else /* !MS_WINDOWS */
{
PyObject *result;
DWORD sig = (DWORD)signal;
DWORD err;
HANDLE handle;
/* Console processes which share a common console can be sent CTRL+C or
CTRL+BREAK events, provided they handle said events. */
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {
if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {
err = GetLastError();
PyErr_SetFromWindowsErr(err);
}
else
Py_RETURN_NONE;
}
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
attempt to open and terminate the process. */
handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (handle == NULL) {
err = GetLastError();
return PyErr_SetFromWindowsErr(err);
}
if (TerminateProcess(handle, sig) == 0) {
err = GetLastError();
result = PyErr_SetFromWindowsErr(err);
} else {
Py_INCREF(Py_None);
result = Py_None;
}
CloseHandle(handle);
return result;
}
#endif /* !MS_WINDOWS */
#endif /* HAVE_KILL */
#ifdef HAVE_KILLPG
/*[clinic input]
os.killpg
pgid: pid_t
signal: int
/
Kill a process group with a signal.
[clinic start generated code]*/
PyDoc_STRVAR(os_killpg__doc__,
"killpg($module, pgid, signal, /)\n"
"--\n"
"\n"
"Kill a process group with a signal.");
#define OS_KILLPG_METHODDEF \
{"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
static PyObject *
os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal);
static PyObject *
os_killpg(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pgid;
int signal;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "i:killpg",
&pgid, &signal))
goto exit;
return_value = os_killpg_impl(module, pgid, signal);
exit:
return return_value;
}
static PyObject *
os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal)
/*[clinic end generated code: output=0e05215d1c007e01 input=38b5449eb8faec19]*/
{
/* XXX some man pages make the `pgid` parameter an int, others
a pid_t. Since getpgrp() returns a pid_t, we assume killpg should
take the same type. Moreover, pid_t is always at least as wide as
int (else compilation of this module fails), which is safe. */
if (killpg(pgid, signal) == -1)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_KILLPG */
#ifdef HAVE_PLOCK
#ifdef HAVE_SYS_LOCK_H
#include <sys/lock.h>
#endif
/*[clinic input]
os.plock
op: int
/
Lock program segments into memory.");
[clinic start generated code]*/
PyDoc_STRVAR(os_plock__doc__,
"plock($module, op, /)\n"
"--\n"
"\n"
"Lock program segments into memory.\");");
#define OS_PLOCK_METHODDEF \
{"plock", (PyCFunction)os_plock, METH_VARARGS, os_plock__doc__},
static PyObject *
os_plock_impl(PyModuleDef *module, int op);
static PyObject *
os_plock(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int op;
if (!PyArg_ParseTuple(args,
"i:plock",
&op))
goto exit;
return_value = os_plock_impl(module, op);
exit:
return return_value;
}
static PyObject *
os_plock_impl(PyModuleDef *module, int op)
/*[clinic end generated code: output=2744fe4b6e5f4dbc input=e6e5e348e1525f60]*/
{
if (plock(op) == -1)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_PLOCK */
#ifdef HAVE_SETUID
/*[clinic input]
os.setuid
uid: uid_t
/
Set the current process's user id.
[clinic start generated code]*/
PyDoc_STRVAR(os_setuid__doc__,
"setuid($module, uid, /)\n"
"--\n"
"\n"
"Set the current process\'s user id.");
#define OS_SETUID_METHODDEF \
{"setuid", (PyCFunction)os_setuid, METH_VARARGS, os_setuid__doc__},
static PyObject *
os_setuid_impl(PyModuleDef *module, uid_t uid);
static PyObject *
os_setuid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
uid_t uid;
if (!PyArg_ParseTuple(args,
"O&:setuid",
_Py_Uid_Converter, &uid))
goto exit;
return_value = os_setuid_impl(module, uid);
exit:
return return_value;
}
static PyObject *
os_setuid_impl(PyModuleDef *module, uid_t uid)
/*[clinic end generated code: output=aea344bc22ccf400 input=c921a3285aa22256]*/
{
if (setuid(uid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETUID */
#ifdef HAVE_SETEUID
/*[clinic input]
os.seteuid
euid: uid_t
/
Set the current process's effective user id.
[clinic start generated code]*/
PyDoc_STRVAR(os_seteuid__doc__,
"seteuid($module, euid, /)\n"
"--\n"
"\n"
"Set the current process\'s effective user id.");
#define OS_SETEUID_METHODDEF \
{"seteuid", (PyCFunction)os_seteuid, METH_VARARGS, os_seteuid__doc__},
static PyObject *
os_seteuid_impl(PyModuleDef *module, uid_t euid);
static PyObject *
os_seteuid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
uid_t euid;
if (!PyArg_ParseTuple(args,
"O&:seteuid",
_Py_Uid_Converter, &euid))
goto exit;
return_value = os_seteuid_impl(module, euid);
exit:
return return_value;
}
static PyObject *
os_seteuid_impl(PyModuleDef *module, uid_t euid)
/*[clinic end generated code: output=6e824cce4f3b8a5d input=ba93d927e4781aa9]*/
{
if (seteuid(euid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETEUID */
#ifdef HAVE_SETEGID
/*[clinic input]
os.setegid
egid: gid_t
/
Set the current process's effective group id.
[clinic start generated code]*/
PyDoc_STRVAR(os_setegid__doc__,
"setegid($module, egid, /)\n"
"--\n"
"\n"
"Set the current process\'s effective group id.");
#define OS_SETEGID_METHODDEF \
{"setegid", (PyCFunction)os_setegid, METH_VARARGS, os_setegid__doc__},
static PyObject *
os_setegid_impl(PyModuleDef *module, gid_t egid);
static PyObject *
os_setegid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
gid_t egid;
if (!PyArg_ParseTuple(args,
"O&:setegid",
_Py_Gid_Converter, &egid))
goto exit;
return_value = os_setegid_impl(module, egid);
exit:
return return_value;
}
static PyObject *
os_setegid_impl(PyModuleDef *module, gid_t egid)
/*[clinic end generated code: output=80a32263a4d56a9c input=4080526d0ccd6ce3]*/
{
if (setegid(egid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETEGID */
#ifdef HAVE_SETREUID
/*[clinic input]
os.setreuid
ruid: uid_t
euid: uid_t
/
Set the current process's real and effective user ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_setreuid__doc__,
"setreuid($module, ruid, euid, /)\n"
"--\n"
"\n"
"Set the current process\'s real and effective user ids.");
#define OS_SETREUID_METHODDEF \
{"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
static PyObject *
os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid);
static PyObject *
os_setreuid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
uid_t ruid;
uid_t euid;
if (!PyArg_ParseTuple(args,
"O&O&:setreuid",
_Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid))
goto exit;
return_value = os_setreuid_impl(module, ruid, euid);
exit:
return return_value;
}
static PyObject *
os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid)
/*[clinic end generated code: output=d7f226f943dad739 input=0ca8978de663880c]*/
{
if (setreuid(ruid, euid) < 0) {
return posix_error();
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
#endif /* HAVE_SETREUID */
#ifdef HAVE_SETREGID
/*[clinic input]
os.setregid
rgid: gid_t
egid: gid_t
/
Set the current process's real and effective group ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_setregid__doc__,
"setregid($module, rgid, egid, /)\n"
"--\n"
"\n"
"Set the current process\'s real and effective group ids.");
#define OS_SETREGID_METHODDEF \
{"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
static PyObject *
os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid);
static PyObject *
os_setregid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
gid_t rgid;
gid_t egid;
if (!PyArg_ParseTuple(args,
"O&O&:setregid",
_Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid))
goto exit;
return_value = os_setregid_impl(module, rgid, egid);
exit:
return return_value;
}
static PyObject *
os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid)
/*[clinic end generated code: output=a82d9ab70f8e6562 input=c59499f72846db78]*/
{
if (setregid(rgid, egid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETREGID */
#ifdef HAVE_SETGID
/*[clinic input]
os.setgid
gid: gid_t
/
Set the current process's group id.
[clinic start generated code]*/
PyDoc_STRVAR(os_setgid__doc__,
"setgid($module, gid, /)\n"
"--\n"
"\n"
"Set the current process\'s group id.");
#define OS_SETGID_METHODDEF \
{"setgid", (PyCFunction)os_setgid, METH_VARARGS, os_setgid__doc__},
static PyObject *
os_setgid_impl(PyModuleDef *module, gid_t gid);
static PyObject *
os_setgid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
gid_t gid;
if (!PyArg_ParseTuple(args,
"O&:setgid",
_Py_Gid_Converter, &gid))
goto exit;
return_value = os_setgid_impl(module, gid);
exit:
return return_value;
}
static PyObject *
os_setgid_impl(PyModuleDef *module, gid_t gid)
/*[clinic end generated code: output=08287886db435f23 input=27d30c4059045dc6]*/
{
if (setgid(gid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETGID */
#ifdef HAVE_SETGROUPS
/*[clinic input]
os.setgroups
groups: object
/
Set the groups of the current process to list.
[clinic start generated code]*/
PyDoc_STRVAR(os_setgroups__doc__,
"setgroups($module, groups, /)\n"
"--\n"
"\n"
"Set the groups of the current process to list.");
#define OS_SETGROUPS_METHODDEF \
{"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
static PyObject *
os_setgroups(PyModuleDef *module, PyObject *groups)
/*[clinic end generated code: output=0b8de65d5b3cda94 input=fa742ca3daf85a7e]*/
{
int i, len;
gid_t grouplist[MAX_GROUPS];
if (!PySequence_Check(groups)) {
PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence");
return NULL;
}
len = PySequence_Size(groups);
if (len > MAX_GROUPS) {
PyErr_SetString(PyExc_ValueError, "too many groups");
return NULL;
}
for(i = 0; i < len; i++) {
PyObject *elem;
elem = PySequence_GetItem(groups, i);
if (!elem)
return NULL;
if (!PyLong_Check(elem)) {
PyErr_SetString(PyExc_TypeError,
"groups must be integers");
Py_DECREF(elem);
return NULL;
} else {
if (!_Py_Gid_Converter(elem, &grouplist[i])) {
Py_DECREF(elem);
return NULL;
}
}
Py_DECREF(elem);
}
if (setgroups(len, grouplist) < 0)
return posix_error();
Py_INCREF(Py_None);
return Py_None;
}
#endif /* HAVE_SETGROUPS */
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
static PyObject *
wait_helper(pid_t pid, int status, struct rusage *ru)
{
PyObject *result;
static PyObject *struct_rusage;
_Py_IDENTIFIER(struct_rusage);
if (pid == -1)
return posix_error();
if (struct_rusage == NULL) {
PyObject *m = PyImport_ImportModuleNoBlock("resource");
if (m == NULL)
return NULL;
struct_rusage = _PyObject_GetAttrId(m, &PyId_struct_rusage);
Py_DECREF(m);
if (struct_rusage == NULL)
return NULL;
}
/* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */
result = PyStructSequence_New((PyTypeObject*) struct_rusage);
if (!result)
return NULL;
#ifndef doubletime
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
#endif
PyStructSequence_SET_ITEM(result, 0,
PyFloat_FromDouble(doubletime(ru->ru_utime)));
PyStructSequence_SET_ITEM(result, 1,
PyFloat_FromDouble(doubletime(ru->ru_stime)));
#define SET_INT(result, index, value)\
PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
SET_INT(result, 2, ru->ru_maxrss);
SET_INT(result, 3, ru->ru_ixrss);
SET_INT(result, 4, ru->ru_idrss);
SET_INT(result, 5, ru->ru_isrss);
SET_INT(result, 6, ru->ru_minflt);
SET_INT(result, 7, ru->ru_majflt);
SET_INT(result, 8, ru->ru_nswap);
SET_INT(result, 9, ru->ru_inblock);
SET_INT(result, 10, ru->ru_oublock);
SET_INT(result, 11, ru->ru_msgsnd);
SET_INT(result, 12, ru->ru_msgrcv);
SET_INT(result, 13, ru->ru_nsignals);
SET_INT(result, 14, ru->ru_nvcsw);
SET_INT(result, 15, ru->ru_nivcsw);
#undef SET_INT
if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);
}
#endif /* HAVE_WAIT3 || HAVE_WAIT4 */
#ifdef HAVE_WAIT3
/*[clinic input]
os.wait3
options: int
Wait for completion of a child process.
Returns a tuple of information about the child process:
(pid, status, rusage)
[clinic start generated code]*/
PyDoc_STRVAR(os_wait3__doc__,
"wait3($module, /, options)\n"
"--\n"
"\n"
"Wait for completion of a child process.\n"
"\n"
"Returns a tuple of information about the child process:\n"
" (pid, status, rusage)");
#define OS_WAIT3_METHODDEF \
{"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__},
static PyObject *
os_wait3_impl(PyModuleDef *module, int options);
static PyObject *
os_wait3(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"options", NULL};
int options;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:wait3", _keywords,
&options))
goto exit;
return_value = os_wait3_impl(module, options);
exit:
return return_value;
}
static PyObject *
os_wait3_impl(PyModuleDef *module, int options)
/*[clinic end generated code: output=1f2a63b6a93cbb57 input=8ac4c56956b61710]*/
{
pid_t pid;
struct rusage ru;
WAIT_TYPE status;
WAIT_STATUS_INT(status) = 0;
Py_BEGIN_ALLOW_THREADS
pid = wait3(&status, options, &ru);
Py_END_ALLOW_THREADS
return wait_helper(pid, WAIT_STATUS_INT(status), &ru);
}
#endif /* HAVE_WAIT3 */
#ifdef HAVE_WAIT4
/*[clinic input]
os.wait4
pid: pid_t
options: int
Wait for completion of a specific child process.
Returns a tuple of information about the child process:
(pid, status, rusage)
[clinic start generated code]*/
PyDoc_STRVAR(os_wait4__doc__,
"wait4($module, /, pid, options)\n"
"--\n"
"\n"
"Wait for completion of a specific child process.\n"
"\n"
"Returns a tuple of information about the child process:\n"
" (pid, status, rusage)");
#define OS_WAIT4_METHODDEF \
{"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__},
static PyObject *
os_wait4_impl(PyModuleDef *module, pid_t pid, int options);
static PyObject *
os_wait4(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"pid", "options", NULL};
pid_t pid;
int options;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"" _Py_PARSE_PID "i:wait4", _keywords,
&pid, &options))
goto exit;
return_value = os_wait4_impl(module, pid, options);
exit:
return return_value;
}
static PyObject *
os_wait4_impl(PyModuleDef *module, pid_t pid, int options)
/*[clinic end generated code: output=20dfb05289d37dc6 input=d11deed0750600ba]*/
{
struct rusage ru;
WAIT_TYPE status;
WAIT_STATUS_INT(status) = 0;
Py_BEGIN_ALLOW_THREADS
pid = wait4(pid, &status, options, &ru);
Py_END_ALLOW_THREADS
return wait_helper(pid, WAIT_STATUS_INT(status), &ru);
}
#endif /* HAVE_WAIT4 */
#if defined(HAVE_WAITID) && !defined(__APPLE__)
/*[clinic input]
os.waitid
idtype: idtype_t
Must be one of be P_PID, P_PGID or P_ALL.
id: id_t
The id to wait on.
options: int
Constructed from the ORing of one or more of WEXITED, WSTOPPED
or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.
/
Returns the result of waiting for a process or processes.
Returns either waitid_result or None if WNOHANG is specified and there are
no children in a waitable state.
[clinic start generated code]*/
PyDoc_STRVAR(os_waitid__doc__,
"waitid($module, idtype, id, options, /)\n"
"--\n"
"\n"
"Returns the result of waiting for a process or processes.\n"
"\n"
" idtype\n"
" Must be one of be P_PID, P_PGID or P_ALL.\n"
" id\n"
" The id to wait on.\n"
" options\n"
" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
"\n"
"Returns either waitid_result or None if WNOHANG is specified and there are\n"
"no children in a waitable state.");
#define OS_WAITID_METHODDEF \
{"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
static PyObject *
os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options);
static PyObject *
os_waitid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
idtype_t idtype;
id_t id;
int options;
if (!PyArg_ParseTuple(args,
"i" _Py_PARSE_PID "i:waitid",
&idtype, &id, &options))
goto exit;
return_value = os_waitid_impl(module, idtype, id, options);
exit:
return return_value;
}
static PyObject *
os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options)
/*[clinic end generated code: output=fb44bf97f01021b2 input=d8e7f76e052b7920]*/
{
PyObject *result;
int res;
siginfo_t si;
si.si_pid = 0;
Py_BEGIN_ALLOW_THREADS
res = waitid(idtype, id, &si, options);
Py_END_ALLOW_THREADS
if (res == -1)
return posix_error();
if (si.si_pid == 0)
Py_RETURN_NONE;
result = PyStructSequence_New(&WaitidResultType);
if (!result)
return NULL;
PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid));
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
return result;
}
#endif /* defined(HAVE_WAITID) && !defined(__APPLE__) */
#if defined(HAVE_WAITPID)
/*[clinic input]
os.waitpid
pid: pid_t
options: int
/
Wait for completion of a given child process.
Returns a tuple of information regarding the child process:
(pid, status)
The options argument is ignored on Windows.
[clinic start generated code]*/
PyDoc_STRVAR(os_waitpid__doc__,
"waitpid($module, pid, options, /)\n"
"--\n"
"\n"
"Wait for completion of a given child process.\n"
"\n"
"Returns a tuple of information regarding the child process:\n"
" (pid, status)\n"
"\n"
"The options argument is ignored on Windows.");
#define OS_WAITPID_METHODDEF \
{"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
static PyObject *
os_waitpid_impl(PyModuleDef *module, pid_t pid, int options);
static PyObject *
os_waitpid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
int options;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "i:waitpid",
&pid, &options))
goto exit;
return_value = os_waitpid_impl(module, pid, options);
exit:
return return_value;
}
static PyObject *
os_waitpid_impl(PyModuleDef *module, pid_t pid, int options)
/*[clinic end generated code: output=095a6b00af70b7ac input=0bf1666b8758fda3]*/
{
WAIT_TYPE status;
WAIT_STATUS_INT(status) = 0;
Py_BEGIN_ALLOW_THREADS
pid = waitpid(pid, &status, options);
Py_END_ALLOW_THREADS
if (pid == -1)
return posix_error();
return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));
}
#elif defined(HAVE_CWAIT)
/* MS C has a variant of waitpid() that's usable for most purposes. */
/*[clinic input]
os.waitpid
pid: Py_intptr_t
options: int
/
Wait for completion of a given process.
Returns a tuple of information regarding the process:
(pid, status << 8)
The options argument is ignored on Windows.
[clinic start generated code]*/
PyDoc_STRVAR(os_waitpid__doc__,
"waitpid($module, pid, options, /)\n"
"--\n"
"\n"
"Wait for completion of a given process.\n"
"\n"
"Returns a tuple of information regarding the process:\n"
" (pid, status << 8)\n"
"\n"
"The options argument is ignored on Windows.");
#define OS_WAITPID_METHODDEF \
{"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
static PyObject *
os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options);
static PyObject *
os_waitpid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
Py_intptr_t pid;
int options;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_INTPTR "i:waitpid",
&pid, &options))
goto exit;
return_value = os_waitpid_impl(module, pid, options);
exit:
return return_value;
}
static PyObject *
os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options)
/*[clinic end generated code: output=c20b95b15ad44a3a input=444c8f51cca5b862]*/
{
int status;
Py_BEGIN_ALLOW_THREADS
pid = _cwait(&status, pid, options);
Py_END_ALLOW_THREADS
if (pid == -1)
return posix_error();
/* shift the status left a byte so this is more like the POSIX waitpid */
return Py_BuildValue(_Py_PARSE_INTPTR "i", pid, status << 8);
}
#endif
#ifdef HAVE_WAIT
/*[clinic input]
os.wait
Wait for completion of a child process.
Returns a tuple of information about the child process:
(pid, status)
[clinic start generated code]*/
PyDoc_STRVAR(os_wait__doc__,
"wait($module, /)\n"
"--\n"
"\n"
"Wait for completion of a child process.\n"
"\n"
"Returns a tuple of information about the child process:\n"
" (pid, status)");
#define OS_WAIT_METHODDEF \
{"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
static PyObject *
os_wait_impl(PyModuleDef *module);
static PyObject *
os_wait(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_wait_impl(module);
}
static PyObject *
os_wait_impl(PyModuleDef *module)
/*[clinic end generated code: output=2a83a9d164e7e6a8 input=03b0182d4a4700ce]*/
{
pid_t pid;
WAIT_TYPE status;
WAIT_STATUS_INT(status) = 0;
Py_BEGIN_ALLOW_THREADS
pid = wait(&status);
Py_END_ALLOW_THREADS
if (pid == -1)
return posix_error();
return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));
}
#endif /* HAVE_WAIT */
#if defined(HAVE_READLINK) || defined(MS_WINDOWS)
PyDoc_STRVAR(readlink__doc__,
"readlink(path, *, dir_fd=None) -> path\n\n\
Return a string representing the path to which the symbolic link points.\n\
\n\
If dir_fd is not None, it should be a file descriptor open to a directory,\n\
and path should be relative; path will then be relative to that directory.\n\
dir_fd may not be implemented on your platform.\n\
If it is unavailable, using it will raise a NotImplementedError.");
#endif
#ifdef HAVE_READLINK
/* AC 3.5: merge win32 and not together */
static PyObject *
posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
{
path_t path;
int dir_fd = DEFAULT_DIR_FD;
char buffer[MAXPATHLEN];
ssize_t length;
PyObject *return_value = NULL;
static char *keywords[] = {"path", "dir_fd", NULL};
memset(&path, 0, sizeof(path));
path.function_name = "readlink";
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:readlink", keywords,
path_converter, &path,
READLINKAT_DIR_FD_CONVERTER, &dir_fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_READLINKAT
if (dir_fd != DEFAULT_DIR_FD)
length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer));
else
#endif
length = readlink(path.narrow, buffer, sizeof(buffer));
Py_END_ALLOW_THREADS
if (length < 0) {
return_value = path_error(&path);
goto exit;
}
if (PyUnicode_Check(path.object))
return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);
else
return_value = PyBytes_FromStringAndSize(buffer, length);
exit:
path_cleanup(&path);
return return_value;
}
#endif /* HAVE_READLINK */
#if !defined(HAVE_READLINK) && defined(MS_WINDOWS)
static PyObject *
win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
{
wchar_t *path;
DWORD n_bytes_returned;
DWORD io_result;
PyObject *po, *result;
int dir_fd;
HANDLE reparse_point_handle;
char target_buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER *)target_buffer;
wchar_t *print_name;
static char *keywords[] = {"path", "dir_fd", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U|$O&:readlink", keywords,
&po,
dir_fd_unavailable, &dir_fd
))
return NULL;
path = PyUnicode_AsUnicode(po);
if (path == NULL)
return NULL;
/* First get a handle to the reparse point */
Py_BEGIN_ALLOW_THREADS
reparse_point_handle = CreateFileW(
path,
0,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS,
0);
Py_END_ALLOW_THREADS
if (reparse_point_handle==INVALID_HANDLE_VALUE)
return win32_error_object("readlink", po);
Py_BEGIN_ALLOW_THREADS
/* New call DeviceIoControl to read the reparse point */
io_result = DeviceIoControl(
reparse_point_handle,
FSCTL_GET_REPARSE_POINT,
0, 0, /* in buffer */
target_buffer, sizeof(target_buffer),
&n_bytes_returned,
0 /* we're not using OVERLAPPED_IO */
);
CloseHandle(reparse_point_handle);
Py_END_ALLOW_THREADS
if (io_result==0)
return win32_error_object("readlink", po);
if (rdb->ReparseTag != IO_REPARSE_TAG_SYMLINK)
{
PyErr_SetString(PyExc_ValueError,
"not a symbolic link");
return NULL;
}
print_name = rdb->SymbolicLinkReparseBuffer.PathBuffer +
rdb->SymbolicLinkReparseBuffer.PrintNameOffset;
result = PyUnicode_FromWideChar(print_name,
rdb->SymbolicLinkReparseBuffer.PrintNameLength/2);
return result;
}
#endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
#ifdef HAVE_SYMLINK
#if defined(MS_WINDOWS)
/* Grab CreateSymbolicLinkW dynamically from kernel32 */
static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD) = NULL;
static DWORD (CALLBACK *Py_CreateSymbolicLinkA)(LPSTR, LPSTR, DWORD) = NULL;
static int
check_CreateSymbolicLink(void)
{
HINSTANCE hKernel32;
/* only recheck */
if (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA)
return 1;
hKernel32 = GetModuleHandleW(L"KERNEL32");
*(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32,
"CreateSymbolicLinkW");
*(FARPROC*)&Py_CreateSymbolicLinkA = GetProcAddress(hKernel32,
"CreateSymbolicLinkA");
return (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA);
}
/* Remove the last portion of the path */
static void
_dirnameW(WCHAR *path)
{
WCHAR *ptr;
/* walk the path from the end until a backslash is encountered */
for(ptr = path + wcslen(path); ptr != path; ptr--) {
if (*ptr == L'\\' || *ptr == L'/')
break;
}
*ptr = 0;
}
/* Remove the last portion of the path */
static void
_dirnameA(char *path)
{
char *ptr;
/* walk the path from the end until a backslash is encountered */
for(ptr = path + strlen(path); ptr != path; ptr--) {
if (*ptr == '\\' || *ptr == '/')
break;
}
*ptr = 0;
}
/* Is this path absolute? */
static int
_is_absW(const WCHAR *path)
{
return path[0] == L'\\' || path[0] == L'/' || path[1] == L':';
}
/* Is this path absolute? */
static int
_is_absA(const char *path)
{
return path[0] == '\\' || path[0] == '/' || path[1] == ':';
}
/* join root and rest with a backslash */
static void
_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest)
{
size_t root_len;
if (_is_absW(rest)) {
wcscpy(dest_path, rest);
return;
}
root_len = wcslen(root);
wcscpy(dest_path, root);
if(root_len) {
dest_path[root_len] = L'\\';
root_len++;
}
wcscpy(dest_path+root_len, rest);
}
/* join root and rest with a backslash */
static void
_joinA(char *dest_path, const char *root, const char *rest)
{
size_t root_len;
if (_is_absA(rest)) {
strcpy(dest_path, rest);
return;
}
root_len = strlen(root);
strcpy(dest_path, root);
if(root_len) {
dest_path[root_len] = '\\';
root_len++;
}
strcpy(dest_path+root_len, rest);
}
/* Return True if the path at src relative to dest is a directory */
static int
_check_dirW(WCHAR *src, WCHAR *dest)
{
WIN32_FILE_ATTRIBUTE_DATA src_info;
WCHAR dest_parent[MAX_PATH];
WCHAR src_resolved[MAX_PATH] = L"";
/* dest_parent = os.path.dirname(dest) */
wcscpy(dest_parent, dest);
_dirnameW(dest_parent);
/* src_resolved = os.path.join(dest_parent, src) */
_joinW(src_resolved, dest_parent, src);
return (
GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info)
&& src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
);
}
/* Return True if the path at src relative to dest is a directory */
static int
_check_dirA(char *src, char *dest)
{
WIN32_FILE_ATTRIBUTE_DATA src_info;
char dest_parent[MAX_PATH];
char src_resolved[MAX_PATH] = "";
/* dest_parent = os.path.dirname(dest) */
strcpy(dest_parent, dest);
_dirnameA(dest_parent);
/* src_resolved = os.path.join(dest_parent, src) */
_joinA(src_resolved, dest_parent, src);
return (
GetFileAttributesExA(src_resolved, GetFileExInfoStandard, &src_info)
&& src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
);
}
#endif
/*[clinic input]
os.symlink
src: path_t
dst: path_t
target_is_directory: bool = False
*
dir_fd: dir_fd(requires='symlinkat')=None
# "symlink(src, dst, target_is_directory=False, *, dir_fd=None)\n\n\
Create a symbolic link pointing to src named dst.
target_is_directory is required on Windows if the target is to be
interpreted as a directory. (On Windows, symlink requires
Windows 6.0 or greater, and raises a NotImplementedError otherwise.)
target_is_directory is ignored on non-Windows platforms.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_symlink__doc__,
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
"--\n"
"\n"
"Create a symbolic link pointing to src named dst.\n"
"\n"
"target_is_directory is required on Windows if the target is to be\n"
" interpreted as a directory. (On Windows, symlink requires\n"
" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
" target_is_directory is ignored on non-Windows platforms.\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_SYMLINK_METHODDEF \
{"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__},
static PyObject *
os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst, int target_is_directory, int dir_fd);
static PyObject *
os_symlink(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
int target_is_directory = 0;
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|p$O&:symlink", _keywords,
path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
exit:
/* Cleanup for src */
path_cleanup(&src);
/* Cleanup for dst */
path_cleanup(&dst);
return return_value;
}
static PyObject *
os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst, int target_is_directory, int dir_fd)
/*[clinic end generated code: output=1a31e6d88aafe9b6 input=e820ec4472547bc3]*/
{
#ifdef MS_WINDOWS
DWORD result;
#else
int result;
#endif
#ifdef MS_WINDOWS
if (!check_CreateSymbolicLink()) {
PyErr_SetString(PyExc_NotImplementedError,
"CreateSymbolicLink functions not found");
return NULL;
}
if (!win32_can_symlink) {
PyErr_SetString(PyExc_OSError, "symbolic link privilege not held");
return NULL;
}
#endif
if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
PyErr_SetString(PyExc_ValueError,
"symlink: src and dst must be the same type");
return NULL;
}
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
if (dst->wide) {
/* if src is a directory, ensure target_is_directory==1 */
target_is_directory |= _check_dirW(src->wide, dst->wide);
result = Py_CreateSymbolicLinkW(dst->wide, src->wide,
target_is_directory);
}
else {
/* if src is a directory, ensure target_is_directory==1 */
target_is_directory |= _check_dirA(src->narrow, dst->narrow);
result = Py_CreateSymbolicLinkA(dst->narrow, src->narrow,
target_is_directory);
}
Py_END_ALLOW_THREADS
if (!result)
return path_error2(src, dst);
#else
Py_BEGIN_ALLOW_THREADS
#if HAVE_SYMLINKAT
if (dir_fd != DEFAULT_DIR_FD)
result = symlinkat(src->narrow, dir_fd, dst->narrow);
else
#endif
result = symlink(src->narrow, dst->narrow);
Py_END_ALLOW_THREADS
if (result)
return path_error2(src, dst);
#endif
Py_RETURN_NONE;
}
#endif /* HAVE_SYMLINK */
static PyStructSequence_Field times_result_fields[] = {
{"user", "user time"},
{"system", "system time"},
{"children_user", "user time of children"},
{"children_system", "system time of children"},
{"elapsed", "elapsed time since an arbitrary point in the past"},
{NULL}
};
PyDoc_STRVAR(times_result__doc__,
"times_result: Result from os.times().\n\n\
This object may be accessed either as a tuple of\n\
(user, system, children_user, children_system, elapsed),\n\
or via the attributes user, system, children_user, children_system,\n\
and elapsed.\n\
\n\
See os.times for more information.");
static PyStructSequence_Desc times_result_desc = {
"times_result", /* name */
times_result__doc__, /* doc */
times_result_fields,
5
};
static PyTypeObject TimesResultType;
#ifdef MS_WINDOWS
#define HAVE_TIMES /* mandatory, for the method table */
#endif
#ifdef HAVE_TIMES
static PyObject *
build_times_result(double user, double system,
double children_user, double children_system,
double elapsed)
{
PyObject *value = PyStructSequence_New(&TimesResultType);
if (value == NULL)
return NULL;
#define SET(i, field) \
{ \
PyObject *o = PyFloat_FromDouble(field); \
if (!o) { \
Py_DECREF(value); \
return NULL; \
} \
PyStructSequence_SET_ITEM(value, i, o); \
} \
SET(0, user);
SET(1, system);
SET(2, children_user);
SET(3, children_system);
SET(4, elapsed);
#undef SET
return value;
}
#ifndef MS_WINDOWS
#define NEED_TICKS_PER_SECOND
static long ticks_per_second = -1;
#endif /* MS_WINDOWS */
/*[clinic input]
os.times
Return a collection containing process timing information.
The object returned behaves like a named tuple with these fields:
(utime, stime, cutime, cstime, elapsed_time)
All fields are floating point numbers.
[clinic start generated code]*/
PyDoc_STRVAR(os_times__doc__,
"times($module, /)\n"
"--\n"
"\n"
"Return a collection containing process timing information.\n"
"\n"
"The object returned behaves like a named tuple with these fields:\n"
" (utime, stime, cutime, cstime, elapsed_time)\n"
"All fields are floating point numbers.");
#define OS_TIMES_METHODDEF \
{"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
static PyObject *
os_times_impl(PyModuleDef *module);
static PyObject *
os_times(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_times_impl(module);
}
static PyObject *
os_times_impl(PyModuleDef *module)
/*[clinic end generated code: output=b86896d031a9b768 input=2bf9df3d6ab2e48b]*/
#ifdef MS_WINDOWS
{
FILETIME create, exit, kernel, user;
HANDLE hProc;
hProc = GetCurrentProcess();
GetProcessTimes(hProc, &create, &exit, &kernel, &user);
/* The fields of a FILETIME structure are the hi and lo part
of a 64-bit value expressed in 100 nanosecond units.
1e7 is one second in such units; 1e-7 the inverse.
429.4967296 is 2**32 / 1e7 or 2**32 * 1e-7.
*/
return build_times_result(
(double)(user.dwHighDateTime*429.4967296 +
user.dwLowDateTime*1e-7),
(double)(kernel.dwHighDateTime*429.4967296 +
kernel.dwLowDateTime*1e-7),
(double)0,
(double)0,
(double)0);
}
#else /* MS_WINDOWS */
{
struct tms t;
clock_t c;
errno = 0;
c = times(&t);
if (c == (clock_t) -1)
return posix_error();
return build_times_result(
(double)t.tms_utime / ticks_per_second,
(double)t.tms_stime / ticks_per_second,
(double)t.tms_cutime / ticks_per_second,
(double)t.tms_cstime / ticks_per_second,
(double)c / ticks_per_second);
}
#endif /* MS_WINDOWS */
#endif /* HAVE_TIMES */
#ifdef HAVE_GETSID
/*[clinic input]
os.getsid
pid: pid_t
/
Call the system call getsid(pid) and return the result.
[clinic start generated code]*/
PyDoc_STRVAR(os_getsid__doc__,
"getsid($module, pid, /)\n"
"--\n"
"\n"
"Call the system call getsid(pid) and return the result.");
#define OS_GETSID_METHODDEF \
{"getsid", (PyCFunction)os_getsid, METH_VARARGS, os_getsid__doc__},
static PyObject *
os_getsid_impl(PyModuleDef *module, pid_t pid);
static PyObject *
os_getsid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID ":getsid",
&pid))
goto exit;
return_value = os_getsid_impl(module, pid);
exit:
return return_value;
}
static PyObject *
os_getsid_impl(PyModuleDef *module, pid_t pid)
/*[clinic end generated code: output=ea8390f395f4e0e1 input=eeb2b923a30ce04e]*/
{
int sid;
sid = getsid(pid);
if (sid < 0)
return posix_error();
return PyLong_FromLong((long)sid);
}
#endif /* HAVE_GETSID */
#ifdef HAVE_SETSID
/*[clinic input]
os.setsid
Call the system call setsid().
[clinic start generated code]*/
PyDoc_STRVAR(os_setsid__doc__,
"setsid($module, /)\n"
"--\n"
"\n"
"Call the system call setsid().");
#define OS_SETSID_METHODDEF \
{"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
static PyObject *
os_setsid_impl(PyModuleDef *module);
static PyObject *
os_setsid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_setsid_impl(module);
}
static PyObject *
os_setsid_impl(PyModuleDef *module)
/*[clinic end generated code: output=2a9a1435d8d764d5 input=5fff45858e2f0776]*/
{
if (setsid() < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETSID */
#ifdef HAVE_SETPGID
/*[clinic input]
os.setpgid
pid: pid_t
pgrp: pid_t
/
Call the system call setpgid(pid, pgrp).
[clinic start generated code]*/
PyDoc_STRVAR(os_setpgid__doc__,
"setpgid($module, pid, pgrp, /)\n"
"--\n"
"\n"
"Call the system call setpgid(pid, pgrp).");
#define OS_SETPGID_METHODDEF \
{"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
static PyObject *
os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp);
static PyObject *
os_setpgid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
pid_t pid;
pid_t pgrp;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
&pid, &pgrp))
goto exit;
return_value = os_setpgid_impl(module, pid, pgrp);
exit:
return return_value;
}
static PyObject *
os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp)
/*[clinic end generated code: output=7ad79b725f890e1f input=fceb395eca572e1a]*/
{
if (setpgid(pid, pgrp) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETPGID */
#ifdef HAVE_TCGETPGRP
/*[clinic input]
os.tcgetpgrp
fd: int
/
Return the process group associated with the terminal specified by fd.
[clinic start generated code]*/
PyDoc_STRVAR(os_tcgetpgrp__doc__,
"tcgetpgrp($module, fd, /)\n"
"--\n"
"\n"
"Return the process group associated with the terminal specified by fd.");
#define OS_TCGETPGRP_METHODDEF \
{"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_VARARGS, os_tcgetpgrp__doc__},
static PyObject *
os_tcgetpgrp_impl(PyModuleDef *module, int fd);
static PyObject *
os_tcgetpgrp(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
if (!PyArg_ParseTuple(args,
"i:tcgetpgrp",
&fd))
goto exit;
return_value = os_tcgetpgrp_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_tcgetpgrp_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=abcf52ed4c8d22cb input=7f6c18eac10ada86]*/
{
pid_t pgid = tcgetpgrp(fd);
if (pgid < 0)
return posix_error();
return PyLong_FromPid(pgid);
}
#endif /* HAVE_TCGETPGRP */
#ifdef HAVE_TCSETPGRP
/*[clinic input]
os.tcsetpgrp
fd: int
pgid: pid_t
/
Set the process group associated with the terminal specified by fd.
[clinic start generated code]*/
PyDoc_STRVAR(os_tcsetpgrp__doc__,
"tcsetpgrp($module, fd, pgid, /)\n"
"--\n"
"\n"
"Set the process group associated with the terminal specified by fd.");
#define OS_TCSETPGRP_METHODDEF \
{"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
static PyObject *
os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid);
static PyObject *
os_tcsetpgrp(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
pid_t pgid;
if (!PyArg_ParseTuple(args,
"i" _Py_PARSE_PID ":tcsetpgrp",
&fd, &pgid))
goto exit;
return_value = os_tcsetpgrp_impl(module, fd, pgid);
exit:
return return_value;
}
static PyObject *
os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid)
/*[clinic end generated code: output=76f9bb8fd00f20f5 input=5bdc997c6a619020]*/
{
if (tcsetpgrp(fd, pgid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_TCSETPGRP */
/* Functions acting on file descriptors */
#ifdef O_CLOEXEC
extern int _Py_open_cloexec_works;
#endif
/*[clinic input]
os.open -> int
path: path_t
flags: int
mode: int = 0o777
*
dir_fd: dir_fd(requires='openat') = None
# "open(path, flags, mode=0o777, *, dir_fd=None)\n\n\
Open a file for low level IO. Returns a file descriptor (integer).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_open__doc__,
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
"--\n"
"\n"
"Open a file for low level IO. Returns a file descriptor (integer).\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_OPEN_METHODDEF \
{"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__},
static int
os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd);
static PyObject *
os_open(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
int flags;
int mode = 511;
int dir_fd = DEFAULT_DIR_FD;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&i|i$O&:open", _keywords,
path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
_return_value = os_open_impl(module, &path, flags, mode, dir_fd);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static int
os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd)
/*[clinic end generated code: output=05b68fc4ed5e29c9 input=ad8623b29acd2934]*/
{
int fd;
#ifdef O_CLOEXEC
int *atomic_flag_works = &_Py_open_cloexec_works;
#elif !defined(MS_WINDOWS)
int *atomic_flag_works = NULL;
#endif
#ifdef MS_WINDOWS
flags |= O_NOINHERIT;
#elif defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if (path->wide)
fd = _wopen(path->wide, flags, mode);
else
#endif
#ifdef HAVE_OPENAT
if (dir_fd != DEFAULT_DIR_FD)
fd = openat(dir_fd, path->narrow, flags, mode);
else
#endif
fd = open(path->narrow, flags, mode);
Py_END_ALLOW_THREADS
if (fd == -1) {
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
return -1;
}
#ifndef MS_WINDOWS
if (_Py_set_inheritable(fd, 0, atomic_flag_works) < 0) {
close(fd);
return -1;
}
#endif
return fd;
}
/*[clinic input]
os.close
fd: int
Close a file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_close__doc__,
"close($module, /, fd)\n"
"--\n"
"\n"
"Close a file descriptor.");
#define OS_CLOSE_METHODDEF \
{"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__},
static PyObject *
os_close_impl(PyModuleDef *module, int fd);
static PyObject *
os_close(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:close", _keywords,
&fd))
goto exit;
return_value = os_close_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_close_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=927004e29ad55808 input=2bc42451ca5c3223]*/
{
int res;
if (!_PyVerify_fd(fd))
return posix_error();
Py_BEGIN_ALLOW_THREADS
res = close(fd);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
Py_RETURN_NONE;
}
/*[clinic input]
os.closerange
fd_low: int
fd_high: int
/
Closes all file descriptors in [fd_low, fd_high), ignoring errors.
[clinic start generated code]*/
PyDoc_STRVAR(os_closerange__doc__,
"closerange($module, fd_low, fd_high, /)\n"
"--\n"
"\n"
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
#define OS_CLOSERANGE_METHODDEF \
{"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
static PyObject *
os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high);
static PyObject *
os_closerange(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd_low;
int fd_high;
if (!PyArg_ParseTuple(args,
"ii:closerange",
&fd_low, &fd_high))
goto exit;
return_value = os_closerange_impl(module, fd_low, fd_high);
exit:
return return_value;
}
static PyObject *
os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high)
/*[clinic end generated code: output=0a929ece386811c3 input=5855a3d053ebd4ec]*/
{
int i;
Py_BEGIN_ALLOW_THREADS
for (i = fd_low; i < fd_high; i++)
if (_PyVerify_fd(i))
close(i);
Py_END_ALLOW_THREADS
Py_RETURN_NONE;
}
/*[clinic input]
os.dup -> int
fd: int
/
Return a duplicate of a file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_dup__doc__,
"dup($module, fd, /)\n"
"--\n"
"\n"
"Return a duplicate of a file descriptor.");
#define OS_DUP_METHODDEF \
{"dup", (PyCFunction)os_dup, METH_VARARGS, os_dup__doc__},
static int
os_dup_impl(PyModuleDef *module, int fd);
static PyObject *
os_dup(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int _return_value;
if (!PyArg_ParseTuple(args,
"i:dup",
&fd))
goto exit;
_return_value = os_dup_impl(module, fd);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_dup_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=75943e057b25e1bd input=6f10f7ea97f7852a]*/
{
return _Py_dup(fd);
}
/*[clinic input]
os.dup2
fd: int
fd2: int
inheritable: bool=True
Duplicate file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_dup2__doc__,
"dup2($module, /, fd, fd2, inheritable=True)\n"
"--\n"
"\n"
"Duplicate file descriptor.");
#define OS_DUP2_METHODDEF \
{"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__},
static PyObject *
os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable);
static PyObject *
os_dup2(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", "fd2", "inheritable", NULL};
int fd;
int fd2;
int inheritable = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"ii|p:dup2", _keywords,
&fd, &fd2, &inheritable))
goto exit;
return_value = os_dup2_impl(module, fd, fd2, inheritable);
exit:
return return_value;
}
static PyObject *
os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable)
/*[clinic end generated code: output=531e482dd11a99a0 input=76e96f511be0352f]*/
{
int res;
#if defined(HAVE_DUP3) && \
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
int dup3_works = -1;
#endif
if (!_PyVerify_fd_dup2(fd, fd2))
return posix_error();
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
res = dup2(fd, fd2);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
/* Character files like console cannot be make non-inheritable */
if (!inheritable && _Py_set_inheritable(fd2, 0, NULL) < 0) {
close(fd2);
return NULL;
}
#elif defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)
Py_BEGIN_ALLOW_THREADS
if (!inheritable)
res = fcntl(fd, F_DUP2FD_CLOEXEC, fd2);
else
res = dup2(fd, fd2);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
#else
#ifdef HAVE_DUP3
if (!inheritable && dup3_works != 0) {
Py_BEGIN_ALLOW_THREADS
res = dup3(fd, fd2, O_CLOEXEC);
Py_END_ALLOW_THREADS
if (res < 0) {
if (dup3_works == -1)
dup3_works = (errno != ENOSYS);
if (dup3_works)
return posix_error();
}
}
if (inheritable || dup3_works == 0)
{
#endif
Py_BEGIN_ALLOW_THREADS
res = dup2(fd, fd2);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
if (!inheritable && _Py_set_inheritable(fd2, 0, NULL) < 0) {
close(fd2);
return NULL;
}
#ifdef HAVE_DUP3
}
#endif
#endif
Py_RETURN_NONE;
}
#ifdef HAVE_LOCKF
/*[clinic input]
os.lockf
fd: int
An open file descriptor.
command: int
One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.
length: Py_off_t
The number of bytes to lock, starting at the current position.
/
Apply, test or remove a POSIX lock on an open file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_lockf__doc__,
"lockf($module, fd, command, length, /)\n"
"--\n"
"\n"
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
"\n"
" fd\n"
" An open file descriptor.\n"
" command\n"
" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
" length\n"
" The number of bytes to lock, starting at the current position.");
#define OS_LOCKF_METHODDEF \
{"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
static PyObject *
os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length);
static PyObject *
os_lockf(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int command;
Py_off_t length;
if (!PyArg_ParseTuple(args,
"iiO&:lockf",
&fd, &command, Py_off_t_converter, &length))
goto exit;
return_value = os_lockf_impl(module, fd, command, length);
exit:
return return_value;
}
static PyObject *
os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length)
/*[clinic end generated code: output=1b28346ac7335c0f input=65da41d2106e9b79]*/
{
int res;
Py_BEGIN_ALLOW_THREADS
res = lockf(fd, command, length);
Py_END_ALLOW_THREADS
if (res < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_LOCKF */
/*[clinic input]
os.lseek -> Py_off_t
fd: int
position: Py_off_t
how: int
/
Set the position of a file descriptor. Return the new position.
Return the new cursor position in number of bytes
relative to the beginning of the file.
[clinic start generated code]*/
PyDoc_STRVAR(os_lseek__doc__,
"lseek($module, fd, position, how, /)\n"
"--\n"
"\n"
"Set the position of a file descriptor. Return the new position.\n"
"\n"
"Return the new cursor position in number of bytes\n"
"relative to the beginning of the file.");
#define OS_LSEEK_METHODDEF \
{"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
static Py_off_t
os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how);
static PyObject *
os_lseek(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_off_t position;
int how;
Py_off_t _return_value;
if (!PyArg_ParseTuple(args,
"iO&i:lseek",
&fd, Py_off_t_converter, &position, &how))
goto exit;
_return_value = os_lseek_impl(module, fd, position, how);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromPy_off_t(_return_value);
exit:
return return_value;
}
static Py_off_t
os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how)
/*[clinic end generated code: output=88cfc146f55667af input=902654ad3f96a6d3]*/
{
Py_off_t result;
if (!_PyVerify_fd(fd)) {
posix_error();
return -1;
}
#ifdef SEEK_SET
/* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
switch (how) {
case 0: how = SEEK_SET; break;
case 1: how = SEEK_CUR; break;
case 2: how = SEEK_END; break;
}
#endif /* SEEK_END */
if (PyErr_Occurred())
return -1;
if (!_PyVerify_fd(fd)) {
posix_error();
return -1;
}
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
result = _lseeki64(fd, position, how);
#else
result = lseek(fd, position, how);
#endif
Py_END_ALLOW_THREADS
if (result < 0)
posix_error();
return result;
}
/*[clinic input]
os.read
fd: int
length: Py_ssize_t
/
Read from a file descriptor. Returns a bytes object.
[clinic start generated code]*/
PyDoc_STRVAR(os_read__doc__,
"read($module, fd, length, /)\n"
"--\n"
"\n"
"Read from a file descriptor. Returns a bytes object.");
#define OS_READ_METHODDEF \
{"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
static PyObject *
os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length);
static PyObject *
os_read(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_ssize_t length;
if (!PyArg_ParseTuple(args,
"in:read",
&fd, &length))
goto exit;
return_value = os_read_impl(module, fd, length);
exit:
return return_value;
}
static PyObject *
os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length)
/*[clinic end generated code: output=1f3bc27260a24968 input=1df2eaa27c0bf1d3]*/
{
Py_ssize_t n;
PyObject *buffer;
if (length < 0) {
errno = EINVAL;
return posix_error();
}
if (!_PyVerify_fd(fd))
return posix_error();
#ifdef MS_WINDOWS
#define READ_CAST (int)
if (length > INT_MAX)
length = INT_MAX;
#else
#define READ_CAST
#endif
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
if (buffer == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
n = read(fd, PyBytes_AS_STRING(buffer), READ_CAST length);
Py_END_ALLOW_THREADS
if (n < 0) {
Py_DECREF(buffer);
return posix_error();
}
if (n != length)
_PyBytes_Resize(&buffer, n);
return buffer;
}
#if (defined(HAVE_SENDFILE) && (defined(__FreeBSD__) || defined(__DragonFly__) \
|| defined(__APPLE__))) || defined(HAVE_READV) || defined(HAVE_WRITEV)
static Py_ssize_t
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
{
int i, j;
Py_ssize_t blen, total = 0;
*iov = PyMem_New(struct iovec, cnt);
if (*iov == NULL) {
PyErr_NoMemory();
return -1;
}
*buf = PyMem_New(Py_buffer, cnt);
if (*buf == NULL) {
PyMem_Del(*iov);
PyErr_NoMemory();
return -1;
}
for (i = 0; i < cnt; i++) {
PyObject *item = PySequence_GetItem(seq, i);
if (item == NULL)
goto fail;
if (PyObject_GetBuffer(item, &(*buf)[i], type) == -1) {
Py_DECREF(item);
goto fail;
}
Py_DECREF(item);
(*iov)[i].iov_base = (*buf)[i].buf;
blen = (*buf)[i].len;
(*iov)[i].iov_len = blen;
total += blen;
}
return total;
fail:
PyMem_Del(*iov);
for (j = 0; j < i; j++) {
PyBuffer_Release(&(*buf)[j]);
}
PyMem_Del(*buf);
return -1;
}
static void
iov_cleanup(struct iovec *iov, Py_buffer *buf, int cnt)
{
int i;
PyMem_Del(iov);
for (i = 0; i < cnt; i++) {
PyBuffer_Release(&buf[i]);
}
PyMem_Del(buf);
}
#endif
#ifdef HAVE_READV
/*[clinic input]
os.readv -> Py_ssize_t
fd: int
buffers: object
/
Read from a file descriptor fd into an iterable of buffers.
The buffers should be mutable buffers accepting bytes.
readv will transfer data into each buffer until it is full
and then move on to the next buffer in the sequence to hold
the rest of the data.
readv returns the total number of bytes read,
which may be less than the total capacity of all the buffers.
[clinic start generated code]*/
PyDoc_STRVAR(os_readv__doc__,
"readv($module, fd, buffers, /)\n"
"--\n"
"\n"
"Read from a file descriptor fd into an iterable of buffers.\n"
"\n"
"The buffers should be mutable buffers accepting bytes.\n"
"readv will transfer data into each buffer until it is full\n"
"and then move on to the next buffer in the sequence to hold\n"
"the rest of the data.\n"
"\n"
"readv returns the total number of bytes read,\n"
"which may be less than the total capacity of all the buffers.");
#define OS_READV_METHODDEF \
{"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
static Py_ssize_t
os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers);
static PyObject *
os_readv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
PyObject *buffers;
Py_ssize_t _return_value;
if (!PyArg_ParseTuple(args,
"iO:readv",
&fd, &buffers))
goto exit;
_return_value = os_readv_impl(module, fd, buffers);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromSsize_t(_return_value);
exit:
return return_value;
}
static Py_ssize_t
os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers)
/*[clinic end generated code: output=72748b1c32a6e2a1 input=e679eb5dbfa0357d]*/
{
int cnt;
Py_ssize_t n;
struct iovec *iov;
Py_buffer *buf;
if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"readv() arg 2 must be a sequence");
return -1;
}
cnt = PySequence_Size(buffers);
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0)
return -1;
Py_BEGIN_ALLOW_THREADS
n = readv(fd, iov, cnt);
Py_END_ALLOW_THREADS
iov_cleanup(iov, buf, cnt);
if (n < 0) {
posix_error();
return -1;
}
return n;
}
#endif /* HAVE_READV */
#ifdef HAVE_PREAD
/*[clinic input]
# TODO length should be size_t! but Python doesn't support parsing size_t yet.
os.pread
fd: int
length: int
offset: Py_off_t
/
Read a number of bytes from a file descriptor starting at a particular offset.
Read length bytes from file descriptor fd, starting at offset bytes from
the beginning of the file. The file offset remains unchanged.
[clinic start generated code]*/
PyDoc_STRVAR(os_pread__doc__,
"pread($module, fd, length, offset, /)\n"
"--\n"
"\n"
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
"\n"
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
"the beginning of the file. The file offset remains unchanged.");
#define OS_PREAD_METHODDEF \
{"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
static PyObject *
os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset);
static PyObject *
os_pread(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int length;
Py_off_t offset;
if (!PyArg_ParseTuple(args,
"iiO&:pread",
&fd, &length, Py_off_t_converter, &offset))
goto exit;
return_value = os_pread_impl(module, fd, length, offset);
exit:
return return_value;
}
static PyObject *
os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset)
/*[clinic end generated code: output=7b62bf6c06e20ae8 input=084948dcbaa35d4c]*/
{
Py_ssize_t n;
PyObject *buffer;
if (length < 0) {
errno = EINVAL;
return posix_error();
}
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
if (buffer == NULL)
return NULL;
if (!_PyVerify_fd(fd)) {
Py_DECREF(buffer);
return posix_error();
}
Py_BEGIN_ALLOW_THREADS
n = pread(fd, PyBytes_AS_STRING(buffer), length, offset);
Py_END_ALLOW_THREADS
if (n < 0) {
Py_DECREF(buffer);
return posix_error();
}
if (n != length)
_PyBytes_Resize(&buffer, n);
return buffer;
}
#endif /* HAVE_PREAD */
/*[clinic input]
os.write -> Py_ssize_t
fd: int
data: Py_buffer
/
Write a bytes object to a file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_write__doc__,
"write($module, fd, data, /)\n"
"--\n"
"\n"
"Write a bytes object to a file descriptor.");
#define OS_WRITE_METHODDEF \
{"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
static Py_ssize_t
os_write_impl(PyModuleDef *module, int fd, Py_buffer *data);
static PyObject *
os_write(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_buffer data = {NULL, NULL};
Py_ssize_t _return_value;
if (!PyArg_ParseTuple(args,
"iy*:write",
&fd, &data))
goto exit;
_return_value = os_write_impl(module, fd, &data);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromSsize_t(_return_value);
exit:
/* Cleanup for data */
if (data.obj)
PyBuffer_Release(&data);
return return_value;
}
static Py_ssize_t
os_write_impl(PyModuleDef *module, int fd, Py_buffer *data)
/*[clinic end generated code: output=aeb96acfdd4d5112 input=3207e28963234f3c]*/
{
Py_ssize_t size;
Py_ssize_t len = data->len;
if (!_PyVerify_fd(fd)) {
posix_error();
return -1;
}
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if (len > INT_MAX)
len = INT_MAX;
size = write(fd, data->buf, (int)len);
#else
size = write(fd, data->buf, len);
#endif
Py_END_ALLOW_THREADS
if (size < 0) {
posix_error();
return -1;
}
return size;
}
#ifdef HAVE_SENDFILE
PyDoc_STRVAR(posix_sendfile__doc__,
"sendfile(out, in, offset, nbytes) -> byteswritten\n\
sendfile(out, in, offset, nbytes, headers=None, trailers=None, flags=0)\n\
-> byteswritten\n\
Copy nbytes bytes from file descriptor in to file descriptor out.");
/* AC 3.5: don't bother converting, has optional group*/
static PyObject *
posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
{
int in, out;
Py_ssize_t ret;
off_t offset;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
#ifndef __APPLE__
Py_ssize_t len;
#endif
PyObject *headers = NULL, *trailers = NULL;
Py_buffer *hbuf, *tbuf;
off_t sbytes;
struct sf_hdtr sf;
int flags = 0;
static char *keywords[] = {"out", "in",
"offset", "count",
"headers", "trailers", "flags", NULL};
sf.headers = NULL;
sf.trailers = NULL;
#ifdef __APPLE__
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile",
keywords, &out, &in, Py_off_t_converter, &offset, Py_off_t_converter, &sbytes,
#else
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile",
keywords, &out, &in, Py_off_t_converter, &offset, &len,
#endif
&headers, &trailers, &flags))
return NULL;
if (headers != NULL) {
if (!PySequence_Check(headers)) {
PyErr_SetString(PyExc_TypeError,
"sendfile() headers must be a sequence or None");
return NULL;
} else {
Py_ssize_t i = 0; /* Avoid uninitialized warning */
sf.hdr_cnt = PySequence_Size(headers);
if (sf.hdr_cnt > 0 &&
(i = iov_setup(&(sf.headers), &hbuf,
headers, sf.hdr_cnt, PyBUF_SIMPLE)) < 0)
return NULL;
#ifdef __APPLE__
sbytes += i;
#endif
}
}
if (trailers != NULL) {
if (!PySequence_Check(trailers)) {
PyErr_SetString(PyExc_TypeError,
"sendfile() trailers must be a sequence or None");
return NULL;
} else {
Py_ssize_t i = 0; /* Avoid uninitialized warning */
sf.trl_cnt = PySequence_Size(trailers);
if (sf.trl_cnt > 0 &&
(i = iov_setup(&(sf.trailers), &tbuf,
trailers, sf.trl_cnt, PyBUF_SIMPLE)) < 0)
return NULL;
#ifdef __APPLE__
sbytes += i;
#endif
}
}
Py_BEGIN_ALLOW_THREADS
#ifdef __APPLE__
ret = sendfile(in, out, offset, &sbytes, &sf, flags);
#else
ret = sendfile(in, out, offset, len, &sf, &sbytes, flags);
#endif
Py_END_ALLOW_THREADS
if (sf.headers != NULL)
iov_cleanup(sf.headers, hbuf, sf.hdr_cnt);
if (sf.trailers != NULL)
iov_cleanup(sf.trailers, tbuf, sf.trl_cnt);
if (ret < 0) {
if ((errno == EAGAIN) || (errno == EBUSY)) {
if (sbytes != 0) {
// some data has been sent
goto done;
}
else {
// no data has been sent; upper application is supposed
// to retry on EAGAIN or EBUSY
return posix_error();
}
}
return posix_error();
}
goto done;
done:
#if !defined(HAVE_LARGEFILE_SUPPORT)
return Py_BuildValue("l", sbytes);
#else
return Py_BuildValue("L", sbytes);
#endif
#else
Py_ssize_t count;
PyObject *offobj;
static char *keywords[] = {"out", "in",
"offset", "count", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile",
keywords, &out, &in, &offobj, &count))
return NULL;
#ifdef linux
if (offobj == Py_None) {
Py_BEGIN_ALLOW_THREADS
ret = sendfile(out, in, NULL, count);
Py_END_ALLOW_THREADS
if (ret < 0)
return posix_error();
return Py_BuildValue("n", ret);
}
#endif
if (!Py_off_t_converter(offobj, &offset))
return NULL;
Py_BEGIN_ALLOW_THREADS
ret = sendfile(out, in, &offset, count);
Py_END_ALLOW_THREADS
if (ret < 0)
return posix_error();
return Py_BuildValue("n", ret);
#endif
}
#endif /* HAVE_SENDFILE */
/*[clinic input]
os.fstat
fd : int
Perform a stat system call on the given file descriptor.
Like stat(), but for an open file descriptor.
Equivalent to os.stat(fd).
[clinic start generated code]*/
PyDoc_STRVAR(os_fstat__doc__,
"fstat($module, /, fd)\n"
"--\n"
"\n"
"Perform a stat system call on the given file descriptor.\n"
"\n"
"Like stat(), but for an open file descriptor.\n"
"Equivalent to os.stat(fd).");
#define OS_FSTAT_METHODDEF \
{"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__},
static PyObject *
os_fstat_impl(PyModuleDef *module, int fd);
static PyObject *
os_fstat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:fstat", _keywords,
&fd))
goto exit;
return_value = os_fstat_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_fstat_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=dae4a9678c7bd881 input=27e0e0ebbe5600c9]*/
{
STRUCT_STAT st;
int res;
Py_BEGIN_ALLOW_THREADS
res = FSTAT(fd, &st);
Py_END_ALLOW_THREADS
if (res != 0) {
#ifdef MS_WINDOWS
return PyErr_SetFromWindowsErr(0);
#else
return posix_error();
#endif
}
return _pystat_fromstructstat(&st);
}
/*[clinic input]
os.isatty -> bool
fd: int
/
Return True if the fd is connected to a terminal.
Return True if the file descriptor is an open file descriptor
connected to the slave end of a terminal.
[clinic start generated code]*/
PyDoc_STRVAR(os_isatty__doc__,
"isatty($module, fd, /)\n"
"--\n"
"\n"
"Return True if the fd is connected to a terminal.\n"
"\n"
"Return True if the file descriptor is an open file descriptor\n"
"connected to the slave end of a terminal.");
#define OS_ISATTY_METHODDEF \
{"isatty", (PyCFunction)os_isatty, METH_VARARGS, os_isatty__doc__},
static int
os_isatty_impl(PyModuleDef *module, int fd);
static PyObject *
os_isatty(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int _return_value;
if (!PyArg_ParseTuple(args,
"i:isatty",
&fd))
goto exit;
_return_value = os_isatty_impl(module, fd);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_isatty_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=4bfadbfe22715097 input=08ce94aa1eaf7b5e]*/
{
if (!_PyVerify_fd(fd))
return 0;
return isatty(fd);
}
#ifdef HAVE_PIPE
/*[clinic input]
os.pipe
Create a pipe.
Returns a tuple of two file descriptors:
(read_fd, write_fd)
[clinic start generated code]*/
PyDoc_STRVAR(os_pipe__doc__,
"pipe($module, /)\n"
"--\n"
"\n"
"Create a pipe.\n"
"\n"
"Returns a tuple of two file descriptors:\n"
" (read_fd, write_fd)");
#define OS_PIPE_METHODDEF \
{"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
static PyObject *
os_pipe_impl(PyModuleDef *module);
static PyObject *
os_pipe(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_pipe_impl(module);
}
static PyObject *
os_pipe_impl(PyModuleDef *module)
/*[clinic end generated code: output=0da2479f2266e774 input=02535e8c8fa6c4d4]*/
{
int fds[2];
#ifdef MS_WINDOWS
HANDLE read, write;
SECURITY_ATTRIBUTES attr;
BOOL ok;
#else
int res;
#endif
#ifdef MS_WINDOWS
attr.nLength = sizeof(attr);
attr.lpSecurityDescriptor = NULL;
attr.bInheritHandle = FALSE;
Py_BEGIN_ALLOW_THREADS
ok = CreatePipe(&read, &write, &attr, 0);
if (ok) {
fds[0] = _open_osfhandle((Py_intptr_t)read, _O_RDONLY);
fds[1] = _open_osfhandle((Py_intptr_t)write, _O_WRONLY);
if (fds[0] == -1 || fds[1] == -1) {
CloseHandle(read);
CloseHandle(write);
ok = 0;
}
}
Py_END_ALLOW_THREADS
if (!ok)
return PyErr_SetFromWindowsErr(0);
#else
#ifdef HAVE_PIPE2
Py_BEGIN_ALLOW_THREADS
res = pipe2(fds, O_CLOEXEC);
Py_END_ALLOW_THREADS
if (res != 0 && errno == ENOSYS)
{
#endif
Py_BEGIN_ALLOW_THREADS
res = pipe(fds);
Py_END_ALLOW_THREADS
if (res == 0) {
if (_Py_set_inheritable(fds[0], 0, NULL) < 0) {
close(fds[0]);
close(fds[1]);
return NULL;
}
if (_Py_set_inheritable(fds[1], 0, NULL) < 0) {
close(fds[0]);
close(fds[1]);
return NULL;
}
}
#ifdef HAVE_PIPE2
}
#endif
if (res != 0)
return PyErr_SetFromErrno(PyExc_OSError);
#endif /* !MS_WINDOWS */
return Py_BuildValue("(ii)", fds[0], fds[1]);
}
#endif /* HAVE_PIPE */
#ifdef HAVE_PIPE2
/*[clinic input]
os.pipe2
flags: int
/
Create a pipe with flags set atomically.
Returns a tuple of two file descriptors:
(read_fd, write_fd)
flags can be constructed by ORing together one or more of these values:
O_NONBLOCK, O_CLOEXEC.
[clinic start generated code]*/
PyDoc_STRVAR(os_pipe2__doc__,
"pipe2($module, flags, /)\n"
"--\n"
"\n"
"Create a pipe with flags set atomically.\n"
"\n"
"Returns a tuple of two file descriptors:\n"
" (read_fd, write_fd)\n"
"\n"
"flags can be constructed by ORing together one or more of these values:\n"
"O_NONBLOCK, O_CLOEXEC.");
#define OS_PIPE2_METHODDEF \
{"pipe2", (PyCFunction)os_pipe2, METH_VARARGS, os_pipe2__doc__},
static PyObject *
os_pipe2_impl(PyModuleDef *module, int flags);
static PyObject *
os_pipe2(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int flags;
if (!PyArg_ParseTuple(args,
"i:pipe2",
&flags))
goto exit;
return_value = os_pipe2_impl(module, flags);
exit:
return return_value;
}
static PyObject *
os_pipe2_impl(PyModuleDef *module, int flags)
/*[clinic end generated code: output=9e27c799ce19220b input=f261b6e7e63c6817]*/
{
int fds[2];
int res;
res = pipe2(fds, flags);
if (res != 0)
return posix_error();
return Py_BuildValue("(ii)", fds[0], fds[1]);
}
#endif /* HAVE_PIPE2 */
#ifdef HAVE_WRITEV
/*[clinic input]
os.writev -> Py_ssize_t
fd: int
buffers: object
/
Iterate over buffers, and write the contents of each to a file descriptor.
Returns the total number of bytes written.
buffers must be a sequence of bytes-like objects.
[clinic start generated code]*/
PyDoc_STRVAR(os_writev__doc__,
"writev($module, fd, buffers, /)\n"
"--\n"
"\n"
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
"\n"
"Returns the total number of bytes written.\n"
"buffers must be a sequence of bytes-like objects.");
#define OS_WRITEV_METHODDEF \
{"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
static Py_ssize_t
os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers);
static PyObject *
os_writev(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
PyObject *buffers;
Py_ssize_t _return_value;
if (!PyArg_ParseTuple(args,
"iO:writev",
&fd, &buffers))
goto exit;
_return_value = os_writev_impl(module, fd, buffers);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromSsize_t(_return_value);
exit:
return return_value;
}
static Py_ssize_t
os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers)
/*[clinic end generated code: output=591c662dccbe4951 input=5b8d17fe4189d2fe]*/
{
int cnt;
Py_ssize_t result;
struct iovec *iov;
Py_buffer *buf;
if (!PySequence_Check(buffers)) {
PyErr_SetString(PyExc_TypeError,
"writev() arg 2 must be a sequence");
return -1;
}
cnt = PySequence_Size(buffers);
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) {
return -1;
}
Py_BEGIN_ALLOW_THREADS
result = writev(fd, iov, cnt);
Py_END_ALLOW_THREADS
iov_cleanup(iov, buf, cnt);
if (result < 0)
posix_error();
return result;
}
#endif /* HAVE_WRITEV */
#ifdef HAVE_PWRITE
/*[clinic input]
os.pwrite -> Py_ssize_t
fd: int
buffer: Py_buffer
offset: Py_off_t
/
Write bytes to a file descriptor starting at a particular offset.
Write buffer to fd, starting at offset bytes from the beginning of
the file. Returns the number of bytes writte. Does not change the
current file offset.
[clinic start generated code]*/
PyDoc_STRVAR(os_pwrite__doc__,
"pwrite($module, fd, buffer, offset, /)\n"
"--\n"
"\n"
"Write bytes to a file descriptor starting at a particular offset.\n"
"\n"
"Write buffer to fd, starting at offset bytes from the beginning of\n"
"the file. Returns the number of bytes writte. Does not change the\n"
"current file offset.");
#define OS_PWRITE_METHODDEF \
{"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
static Py_ssize_t
os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset);
static PyObject *
os_pwrite(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_buffer buffer = {NULL, NULL};
Py_off_t offset;
Py_ssize_t _return_value;
if (!PyArg_ParseTuple(args,
"iy*O&:pwrite",
&fd, &buffer, Py_off_t_converter, &offset))
goto exit;
_return_value = os_pwrite_impl(module, fd, &buffer, offset);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromSsize_t(_return_value);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
static Py_ssize_t
os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset)
/*[clinic end generated code: output=ec9cc5b2238e96a7 input=19903f1b3dd26377]*/
{
Py_ssize_t size;
if (!_PyVerify_fd(fd)) {
posix_error();
return -1;
}
Py_BEGIN_ALLOW_THREADS
size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset);
Py_END_ALLOW_THREADS
if (size < 0)
posix_error();
return size;
}
#endif /* HAVE_PWRITE */
#ifdef HAVE_MKFIFO
/*[clinic input]
os.mkfifo
path: path_t
mode: int=0o666
*
dir_fd: dir_fd(requires='mkfifoat')=None
Create a "fifo" (a POSIX named pipe).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_mkfifo__doc__,
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
"--\n"
"\n"
"Create a \"fifo\" (a POSIX named pipe).\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_MKFIFO_METHODDEF \
{"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__},
static PyObject *
os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd);
static PyObject *
os_mkfifo(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
int mode = 438;
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|i$O&:mkfifo", _keywords,
path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd)
/*[clinic end generated code: output=b3321927546893d0 input=73032e98a36e0e19]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_MKFIFOAT
if (dir_fd != DEFAULT_DIR_FD)
result = mkfifoat(dir_fd, path->narrow, mode);
else
#endif
result = mkfifo(path->narrow, mode);
Py_END_ALLOW_THREADS
if (result < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_MKFIFO */
#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
/*[clinic input]
os.mknod
path: path_t
mode: int=0o600
device: int=0
*
dir_fd: dir_fd(requires='mknodat')=None
Create a node in the file system.
Create a node in the file system (file, device special file or named pipe)
at path. mode specifies both the permissions to use and the
type of node to be created, being combined (bitwise OR) with one of
S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,
device defines the newly created device special file (probably using
os.makedev()). Otherwise device is ignored.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
[clinic start generated code]*/
PyDoc_STRVAR(os_mknod__doc__,
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
"--\n"
"\n"
"Create a node in the file system.\n"
"\n"
"Create a node in the file system (file, device special file or named pipe)\n"
"at path. mode specifies both the permissions to use and the\n"
"type of node to be created, being combined (bitwise OR) with one of\n"
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
"device defines the newly created device special file (probably using\n"
"os.makedev()). Otherwise device is ignored.\n"
"\n"
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
" and path should be relative; path will then be relative to that directory.\n"
"dir_fd may not be implemented on your platform.\n"
" If it is unavailable, using it will raise a NotImplementedError.");
#define OS_MKNOD_METHODDEF \
{"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__},
static PyObject *
os_mknod_impl(PyModuleDef *module, path_t *path, int mode, int device, int dir_fd);
static PyObject *
os_mknod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL};
path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
int mode = 384;
int device = 0;
int dir_fd = DEFAULT_DIR_FD;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&|ii$O&:mknod", _keywords,
path_converter, &path, &mode, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd))
goto exit;
return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_mknod_impl(PyModuleDef *module, path_t *path, int mode, int device, int dir_fd)
/*[clinic end generated code: output=c688739c15ca7bbb input=30e02126aba9732e]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_MKNODAT
if (dir_fd != DEFAULT_DIR_FD)
result = mknodat(dir_fd, path->narrow, mode, device);
else
#endif
result = mknod(path->narrow, mode, device);
Py_END_ALLOW_THREADS
if (result < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) */
#ifdef HAVE_DEVICE_MACROS
/*[clinic input]
os.major -> unsigned_int
device: int
/
Extracts a device major number from a raw device number.
[clinic start generated code]*/
PyDoc_STRVAR(os_major__doc__,
"major($module, device, /)\n"
"--\n"
"\n"
"Extracts a device major number from a raw device number.");
#define OS_MAJOR_METHODDEF \
{"major", (PyCFunction)os_major, METH_VARARGS, os_major__doc__},
static unsigned int
os_major_impl(PyModuleDef *module, int device);
static PyObject *
os_major(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int device;
unsigned int _return_value;
if (!PyArg_ParseTuple(args,
"i:major",
&device))
goto exit;
_return_value = os_major_impl(module, device);
if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
exit:
return return_value;
}
static unsigned int
os_major_impl(PyModuleDef *module, int device)
/*[clinic end generated code: output=52e6743300dcf4ad input=ea48820b7e10d310]*/
{
return major(device);
}
/*[clinic input]
os.minor -> unsigned_int
device: int
/
Extracts a device minor number from a raw device number.
[clinic start generated code]*/
PyDoc_STRVAR(os_minor__doc__,
"minor($module, device, /)\n"
"--\n"
"\n"
"Extracts a device minor number from a raw device number.");
#define OS_MINOR_METHODDEF \
{"minor", (PyCFunction)os_minor, METH_VARARGS, os_minor__doc__},
static unsigned int
os_minor_impl(PyModuleDef *module, int device);
static PyObject *
os_minor(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int device;
unsigned int _return_value;
if (!PyArg_ParseTuple(args,
"i:minor",
&device))
goto exit;
_return_value = os_minor_impl(module, device);
if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
exit:
return return_value;
}
static unsigned int
os_minor_impl(PyModuleDef *module, int device)
/*[clinic end generated code: output=aebe4bd7f455b755 input=089733ebbf9754e8]*/
{
return minor(device);
}
/*[clinic input]
os.makedev -> unsigned_int
major: int
minor: int
/
Composes a raw device number from the major and minor device numbers.
[clinic start generated code]*/
PyDoc_STRVAR(os_makedev__doc__,
"makedev($module, major, minor, /)\n"
"--\n"
"\n"
"Composes a raw device number from the major and minor device numbers.");
#define OS_MAKEDEV_METHODDEF \
{"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
static unsigned int
os_makedev_impl(PyModuleDef *module, int major, int minor);
static PyObject *
os_makedev(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int major;
int minor;
unsigned int _return_value;
if (!PyArg_ParseTuple(args,
"ii:makedev",
&major, &minor))
goto exit;
_return_value = os_makedev_impl(module, major, minor);
if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
exit:
return return_value;
}
static unsigned int
os_makedev_impl(PyModuleDef *module, int major, int minor)
/*[clinic end generated code: output=5cb79d9c9eac58b0 input=f55bf7cffb028a08]*/
{
return makedev(major, minor);
}
#endif /* HAVE_DEVICE_MACROS */
#ifdef HAVE_FTRUNCATE
/*[clinic input]
os.ftruncate
fd: int
length: Py_off_t
/
Truncate a file, specified by file descriptor, to a specific length.
[clinic start generated code]*/
PyDoc_STRVAR(os_ftruncate__doc__,
"ftruncate($module, fd, length, /)\n"
"--\n"
"\n"
"Truncate a file, specified by file descriptor, to a specific length.");
#define OS_FTRUNCATE_METHODDEF \
{"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
static PyObject *
os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length);
static PyObject *
os_ftruncate(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_off_t length;
if (!PyArg_ParseTuple(args,
"iO&:ftruncate",
&fd, Py_off_t_converter, &length))
goto exit;
return_value = os_ftruncate_impl(module, fd, length);
exit:
return return_value;
}
static PyObject *
os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length)
/*[clinic end generated code: output=62326766cb9b76bf input=63b43641e52818f2]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
result = ftruncate(fd, length);
Py_END_ALLOW_THREADS
if (result < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_FTRUNCATE */
#ifdef HAVE_TRUNCATE
/*[clinic input]
os.truncate
path: path_t(allow_fd='PATH_HAVE_FTRUNCATE')
length: Py_off_t
Truncate a file, specified by path, to a specific length.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
[clinic start generated code]*/
PyDoc_STRVAR(os_truncate__doc__,
"truncate($module, /, path, length)\n"
"--\n"
"\n"
"Truncate a file, specified by path, to a specific length.\n"
"\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.");
#define OS_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__},
static PyObject *
os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length);
static PyObject *
os_truncate(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "length", NULL};
path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
Py_off_t length;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&:truncate", _keywords,
path_converter, &path, Py_off_t_converter, &length))
goto exit;
return_value = os_truncate_impl(module, &path, length);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length)
/*[clinic end generated code: output=6bd76262d2e027c6 input=77229cf0b50a9b77]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FTRUNCATE
if (path->fd != -1)
result = ftruncate(path->fd, length);
else
#endif
result = truncate(path->narrow, length);
Py_END_ALLOW_THREADS
if (result < 0)
return path_error(path);
Py_RETURN_NONE;
}
#endif /* HAVE_TRUNCATE */
#ifdef HAVE_POSIX_FALLOCATE
/*[clinic input]
os.posix_fallocate
fd: int
offset: Py_off_t
length: Py_off_t
/
Ensure a file has allocated at least a particular number of bytes on disk.
Ensure that the file specified by fd encompasses a range of bytes
starting at offset bytes from the beginning and continuing for length bytes.
[clinic start generated code]*/
PyDoc_STRVAR(os_posix_fallocate__doc__,
"posix_fallocate($module, fd, offset, length, /)\n"
"--\n"
"\n"
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
"\n"
"Ensure that the file specified by fd encompasses a range of bytes\n"
"starting at offset bytes from the beginning and continuing for length bytes.");
#define OS_POSIX_FALLOCATE_METHODDEF \
{"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
static PyObject *
os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length);
static PyObject *
os_posix_fallocate(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_off_t offset;
Py_off_t length;
if (!PyArg_ParseTuple(args,
"iO&O&:posix_fallocate",
&fd, Py_off_t_converter, &offset, Py_off_t_converter, &length))
goto exit;
return_value = os_posix_fallocate_impl(module, fd, offset, length);
exit:
return return_value;
}
static PyObject *
os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length)
/*[clinic end generated code: output=0cd702d2065c79db input=d7a2ef0ab2ca52fb]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
result = posix_fallocate(fd, offset, length);
Py_END_ALLOW_THREADS
if (result != 0) {
errno = result;
return posix_error();
}
Py_RETURN_NONE;
}
#endif /* HAVE_POSIX_FALLOCATE */
#ifdef HAVE_POSIX_FADVISE
/*[clinic input]
os.posix_fadvise
fd: int
offset: Py_off_t
length: Py_off_t
advice: int
/
Announce an intention to access data in a specific pattern.
Announce an intention to access data in a specific pattern, thus allowing
the kernel to make optimizations.
The advice applies to the region of the file specified by fd starting at
offset and continuing for length bytes.
advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,
POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or
POSIX_FADV_DONTNEED.
[clinic start generated code]*/
PyDoc_STRVAR(os_posix_fadvise__doc__,
"posix_fadvise($module, fd, offset, length, advice, /)\n"
"--\n"
"\n"
"Announce an intention to access data in a specific pattern.\n"
"\n"
"Announce an intention to access data in a specific pattern, thus allowing\n"
"the kernel to make optimizations.\n"
"The advice applies to the region of the file specified by fd starting at\n"
"offset and continuing for length bytes.\n"
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
"POSIX_FADV_DONTNEED.");
#define OS_POSIX_FADVISE_METHODDEF \
{"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
static PyObject *
os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice);
static PyObject *
os_posix_fadvise(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
Py_off_t offset;
Py_off_t length;
int advice;
if (!PyArg_ParseTuple(args,
"iO&O&i:posix_fadvise",
&fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice))
goto exit;
return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
exit:
return return_value;
}
static PyObject *
os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice)
/*[clinic end generated code: output=dad93f32c04dd4f7 input=0fbe554edc2f04b5]*/
{
int result;
Py_BEGIN_ALLOW_THREADS
result = posix_fadvise(fd, offset, length, advice);
Py_END_ALLOW_THREADS
if (result != 0) {
errno = result;
return posix_error();
}
Py_RETURN_NONE;
}
#endif /* HAVE_POSIX_FADVISE */
#ifdef HAVE_PUTENV
/* Save putenv() parameters as values here, so we can collect them when they
* get re-set with another call for the same key. */
static PyObject *posix_putenv_garbage;
static void
posix_putenv_garbage_setitem(PyObject *name, PyObject *value)
{
/* Install the first arg and newstr in posix_putenv_garbage;
* this will cause previous value to be collected. This has to
* happen after the real putenv() call because the old value
* was still accessible until then. */
if (PyDict_SetItem(posix_putenv_garbage, name, value))
/* really not much we can do; just leak */
PyErr_Clear();
else
Py_DECREF(value);
}
#ifdef MS_WINDOWS
/*[clinic input]
os.putenv
name: unicode
value: unicode
/
Change or add an environment variable.
[clinic start generated code]*/
PyDoc_STRVAR(os_putenv__doc__,
"putenv($module, name, value, /)\n"
"--\n"
"\n"
"Change or add an environment variable.");
#define OS_PUTENV_METHODDEF \
{"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
static PyObject *
os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value);
static PyObject *
os_putenv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *name;
PyObject *value;
if (!PyArg_ParseTuple(args,
"UU:putenv",
&name, &value))
goto exit;
return_value = os_putenv_impl(module, name, value);
exit:
return return_value;
}
static PyObject *
os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value)
/*[clinic end generated code: output=5ce9ef9b15606e7e input=ba586581c2e6105f]*/
{
wchar_t *env;
PyObject *unicode = PyUnicode_FromFormat("%U=%U", name, value);
if (unicode == NULL) {
PyErr_NoMemory();
return NULL;
}
if (_MAX_ENV < PyUnicode_GET_LENGTH(unicode)) {
PyErr_Format(PyExc_ValueError,
"the environment variable is longer than %u characters",
_MAX_ENV);
goto error;
}
env = PyUnicode_AsUnicode(unicode);
if (env == NULL)
goto error;
if (_wputenv(env)) {
posix_error();
goto error;
}
posix_putenv_garbage_setitem(name, unicode);
Py_RETURN_NONE;
error:
Py_DECREF(unicode);
return NULL;
}
#else /* MS_WINDOWS */
/*[clinic input]
os.putenv
name: FSConverter
value: FSConverter
/
Change or add an environment variable.
[clinic start generated code]*/
PyDoc_STRVAR(os_putenv__doc__,
"putenv($module, name, value, /)\n"
"--\n"
"\n"
"Change or add an environment variable.");
#define OS_PUTENV_METHODDEF \
{"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
static PyObject *
os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value);
static PyObject *
os_putenv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *name = NULL;
PyObject *value = NULL;
if (!PyArg_ParseTuple(args,
"O&O&:putenv",
PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value))
goto exit;
return_value = os_putenv_impl(module, name, value);
exit:
/* Cleanup for name */
Py_XDECREF(name);
/* Cleanup for value */
Py_XDECREF(value);
return return_value;
}
static PyObject *
os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value)
/*[clinic end generated code: output=85ab223393dc7afd input=a97bc6152f688d31]*/
{
PyObject *bytes = NULL;
char *env;
char *name_string = PyBytes_AsString(name);
char *value_string = PyBytes_AsString(value);
bytes = PyBytes_FromFormat("%s=%s", name_string, value_string);
if (bytes == NULL) {
PyErr_NoMemory();
return NULL;
}
env = PyBytes_AS_STRING(bytes);
if (putenv(env)) {
Py_DECREF(bytes);
return posix_error();
}
posix_putenv_garbage_setitem(name, bytes);
Py_RETURN_NONE;
}
#endif /* MS_WINDOWS */
#endif /* HAVE_PUTENV */
#ifdef HAVE_UNSETENV
/*[clinic input]
os.unsetenv
name: FSConverter
/
Delete an environment variable.
[clinic start generated code]*/
PyDoc_STRVAR(os_unsetenv__doc__,
"unsetenv($module, name, /)\n"
"--\n"
"\n"
"Delete an environment variable.");
#define OS_UNSETENV_METHODDEF \
{"unsetenv", (PyCFunction)os_unsetenv, METH_VARARGS, os_unsetenv__doc__},
static PyObject *
os_unsetenv_impl(PyModuleDef *module, PyObject *name);
static PyObject *
os_unsetenv(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *name = NULL;
if (!PyArg_ParseTuple(args,
"O&:unsetenv",
PyUnicode_FSConverter, &name))
goto exit;
return_value = os_unsetenv_impl(module, name);
exit:
/* Cleanup for name */
Py_XDECREF(name);
return return_value;
}
static PyObject *
os_unsetenv_impl(PyModuleDef *module, PyObject *name)
/*[clinic end generated code: output=91318c995f9a0767 input=2bb5288a599c7107]*/
{
#ifndef HAVE_BROKEN_UNSETENV
int err;
#endif
#ifdef HAVE_BROKEN_UNSETENV
unsetenv(PyBytes_AS_STRING(name));
#else
err = unsetenv(PyBytes_AS_STRING(name));
if (err)
return posix_error();
#endif
/* Remove the key from posix_putenv_garbage;
* this will cause it to be collected. This has to
* happen after the real unsetenv() call because the
* old value was still accessible until then.
*/
if (PyDict_DelItem(posix_putenv_garbage, name)) {
/* really not much we can do; just leak */
PyErr_Clear();
}
Py_RETURN_NONE;
}
#endif /* HAVE_UNSETENV */
/*[clinic input]
os.strerror
code: int
/
Translate an error code to a message string.
[clinic start generated code]*/
PyDoc_STRVAR(os_strerror__doc__,
"strerror($module, code, /)\n"
"--\n"
"\n"
"Translate an error code to a message string.");
#define OS_STRERROR_METHODDEF \
{"strerror", (PyCFunction)os_strerror, METH_VARARGS, os_strerror__doc__},
static PyObject *
os_strerror_impl(PyModuleDef *module, int code);
static PyObject *
os_strerror(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int code;
if (!PyArg_ParseTuple(args,
"i:strerror",
&code))
goto exit;
return_value = os_strerror_impl(module, code);
exit:
return return_value;
}
static PyObject *
os_strerror_impl(PyModuleDef *module, int code)
/*[clinic end generated code: output=8665c70bb2ca4720 input=75a8673d97915a91]*/
{
char *message = strerror(code);
if (message == NULL) {
PyErr_SetString(PyExc_ValueError,
"strerror() argument out of range");
return NULL;
}
return PyUnicode_DecodeLocale(message, "surrogateescape");
}
#ifdef HAVE_SYS_WAIT_H
#ifdef WCOREDUMP
/*[clinic input]
os.WCOREDUMP -> bool
status: int
/
Return True if the process returning status was dumped to a core file.
[clinic start generated code]*/
PyDoc_STRVAR(os_WCOREDUMP__doc__,
"WCOREDUMP($module, status, /)\n"
"--\n"
"\n"
"Return True if the process returning status was dumped to a core file.");
#define OS_WCOREDUMP_METHODDEF \
{"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_VARARGS, os_WCOREDUMP__doc__},
static int
os_WCOREDUMP_impl(PyModuleDef *module, int status);
static PyObject *
os_WCOREDUMP(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int status;
int _return_value;
if (!PyArg_ParseTuple(args,
"i:WCOREDUMP",
&status))
goto exit;
_return_value = os_WCOREDUMP_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WCOREDUMP_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=e04d55c09c299828 input=8b05e7ab38528d04]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WCOREDUMP(wait_status);
}
#endif /* WCOREDUMP */
#ifdef WIFCONTINUED
/*[clinic input]
os.WIFCONTINUED -> bool
status: int
Return True if a particular process was continued from a job control stop.
Return True if the process returning status was continued from a
job control stop.
[clinic start generated code]*/
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
"WIFCONTINUED($module, /, status)\n"
"--\n"
"\n"
"Return True if a particular process was continued from a job control stop.\n"
"\n"
"Return True if the process returning status was continued from a\n"
"job control stop.");
#define OS_WIFCONTINUED_METHODDEF \
{"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__},
static int
os_WIFCONTINUED_impl(PyModuleDef *module, int status);
static PyObject *
os_WIFCONTINUED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WIFCONTINUED", _keywords,
&status))
goto exit;
_return_value = os_WIFCONTINUED_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WIFCONTINUED_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=9c4e6105a4520ab5 input=e777e7d38eb25bd9]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WIFCONTINUED(wait_status);
}
#endif /* WIFCONTINUED */
#ifdef WIFSTOPPED
/*[clinic input]
os.WIFSTOPPED -> bool
status: int
Return True if the process returning status was stopped.
[clinic start generated code]*/
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
"WIFSTOPPED($module, /, status)\n"
"--\n"
"\n"
"Return True if the process returning status was stopped.");
#define OS_WIFSTOPPED_METHODDEF \
{"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__},
static int
os_WIFSTOPPED_impl(PyModuleDef *module, int status);
static PyObject *
os_WIFSTOPPED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WIFSTOPPED", _keywords,
&status))
goto exit;
_return_value = os_WIFSTOPPED_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WIFSTOPPED_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=e0de2da8ec9593ff input=043cb7f1289ef904]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WIFSTOPPED(wait_status);
}
#endif /* WIFSTOPPED */
#ifdef WIFSIGNALED
/*[clinic input]
os.WIFSIGNALED -> bool
status: int
Return True if the process returning status was terminated by a signal.
[clinic start generated code]*/
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
"WIFSIGNALED($module, /, status)\n"
"--\n"
"\n"
"Return True if the process returning status was terminated by a signal.");
#define OS_WIFSIGNALED_METHODDEF \
{"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__},
static int
os_WIFSIGNALED_impl(PyModuleDef *module, int status);
static PyObject *
os_WIFSIGNALED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WIFSIGNALED", _keywords,
&status))
goto exit;
_return_value = os_WIFSIGNALED_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WIFSIGNALED_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=f14d106558f406be input=d55ba7cc9ce5dc43]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WIFSIGNALED(wait_status);
}
#endif /* WIFSIGNALED */
#ifdef WIFEXITED
/*[clinic input]
os.WIFEXITED -> bool
status: int
Return True if the process returning status exited via the exit() system call.
[clinic start generated code]*/
PyDoc_STRVAR(os_WIFEXITED__doc__,
"WIFEXITED($module, /, status)\n"
"--\n"
"\n"
"Return True if the process returning status exited via the exit() system call.");
#define OS_WIFEXITED_METHODDEF \
{"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__},
static int
os_WIFEXITED_impl(PyModuleDef *module, int status);
static PyObject *
os_WIFEXITED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WIFEXITED", _keywords,
&status))
goto exit;
_return_value = os_WIFEXITED_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WIFEXITED_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=2f76087d53721255 input=d63775a6791586c0]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WIFEXITED(wait_status);
}
#endif /* WIFEXITED */
#ifdef WEXITSTATUS
/*[clinic input]
os.WEXITSTATUS -> int
status: int
Return the process return code from status.
[clinic start generated code]*/
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
"WEXITSTATUS($module, /, status)\n"
"--\n"
"\n"
"Return the process return code from status.");
#define OS_WEXITSTATUS_METHODDEF \
{"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__},
static int
os_WEXITSTATUS_impl(PyModuleDef *module, int status);
static PyObject *
os_WEXITSTATUS(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WEXITSTATUS", _keywords,
&status))
goto exit;
_return_value = os_WEXITSTATUS_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WEXITSTATUS_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=13b6c270e2a326b1 input=e1fb4944e377585b]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WEXITSTATUS(wait_status);
}
#endif /* WEXITSTATUS */
#ifdef WTERMSIG
/*[clinic input]
os.WTERMSIG -> int
status: int
Return the signal that terminated the process that provided the status value.
[clinic start generated code]*/
PyDoc_STRVAR(os_WTERMSIG__doc__,
"WTERMSIG($module, /, status)\n"
"--\n"
"\n"
"Return the signal that terminated the process that provided the status value.");
#define OS_WTERMSIG_METHODDEF \
{"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__},
static int
os_WTERMSIG_impl(PyModuleDef *module, int status);
static PyObject *
os_WTERMSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WTERMSIG", _keywords,
&status))
goto exit;
_return_value = os_WTERMSIG_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WTERMSIG_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=bf1fd4b002d0a9ed input=727fd7f84ec3f243]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WTERMSIG(wait_status);
}
#endif /* WTERMSIG */
#ifdef WSTOPSIG
/*[clinic input]
os.WSTOPSIG -> int
status: int
Return the signal that stopped the process that provided the status value.
[clinic start generated code]*/
PyDoc_STRVAR(os_WSTOPSIG__doc__,
"WSTOPSIG($module, /, status)\n"
"--\n"
"\n"
"Return the signal that stopped the process that provided the status value.");
#define OS_WSTOPSIG_METHODDEF \
{"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__},
static int
os_WSTOPSIG_impl(PyModuleDef *module, int status);
static PyObject *
os_WSTOPSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"status", NULL};
int status;
int _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:WSTOPSIG", _keywords,
&status))
goto exit;
_return_value = os_WSTOPSIG_impl(module, status);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_WSTOPSIG_impl(PyModuleDef *module, int status)
/*[clinic end generated code: output=92e1647d29ee0549 input=46ebf1d1b293c5c1]*/
{
WAIT_TYPE wait_status;
WAIT_STATUS_INT(wait_status) = status;
return WSTOPSIG(wait_status);
}
#endif /* WSTOPSIG */
#endif /* HAVE_SYS_WAIT_H */
#ifndef OS_WCOREDUMP_METHODDEF
#define OS_WCOREDUMP_METHODDEF
#endif /* OS_WCOREDUMP_METHODDEF */
#ifndef OS_WIFCONTINUED_METHODDEF
#define OS_WIFCONTINUED_METHODDEF
#endif /* OS_WIFCONTINUED_METHODDEF */
#ifndef OS_WIFSTOPPED_METHODDEF
#define OS_WIFSTOPPED_METHODDEF
#endif /* OS_WIFSTOPPED_METHODDEF */
#ifndef OS_WIFSIGNALED_METHODDEF
#define OS_WIFSIGNALED_METHODDEF
#endif /* OS_WIFSIGNALED_METHODDEF */
#ifndef OS_WIFEXITED_METHODDEF
#define OS_WIFEXITED_METHODDEF
#endif /* OS_WIFEXITED_METHODDEF */
#ifndef OS_WEXITSTATUS_METHODDEF
#define OS_WEXITSTATUS_METHODDEF
#endif /* OS_WEXITSTATUS_METHODDEF */
#ifndef OS_WTERMSIG_METHODDEF
#define OS_WTERMSIG_METHODDEF
#endif /* OS_WTERMSIG_METHODDEF */
#ifndef OS_WSTOPSIG_METHODDEF
#define OS_WSTOPSIG_METHODDEF
#endif /* OS_WSTOPSIG_METHODDEF */
#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)
#ifdef _SCO_DS
/* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the
needed definitions in sys/statvfs.h */
#define _SVID3
#endif
#include <sys/statvfs.h>
static PyObject*
_pystatvfs_fromstructstatvfs(struct statvfs st) {
PyObject *v = PyStructSequence_New(&StatVFSResultType);
if (v == NULL)
return NULL;
#if !defined(HAVE_LARGEFILE_SUPPORT)
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long) st.f_blocks));
PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long) st.f_bfree));
PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long) st.f_bavail));
PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long) st.f_files));
PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong((long) st.f_ffree));
PyStructSequence_SET_ITEM(v, 7, PyLong_FromLong((long) st.f_favail));
PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
#else
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
PyStructSequence_SET_ITEM(v, 2,
PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
PyStructSequence_SET_ITEM(v, 3,
PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));
PyStructSequence_SET_ITEM(v, 4,
PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));
PyStructSequence_SET_ITEM(v, 5,
PyLong_FromLongLong((PY_LONG_LONG) st.f_files));
PyStructSequence_SET_ITEM(v, 6,
PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
PyStructSequence_SET_ITEM(v, 7,
PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
#endif
if (PyErr_Occurred()) {
Py_DECREF(v);
return NULL;
}
return v;
}
/*[clinic input]
os.fstatvfs
fd: int
/
Perform an fstatvfs system call on the given fd.
Equivalent to statvfs(fd).
[clinic start generated code]*/
PyDoc_STRVAR(os_fstatvfs__doc__,
"fstatvfs($module, fd, /)\n"
"--\n"
"\n"
"Perform an fstatvfs system call on the given fd.\n"
"\n"
"Equivalent to statvfs(fd).");
#define OS_FSTATVFS_METHODDEF \
{"fstatvfs", (PyCFunction)os_fstatvfs, METH_VARARGS, os_fstatvfs__doc__},
static PyObject *
os_fstatvfs_impl(PyModuleDef *module, int fd);
static PyObject *
os_fstatvfs(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
if (!PyArg_ParseTuple(args,
"i:fstatvfs",
&fd))
goto exit;
return_value = os_fstatvfs_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_fstatvfs_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=0e32bf07f946ec0d input=d8122243ac50975e]*/
{
int result;
struct statvfs st;
Py_BEGIN_ALLOW_THREADS
result = fstatvfs(fd, &st);
Py_END_ALLOW_THREADS
if (result != 0)
return posix_error();
return _pystatvfs_fromstructstatvfs(st);
}
#endif /* defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) */
#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
#include <sys/statvfs.h>
/*[clinic input]
os.statvfs
path: path_t(allow_fd='PATH_HAVE_FSTATVFS')
Perform a statvfs system call on the given path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
[clinic start generated code]*/
PyDoc_STRVAR(os_statvfs__doc__,
"statvfs($module, /, path)\n"
"--\n"
"\n"
"Perform a statvfs system call on the given path.\n"
"\n"
"path may always be specified as a string.\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.");
#define OS_STATVFS_METHODDEF \
{"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__},
static PyObject *
os_statvfs_impl(PyModuleDef *module, path_t *path);
static PyObject *
os_statvfs(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&:statvfs", _keywords,
path_converter, &path))
goto exit;
return_value = os_statvfs_impl(module, &path);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_statvfs_impl(PyModuleDef *module, path_t *path)
/*[clinic end generated code: output=00ff54983360b446 input=3f5c35791c669bd9]*/
{
int result;
struct statvfs st;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_FSTATVFS
if (path->fd != -1) {
#ifdef __APPLE__
/* handle weak-linking on Mac OS X 10.3 */
if (fstatvfs == NULL) {
fd_specified("statvfs", path->fd);
return NULL;
}
#endif
result = fstatvfs(path->fd, &st);
}
else
#endif
result = statvfs(path->narrow, &st);
Py_END_ALLOW_THREADS
if (result) {
return path_error(path);
}
return _pystatvfs_fromstructstatvfs(st);
}
#endif /* defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) */
#ifdef MS_WINDOWS
/*[clinic input]
os._getdiskusage
path: Py_UNICODE
Return disk usage statistics about the given path as a (total, free) tuple.
[clinic start generated code]*/
PyDoc_STRVAR(os__getdiskusage__doc__,
"_getdiskusage($module, /, path)\n"
"--\n"
"\n"
"Return disk usage statistics about the given path as a (total, free) tuple.");
#define OS__GETDISKUSAGE_METHODDEF \
{"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__},
static PyObject *
os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path);
static PyObject *
os__getdiskusage(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", NULL};
Py_UNICODE *path;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"u:_getdiskusage", _keywords,
&path))
goto exit;
return_value = os__getdiskusage_impl(module, path);
exit:
return return_value;
}
static PyObject *
os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path)
/*[clinic end generated code: output=054c972179b13708 input=6458133aed893c78]*/
{
BOOL retval;
ULARGE_INTEGER _, total, free;
Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceExW(path, &_, &total, &free);
Py_END_ALLOW_THREADS
if (retval == 0)
return PyErr_SetFromWindowsErr(0);
return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
}
#endif /* MS_WINDOWS */
/* This is used for fpathconf(), pathconf(), confstr() and sysconf().
* It maps strings representing configuration variable names to
* integer values, allowing those functions to be called with the
* magic names instead of polluting the module's namespace with tons of
* rarely-used constants. There are three separate tables that use
* these definitions.
*
* This code is always included, even if none of the interfaces that
* need it are included. The #if hackery needed to avoid it would be
* sufficiently pervasive that it's not worth the loss of readability.
*/
struct constdef {
char *name;
long value;
};
static int
conv_confname(PyObject *arg, int *valuep, struct constdef *table,
size_t tablesize)
{
if (PyLong_Check(arg)) {
*valuep = PyLong_AS_LONG(arg);
return 1;
}
else {
/* look up the value in the table using a binary search */
size_t lo = 0;
size_t mid;
size_t hi = tablesize;
int cmp;
const char *confname;
if (!PyUnicode_Check(arg)) {
PyErr_SetString(PyExc_TypeError,
"configuration names must be strings or integers");
return 0;
}
confname = _PyUnicode_AsString(arg);
if (confname == NULL)
return 0;
while (lo < hi) {
mid = (lo + hi) / 2;
cmp = strcmp(confname, table[mid].name);
if (cmp < 0)
hi = mid;
else if (cmp > 0)
lo = mid + 1;
else {
*valuep = table[mid].value;
return 1;
}
}
PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
return 0;
}
}
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
static struct constdef posix_constants_pathconf[] = {
#ifdef _PC_ABI_AIO_XFER_MAX
{"PC_ABI_AIO_XFER_MAX", _PC_ABI_AIO_XFER_MAX},
#endif
#ifdef _PC_ABI_ASYNC_IO
{"PC_ABI_ASYNC_IO", _PC_ABI_ASYNC_IO},
#endif
#ifdef _PC_ASYNC_IO
{"PC_ASYNC_IO", _PC_ASYNC_IO},
#endif
#ifdef _PC_CHOWN_RESTRICTED
{"PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED},
#endif
#ifdef _PC_FILESIZEBITS
{"PC_FILESIZEBITS", _PC_FILESIZEBITS},
#endif
#ifdef _PC_LAST
{"PC_LAST", _PC_LAST},
#endif
#ifdef _PC_LINK_MAX
{"PC_LINK_MAX", _PC_LINK_MAX},
#endif
#ifdef _PC_MAX_CANON
{"PC_MAX_CANON", _PC_MAX_CANON},
#endif
#ifdef _PC_MAX_INPUT
{"PC_MAX_INPUT", _PC_MAX_INPUT},
#endif
#ifdef _PC_NAME_MAX
{"PC_NAME_MAX", _PC_NAME_MAX},
#endif
#ifdef _PC_NO_TRUNC
{"PC_NO_TRUNC", _PC_NO_TRUNC},
#endif
#ifdef _PC_PATH_MAX
{"PC_PATH_MAX", _PC_PATH_MAX},
#endif
#ifdef _PC_PIPE_BUF
{"PC_PIPE_BUF", _PC_PIPE_BUF},
#endif
#ifdef _PC_PRIO_IO
{"PC_PRIO_IO", _PC_PRIO_IO},
#endif
#ifdef _PC_SOCK_MAXBUF
{"PC_SOCK_MAXBUF", _PC_SOCK_MAXBUF},
#endif
#ifdef _PC_SYNC_IO
{"PC_SYNC_IO", _PC_SYNC_IO},
#endif
#ifdef _PC_VDISABLE
{"PC_VDISABLE", _PC_VDISABLE},
#endif
#ifdef _PC_ACL_ENABLED
{"PC_ACL_ENABLED", _PC_ACL_ENABLED},
#endif
#ifdef _PC_MIN_HOLE_SIZE
{"PC_MIN_HOLE_SIZE", _PC_MIN_HOLE_SIZE},
#endif
#ifdef _PC_ALLOC_SIZE_MIN
{"PC_ALLOC_SIZE_MIN", _PC_ALLOC_SIZE_MIN},
#endif
#ifdef _PC_REC_INCR_XFER_SIZE
{"PC_REC_INCR_XFER_SIZE", _PC_REC_INCR_XFER_SIZE},
#endif
#ifdef _PC_REC_MAX_XFER_SIZE
{"PC_REC_MAX_XFER_SIZE", _PC_REC_MAX_XFER_SIZE},
#endif
#ifdef _PC_REC_MIN_XFER_SIZE
{"PC_REC_MIN_XFER_SIZE", _PC_REC_MIN_XFER_SIZE},
#endif
#ifdef _PC_REC_XFER_ALIGN
{"PC_REC_XFER_ALIGN", _PC_REC_XFER_ALIGN},
#endif
#ifdef _PC_SYMLINK_MAX
{"PC_SYMLINK_MAX", _PC_SYMLINK_MAX},
#endif
#ifdef _PC_XATTR_ENABLED
{"PC_XATTR_ENABLED", _PC_XATTR_ENABLED},
#endif
#ifdef _PC_XATTR_EXISTS
{"PC_XATTR_EXISTS", _PC_XATTR_EXISTS},
#endif
#ifdef _PC_TIMESTAMP_RESOLUTION
{"PC_TIMESTAMP_RESOLUTION", _PC_TIMESTAMP_RESOLUTION},
#endif
};
static int
conv_path_confname(PyObject *arg, int *valuep)
{
return conv_confname(arg, valuep, posix_constants_pathconf,
sizeof(posix_constants_pathconf)
/ sizeof(struct constdef));
}
#endif
#ifdef HAVE_FPATHCONF
/*[clinic input]
os.fpathconf -> long
fd: int
name: path_confname
/
Return the configuration limit name for the file descriptor fd.
If there is no limit, return -1.
[clinic start generated code]*/
PyDoc_STRVAR(os_fpathconf__doc__,
"fpathconf($module, fd, name, /)\n"
"--\n"
"\n"
"Return the configuration limit name for the file descriptor fd.\n"
"\n"
"If there is no limit, return -1.");
#define OS_FPATHCONF_METHODDEF \
{"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
static long
os_fpathconf_impl(PyModuleDef *module, int fd, int name);
static PyObject *
os_fpathconf(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int name;
long _return_value;
if (!PyArg_ParseTuple(args,
"iO&:fpathconf",
&fd, conv_path_confname, &name))
goto exit;
_return_value = os_fpathconf_impl(module, fd, name);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong(_return_value);
exit:
return return_value;
}
static long
os_fpathconf_impl(PyModuleDef *module, int fd, int name)
/*[clinic end generated code: output=3bf04b40e0523a8c input=5942a024d3777810]*/
{
long limit;
errno = 0;
limit = fpathconf(fd, name);
if (limit == -1 && errno != 0)
posix_error();
return limit;
}
#endif /* HAVE_FPATHCONF */
#ifdef HAVE_PATHCONF
/*[clinic input]
os.pathconf -> long
path: path_t(allow_fd='PATH_HAVE_FPATHCONF')
name: path_confname
Return the configuration limit name for the file or directory path.
If there is no limit, return -1.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
[clinic start generated code]*/
PyDoc_STRVAR(os_pathconf__doc__,
"pathconf($module, /, path, name)\n"
"--\n"
"\n"
"Return the configuration limit name for the file or directory path.\n"
"\n"
"If there is no limit, return -1.\n"
"On some platforms, path may also be specified as an open file descriptor.\n"
" If this functionality is unavailable, using it raises an exception.");
#define OS_PATHCONF_METHODDEF \
{"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__},
static long
os_pathconf_impl(PyModuleDef *module, path_t *path, int name);
static PyObject *
os_pathconf(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "name", NULL};
path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
int name;
long _return_value;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&:pathconf", _keywords,
path_converter, &path, conv_path_confname, &name))
goto exit;
_return_value = os_pathconf_impl(module, &path, name);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong(_return_value);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static long
os_pathconf_impl(PyModuleDef *module, path_t *path, int name)
/*[clinic end generated code: output=1a53e125b6cf63e4 input=bc3e2a985af27e5e]*/
{
long limit;
errno = 0;
#ifdef HAVE_FPATHCONF
if (path->fd != -1)
limit = fpathconf(path->fd, name);
else
#endif
limit = pathconf(path->narrow, name);
if (limit == -1 && errno != 0) {
if (errno == EINVAL)
/* could be a path or name problem */
posix_error();
else
path_error(path);
}
return limit;
}
#endif /* HAVE_PATHCONF */
#ifdef HAVE_CONFSTR
static struct constdef posix_constants_confstr[] = {
#ifdef _CS_ARCHITECTURE
{"CS_ARCHITECTURE", _CS_ARCHITECTURE},
#endif
#ifdef _CS_GNU_LIBC_VERSION
{"CS_GNU_LIBC_VERSION", _CS_GNU_LIBC_VERSION},
#endif
#ifdef _CS_GNU_LIBPTHREAD_VERSION
{"CS_GNU_LIBPTHREAD_VERSION", _CS_GNU_LIBPTHREAD_VERSION},
#endif
#ifdef _CS_HOSTNAME
{"CS_HOSTNAME", _CS_HOSTNAME},
#endif
#ifdef _CS_HW_PROVIDER
{"CS_HW_PROVIDER", _CS_HW_PROVIDER},
#endif
#ifdef _CS_HW_SERIAL
{"CS_HW_SERIAL", _CS_HW_SERIAL},
#endif
#ifdef _CS_INITTAB_NAME
{"CS_INITTAB_NAME", _CS_INITTAB_NAME},
#endif
#ifdef _CS_LFS64_CFLAGS
{"CS_LFS64_CFLAGS", _CS_LFS64_CFLAGS},
#endif
#ifdef _CS_LFS64_LDFLAGS
{"CS_LFS64_LDFLAGS", _CS_LFS64_LDFLAGS},
#endif
#ifdef _CS_LFS64_LIBS
{"CS_LFS64_LIBS", _CS_LFS64_LIBS},
#endif
#ifdef _CS_LFS64_LINTFLAGS
{"CS_LFS64_LINTFLAGS", _CS_LFS64_LINTFLAGS},
#endif
#ifdef _CS_LFS_CFLAGS
{"CS_LFS_CFLAGS", _CS_LFS_CFLAGS},
#endif
#ifdef _CS_LFS_LDFLAGS
{"CS_LFS_LDFLAGS", _CS_LFS_LDFLAGS},
#endif
#ifdef _CS_LFS_LIBS
{"CS_LFS_LIBS", _CS_LFS_LIBS},
#endif
#ifdef _CS_LFS_LINTFLAGS
{"CS_LFS_LINTFLAGS", _CS_LFS_LINTFLAGS},
#endif
#ifdef _CS_MACHINE
{"CS_MACHINE", _CS_MACHINE},
#endif
#ifdef _CS_PATH
{"CS_PATH", _CS_PATH},
#endif
#ifdef _CS_RELEASE
{"CS_RELEASE", _CS_RELEASE},
#endif
#ifdef _CS_SRPC_DOMAIN
{"CS_SRPC_DOMAIN", _CS_SRPC_DOMAIN},
#endif
#ifdef _CS_SYSNAME
{"CS_SYSNAME", _CS_SYSNAME},
#endif
#ifdef _CS_VERSION
{"CS_VERSION", _CS_VERSION},
#endif
#ifdef _CS_XBS5_ILP32_OFF32_CFLAGS
{"CS_XBS5_ILP32_OFF32_CFLAGS", _CS_XBS5_ILP32_OFF32_CFLAGS},
#endif
#ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS
{"CS_XBS5_ILP32_OFF32_LDFLAGS", _CS_XBS5_ILP32_OFF32_LDFLAGS},
#endif
#ifdef _CS_XBS5_ILP32_OFF32_LIBS
{"CS_XBS5_ILP32_OFF32_LIBS", _CS_XBS5_ILP32_OFF32_LIBS},
#endif
#ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS
{"CS_XBS5_ILP32_OFF32_LINTFLAGS", _CS_XBS5_ILP32_OFF32_LINTFLAGS},
#endif
#ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS
{"CS_XBS5_ILP32_OFFBIG_CFLAGS", _CS_XBS5_ILP32_OFFBIG_CFLAGS},
#endif
#ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS
{"CS_XBS5_ILP32_OFFBIG_LDFLAGS", _CS_XBS5_ILP32_OFFBIG_LDFLAGS},
#endif
#ifdef _CS_XBS5_ILP32_OFFBIG_LIBS
{"CS_XBS5_ILP32_OFFBIG_LIBS", _CS_XBS5_ILP32_OFFBIG_LIBS},
#endif
#ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
{"CS_XBS5_ILP32_OFFBIG_LINTFLAGS", _CS_XBS5_ILP32_OFFBIG_LINTFLAGS},
#endif
#ifdef _CS_XBS5_LP64_OFF64_CFLAGS
{"CS_XBS5_LP64_OFF64_CFLAGS", _CS_XBS5_LP64_OFF64_CFLAGS},
#endif
#ifdef _CS_XBS5_LP64_OFF64_LDFLAGS
{"CS_XBS5_LP64_OFF64_LDFLAGS", _CS_XBS5_LP64_OFF64_LDFLAGS},
#endif
#ifdef _CS_XBS5_LP64_OFF64_LIBS
{"CS_XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS},
#endif
#ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS
{"CS_XBS5_LP64_OFF64_LINTFLAGS", _CS_XBS5_LP64_OFF64_LINTFLAGS},
#endif
#ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS
{"CS_XBS5_LPBIG_OFFBIG_CFLAGS", _CS_XBS5_LPBIG_OFFBIG_CFLAGS},
#endif
#ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
{"CS_XBS5_LPBIG_OFFBIG_LDFLAGS", _CS_XBS5_LPBIG_OFFBIG_LDFLAGS},
#endif
#ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS
{"CS_XBS5_LPBIG_OFFBIG_LIBS", _CS_XBS5_LPBIG_OFFBIG_LIBS},
#endif
#ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
{"CS_XBS5_LPBIG_OFFBIG_LINTFLAGS", _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS},
#endif
#ifdef _MIPS_CS_AVAIL_PROCESSORS
{"MIPS_CS_AVAIL_PROCESSORS", _MIPS_CS_AVAIL_PROCESSORS},
#endif
#ifdef _MIPS_CS_BASE
{"MIPS_CS_BASE", _MIPS_CS_BASE},
#endif
#ifdef _MIPS_CS_HOSTID
{"MIPS_CS_HOSTID", _MIPS_CS_HOSTID},
#endif
#ifdef _MIPS_CS_HW_NAME
{"MIPS_CS_HW_NAME", _MIPS_CS_HW_NAME},
#endif
#ifdef _MIPS_CS_NUM_PROCESSORS
{"MIPS_CS_NUM_PROCESSORS", _MIPS_CS_NUM_PROCESSORS},
#endif
#ifdef _MIPS_CS_OSREL_MAJ
{"MIPS_CS_OSREL_MAJ", _MIPS_CS_OSREL_MAJ},
#endif
#ifdef _MIPS_CS_OSREL_MIN
{"MIPS_CS_OSREL_MIN", _MIPS_CS_OSREL_MIN},
#endif
#ifdef _MIPS_CS_OSREL_PATCH
{"MIPS_CS_OSREL_PATCH", _MIPS_CS_OSREL_PATCH},
#endif
#ifdef _MIPS_CS_OS_NAME
{"MIPS_CS_OS_NAME", _MIPS_CS_OS_NAME},
#endif
#ifdef _MIPS_CS_OS_PROVIDER
{"MIPS_CS_OS_PROVIDER", _MIPS_CS_OS_PROVIDER},
#endif
#ifdef _MIPS_CS_PROCESSORS
{"MIPS_CS_PROCESSORS", _MIPS_CS_PROCESSORS},
#endif
#ifdef _MIPS_CS_SERIAL
{"MIPS_CS_SERIAL", _MIPS_CS_SERIAL},
#endif
#ifdef _MIPS_CS_VENDOR
{"MIPS_CS_VENDOR", _MIPS_CS_VENDOR},
#endif
};
static int
conv_confstr_confname(PyObject *arg, int *valuep)
{
return conv_confname(arg, valuep, posix_constants_confstr,
sizeof(posix_constants_confstr)
/ sizeof(struct constdef));
}
/*[clinic input]
os.confstr
name: confstr_confname
/
Return a string-valued system configuration variable.
[clinic start generated code]*/
PyDoc_STRVAR(os_confstr__doc__,
"confstr($module, name, /)\n"
"--\n"
"\n"
"Return a string-valued system configuration variable.");
#define OS_CONFSTR_METHODDEF \
{"confstr", (PyCFunction)os_confstr, METH_VARARGS, os_confstr__doc__},
static PyObject *
os_confstr_impl(PyModuleDef *module, int name);
static PyObject *
os_confstr(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int name;
if (!PyArg_ParseTuple(args,
"O&:confstr",
conv_confstr_confname, &name))
goto exit;
return_value = os_confstr_impl(module, name);
exit:
return return_value;
}
static PyObject *
os_confstr_impl(PyModuleDef *module, int name)
/*[clinic end generated code: output=3f5e8aba9f8e3174 input=18fb4d0567242e65]*/
{
PyObject *result = NULL;
char buffer[255];
size_t len;
errno = 0;
len = confstr(name, buffer, sizeof(buffer));
if (len == 0) {
if (errno) {
posix_error();
return NULL;
}
else {
Py_RETURN_NONE;
}
}
if (len >= sizeof(buffer)) {
char *buf = PyMem_Malloc(len);
if (buf == NULL)
return PyErr_NoMemory();
confstr(name, buf, len);
result = PyUnicode_DecodeFSDefaultAndSize(buf, len-1);
PyMem_Free(buf);
}
else
result = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
return result;
}
#endif /* HAVE_CONFSTR */
#ifdef HAVE_SYSCONF
static struct constdef posix_constants_sysconf[] = {
#ifdef _SC_2_CHAR_TERM
{"SC_2_CHAR_TERM", _SC_2_CHAR_TERM},
#endif
#ifdef _SC_2_C_BIND
{"SC_2_C_BIND", _SC_2_C_BIND},
#endif
#ifdef _SC_2_C_DEV
{"SC_2_C_DEV", _SC_2_C_DEV},
#endif
#ifdef _SC_2_C_VERSION
{"SC_2_C_VERSION", _SC_2_C_VERSION},
#endif
#ifdef _SC_2_FORT_DEV
{"SC_2_FORT_DEV", _SC_2_FORT_DEV},
#endif
#ifdef _SC_2_FORT_RUN
{"SC_2_FORT_RUN", _SC_2_FORT_RUN},
#endif
#ifdef _SC_2_LOCALEDEF
{"SC_2_LOCALEDEF", _SC_2_LOCALEDEF},
#endif
#ifdef _SC_2_SW_DEV
{"SC_2_SW_DEV", _SC_2_SW_DEV},
#endif
#ifdef _SC_2_UPE
{"SC_2_UPE", _SC_2_UPE},
#endif
#ifdef _SC_2_VERSION
{"SC_2_VERSION", _SC_2_VERSION},
#endif
#ifdef _SC_ABI_ASYNCHRONOUS_IO
{"SC_ABI_ASYNCHRONOUS_IO", _SC_ABI_ASYNCHRONOUS_IO},
#endif
#ifdef _SC_ACL
{"SC_ACL", _SC_ACL},
#endif
#ifdef _SC_AIO_LISTIO_MAX
{"SC_AIO_LISTIO_MAX", _SC_AIO_LISTIO_MAX},
#endif
#ifdef _SC_AIO_MAX
{"SC_AIO_MAX", _SC_AIO_MAX},
#endif
#ifdef _SC_AIO_PRIO_DELTA_MAX
{"SC_AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX},
#endif
#ifdef _SC_ARG_MAX
{"SC_ARG_MAX", _SC_ARG_MAX},
#endif
#ifdef _SC_ASYNCHRONOUS_IO
{"SC_ASYNCHRONOUS_IO", _SC_ASYNCHRONOUS_IO},
#endif
#ifdef _SC_ATEXIT_MAX
{"SC_ATEXIT_MAX", _SC_ATEXIT_MAX},
#endif
#ifdef _SC_AUDIT
{"SC_AUDIT", _SC_AUDIT},
#endif
#ifdef _SC_AVPHYS_PAGES
{"SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES},
#endif
#ifdef _SC_BC_BASE_MAX
{"SC_BC_BASE_MAX", _SC_BC_BASE_MAX},
#endif
#ifdef _SC_BC_DIM_MAX
{"SC_BC_DIM_MAX", _SC_BC_DIM_MAX},
#endif
#ifdef _SC_BC_SCALE_MAX
{"SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX},
#endif
#ifdef _SC_BC_STRING_MAX
{"SC_BC_STRING_MAX", _SC_BC_STRING_MAX},
#endif
#ifdef _SC_CAP
{"SC_CAP", _SC_CAP},
#endif
#ifdef _SC_CHARCLASS_NAME_MAX
{"SC_CHARCLASS_NAME_MAX", _SC_CHARCLASS_NAME_MAX},
#endif
#ifdef _SC_CHAR_BIT
{"SC_CHAR_BIT", _SC_CHAR_BIT},
#endif
#ifdef _SC_CHAR_MAX
{"SC_CHAR_MAX", _SC_CHAR_MAX},
#endif
#ifdef _SC_CHAR_MIN
{"SC_CHAR_MIN", _SC_CHAR_MIN},
#endif
#ifdef _SC_CHILD_MAX
{"SC_CHILD_MAX", _SC_CHILD_MAX},
#endif
#ifdef _SC_CLK_TCK
{"SC_CLK_TCK", _SC_CLK_TCK},
#endif
#ifdef _SC_COHER_BLKSZ
{"SC_COHER_BLKSZ", _SC_COHER_BLKSZ},
#endif
#ifdef _SC_COLL_WEIGHTS_MAX
{"SC_COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX},
#endif
#ifdef _SC_DCACHE_ASSOC
{"SC_DCACHE_ASSOC", _SC_DCACHE_ASSOC},
#endif
#ifdef _SC_DCACHE_BLKSZ
{"SC_DCACHE_BLKSZ", _SC_DCACHE_BLKSZ},
#endif
#ifdef _SC_DCACHE_LINESZ
{"SC_DCACHE_LINESZ", _SC_DCACHE_LINESZ},
#endif
#ifdef _SC_DCACHE_SZ
{"SC_DCACHE_SZ", _SC_DCACHE_SZ},
#endif
#ifdef _SC_DCACHE_TBLKSZ
{"SC_DCACHE_TBLKSZ", _SC_DCACHE_TBLKSZ},
#endif
#ifdef _SC_DELAYTIMER_MAX
{"SC_DELAYTIMER_MAX", _SC_DELAYTIMER_MAX},
#endif
#ifdef _SC_EQUIV_CLASS_MAX
{"SC_EQUIV_CLASS_MAX", _SC_EQUIV_CLASS_MAX},
#endif
#ifdef _SC_EXPR_NEST_MAX
{"SC_EXPR_NEST_MAX", _SC_EXPR_NEST_MAX},
#endif
#ifdef _SC_FSYNC
{"SC_FSYNC", _SC_FSYNC},
#endif
#ifdef _SC_GETGR_R_SIZE_MAX
{"SC_GETGR_R_SIZE_MAX", _SC_GETGR_R_SIZE_MAX},
#endif
#ifdef _SC_GETPW_R_SIZE_MAX
{"SC_GETPW_R_SIZE_MAX", _SC_GETPW_R_SIZE_MAX},
#endif
#ifdef _SC_ICACHE_ASSOC
{"SC_ICACHE_ASSOC", _SC_ICACHE_ASSOC},
#endif
#ifdef _SC_ICACHE_BLKSZ
{"SC_ICACHE_BLKSZ", _SC_ICACHE_BLKSZ},
#endif
#ifdef _SC_ICACHE_LINESZ
{"SC_ICACHE_LINESZ", _SC_ICACHE_LINESZ},
#endif
#ifdef _SC_ICACHE_SZ
{"SC_ICACHE_SZ", _SC_ICACHE_SZ},
#endif
#ifdef _SC_INF
{"SC_INF", _SC_INF},
#endif
#ifdef _SC_INT_MAX
{"SC_INT_MAX", _SC_INT_MAX},
#endif
#ifdef _SC_INT_MIN
{"SC_INT_MIN", _SC_INT_MIN},
#endif
#ifdef _SC_IOV_MAX
{"SC_IOV_MAX", _SC_IOV_MAX},
#endif
#ifdef _SC_IP_SECOPTS
{"SC_IP_SECOPTS", _SC_IP_SECOPTS},
#endif
#ifdef _SC_JOB_CONTROL
{"SC_JOB_CONTROL", _SC_JOB_CONTROL},
#endif
#ifdef _SC_KERN_POINTERS
{"SC_KERN_POINTERS", _SC_KERN_POINTERS},
#endif
#ifdef _SC_KERN_SIM
{"SC_KERN_SIM", _SC_KERN_SIM},
#endif
#ifdef _SC_LINE_MAX
{"SC_LINE_MAX", _SC_LINE_MAX},
#endif
#ifdef _SC_LOGIN_NAME_MAX
{"SC_LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX},
#endif
#ifdef _SC_LOGNAME_MAX
{"SC_LOGNAME_MAX", _SC_LOGNAME_MAX},
#endif
#ifdef _SC_LONG_BIT
{"SC_LONG_BIT", _SC_LONG_BIT},
#endif
#ifdef _SC_MAC
{"SC_MAC", _SC_MAC},
#endif
#ifdef _SC_MAPPED_FILES
{"SC_MAPPED_FILES", _SC_MAPPED_FILES},
#endif
#ifdef _SC_MAXPID
{"SC_MAXPID", _SC_MAXPID},
#endif
#ifdef _SC_MB_LEN_MAX
{"SC_MB_LEN_MAX", _SC_MB_LEN_MAX},
#endif
#ifdef _SC_MEMLOCK
{"SC_MEMLOCK", _SC_MEMLOCK},
#endif
#ifdef _SC_MEMLOCK_RANGE
{"SC_MEMLOCK_RANGE", _SC_MEMLOCK_RANGE},
#endif
#ifdef _SC_MEMORY_PROTECTION
{"SC_MEMORY_PROTECTION", _SC_MEMORY_PROTECTION},
#endif
#ifdef _SC_MESSAGE_PASSING
{"SC_MESSAGE_PASSING", _SC_MESSAGE_PASSING},
#endif
#ifdef _SC_MMAP_FIXED_ALIGNMENT
{"SC_MMAP_FIXED_ALIGNMENT", _SC_MMAP_FIXED_ALIGNMENT},
#endif
#ifdef _SC_MQ_OPEN_MAX
{"SC_MQ_OPEN_MAX", _SC_MQ_OPEN_MAX},
#endif
#ifdef _SC_MQ_PRIO_MAX
{"SC_MQ_PRIO_MAX", _SC_MQ_PRIO_MAX},
#endif
#ifdef _SC_NACLS_MAX
{"SC_NACLS_MAX", _SC_NACLS_MAX},
#endif
#ifdef _SC_NGROUPS_MAX
{"SC_NGROUPS_MAX", _SC_NGROUPS_MAX},
#endif
#ifdef _SC_NL_ARGMAX
{"SC_NL_ARGMAX", _SC_NL_ARGMAX},
#endif
#ifdef _SC_NL_LANGMAX
{"SC_NL_LANGMAX", _SC_NL_LANGMAX},
#endif
#ifdef _SC_NL_MSGMAX
{"SC_NL_MSGMAX", _SC_NL_MSGMAX},
#endif
#ifdef _SC_NL_NMAX
{"SC_NL_NMAX", _SC_NL_NMAX},
#endif
#ifdef _SC_NL_SETMAX
{"SC_NL_SETMAX", _SC_NL_SETMAX},
#endif
#ifdef _SC_NL_TEXTMAX
{"SC_NL_TEXTMAX", _SC_NL_TEXTMAX},
#endif
#ifdef _SC_NPROCESSORS_CONF
{"SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF},
#endif
#ifdef _SC_NPROCESSORS_ONLN
{"SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN},
#endif
#ifdef _SC_NPROC_CONF
{"SC_NPROC_CONF", _SC_NPROC_CONF},
#endif
#ifdef _SC_NPROC_ONLN
{"SC_NPROC_ONLN", _SC_NPROC_ONLN},
#endif
#ifdef _SC_NZERO
{"SC_NZERO", _SC_NZERO},
#endif
#ifdef _SC_OPEN_MAX
{"SC_OPEN_MAX", _SC_OPEN_MAX},
#endif
#ifdef _SC_PAGESIZE
{"SC_PAGESIZE", _SC_PAGESIZE},
#endif
#ifdef _SC_PAGE_SIZE
{"SC_PAGE_SIZE", _SC_PAGE_SIZE},
#endif
#ifdef _SC_PASS_MAX
{"SC_PASS_MAX", _SC_PASS_MAX},
#endif
#ifdef _SC_PHYS_PAGES
{"SC_PHYS_PAGES", _SC_PHYS_PAGES},
#endif
#ifdef _SC_PII
{"SC_PII", _SC_PII},
#endif
#ifdef _SC_PII_INTERNET
{"SC_PII_INTERNET", _SC_PII_INTERNET},
#endif
#ifdef _SC_PII_INTERNET_DGRAM
{"SC_PII_INTERNET_DGRAM", _SC_PII_INTERNET_DGRAM},
#endif
#ifdef _SC_PII_INTERNET_STREAM
{"SC_PII_INTERNET_STREAM", _SC_PII_INTERNET_STREAM},
#endif
#ifdef _SC_PII_OSI
{"SC_PII_OSI", _SC_PII_OSI},
#endif
#ifdef _SC_PII_OSI_CLTS
{"SC_PII_OSI_CLTS", _SC_PII_OSI_CLTS},
#endif
#ifdef _SC_PII_OSI_COTS
{"SC_PII_OSI_COTS", _SC_PII_OSI_COTS},
#endif
#ifdef _SC_PII_OSI_M
{"SC_PII_OSI_M", _SC_PII_OSI_M},
#endif
#ifdef _SC_PII_SOCKET
{"SC_PII_SOCKET", _SC_PII_SOCKET},
#endif
#ifdef _SC_PII_XTI
{"SC_PII_XTI", _SC_PII_XTI},
#endif
#ifdef _SC_POLL
{"SC_POLL", _SC_POLL},
#endif
#ifdef _SC_PRIORITIZED_IO
{"SC_PRIORITIZED_IO", _SC_PRIORITIZED_IO},
#endif
#ifdef _SC_PRIORITY_SCHEDULING
{"SC_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING},
#endif
#ifdef _SC_REALTIME_SIGNALS
{"SC_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS},
#endif
#ifdef _SC_RE_DUP_MAX
{"SC_RE_DUP_MAX", _SC_RE_DUP_MAX},
#endif
#ifdef _SC_RTSIG_MAX
{"SC_RTSIG_MAX", _SC_RTSIG_MAX},
#endif
#ifdef _SC_SAVED_IDS
{"SC_SAVED_IDS", _SC_SAVED_IDS},
#endif
#ifdef _SC_SCHAR_MAX
{"SC_SCHAR_MAX", _SC_SCHAR_MAX},
#endif
#ifdef _SC_SCHAR_MIN
{"SC_SCHAR_MIN", _SC_SCHAR_MIN},
#endif
#ifdef _SC_SELECT
{"SC_SELECT", _SC_SELECT},
#endif
#ifdef _SC_SEMAPHORES
{"SC_SEMAPHORES", _SC_SEMAPHORES},
#endif
#ifdef _SC_SEM_NSEMS_MAX
{"SC_SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX},
#endif
#ifdef _SC_SEM_VALUE_MAX
{"SC_SEM_VALUE_MAX", _SC_SEM_VALUE_MAX},
#endif
#ifdef _SC_SHARED_MEMORY_OBJECTS
{"SC_SHARED_MEMORY_OBJECTS", _SC_SHARED_MEMORY_OBJECTS},
#endif
#ifdef _SC_SHRT_MAX
{"SC_SHRT_MAX", _SC_SHRT_MAX},
#endif
#ifdef _SC_SHRT_MIN
{"SC_SHRT_MIN", _SC_SHRT_MIN},
#endif
#ifdef _SC_SIGQUEUE_MAX
{"SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX},
#endif
#ifdef _SC_SIGRT_MAX
{"SC_SIGRT_MAX", _SC_SIGRT_MAX},
#endif
#ifdef _SC_SIGRT_MIN
{"SC_SIGRT_MIN", _SC_SIGRT_MIN},
#endif
#ifdef _SC_SOFTPOWER
{"SC_SOFTPOWER", _SC_SOFTPOWER},
#endif
#ifdef _SC_SPLIT_CACHE
{"SC_SPLIT_CACHE", _SC_SPLIT_CACHE},
#endif
#ifdef _SC_SSIZE_MAX
{"SC_SSIZE_MAX", _SC_SSIZE_MAX},
#endif
#ifdef _SC_STACK_PROT
{"SC_STACK_PROT", _SC_STACK_PROT},
#endif
#ifdef _SC_STREAM_MAX
{"SC_STREAM_MAX", _SC_STREAM_MAX},
#endif
#ifdef _SC_SYNCHRONIZED_IO
{"SC_SYNCHRONIZED_IO", _SC_SYNCHRONIZED_IO},
#endif
#ifdef _SC_THREADS
{"SC_THREADS", _SC_THREADS},
#endif
#ifdef _SC_THREAD_ATTR_STACKADDR
{"SC_THREAD_ATTR_STACKADDR", _SC_THREAD_ATTR_STACKADDR},
#endif
#ifdef _SC_THREAD_ATTR_STACKSIZE
{"SC_THREAD_ATTR_STACKSIZE", _SC_THREAD_ATTR_STACKSIZE},
#endif
#ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS
{"SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS},
#endif
#ifdef _SC_THREAD_KEYS_MAX
{"SC_THREAD_KEYS_MAX", _SC_THREAD_KEYS_MAX},
#endif
#ifdef _SC_THREAD_PRIORITY_SCHEDULING
{"SC_THREAD_PRIORITY_SCHEDULING", _SC_THREAD_PRIORITY_SCHEDULING},
#endif
#ifdef _SC_THREAD_PRIO_INHERIT
{"SC_THREAD_PRIO_INHERIT", _SC_THREAD_PRIO_INHERIT},
#endif
#ifdef _SC_THREAD_PRIO_PROTECT
{"SC_THREAD_PRIO_PROTECT", _SC_THREAD_PRIO_PROTECT},
#endif
#ifdef _SC_THREAD_PROCESS_SHARED
{"SC_THREAD_PROCESS_SHARED", _SC_THREAD_PROCESS_SHARED},
#endif
#ifdef _SC_THREAD_SAFE_FUNCTIONS
{"SC_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS},
#endif
#ifdef _SC_THREAD_STACK_MIN
{"SC_THREAD_STACK_MIN", _SC_THREAD_STACK_MIN},
#endif
#ifdef _SC_THREAD_THREADS_MAX
{"SC_THREAD_THREADS_MAX", _SC_THREAD_THREADS_MAX},
#endif
#ifdef _SC_TIMERS
{"SC_TIMERS", _SC_TIMERS},
#endif
#ifdef _SC_TIMER_MAX
{"SC_TIMER_MAX", _SC_TIMER_MAX},
#endif
#ifdef _SC_TTY_NAME_MAX
{"SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX},
#endif
#ifdef _SC_TZNAME_MAX
{"SC_TZNAME_MAX", _SC_TZNAME_MAX},
#endif
#ifdef _SC_T_IOV_MAX
{"SC_T_IOV_MAX", _SC_T_IOV_MAX},
#endif
#ifdef _SC_UCHAR_MAX
{"SC_UCHAR_MAX", _SC_UCHAR_MAX},
#endif
#ifdef _SC_UINT_MAX
{"SC_UINT_MAX", _SC_UINT_MAX},
#endif
#ifdef _SC_UIO_MAXIOV
{"SC_UIO_MAXIOV", _SC_UIO_MAXIOV},
#endif
#ifdef _SC_ULONG_MAX
{"SC_ULONG_MAX", _SC_ULONG_MAX},
#endif
#ifdef _SC_USHRT_MAX
{"SC_USHRT_MAX", _SC_USHRT_MAX},
#endif
#ifdef _SC_VERSION
{"SC_VERSION", _SC_VERSION},
#endif
#ifdef _SC_WORD_BIT
{"SC_WORD_BIT", _SC_WORD_BIT},
#endif
#ifdef _SC_XBS5_ILP32_OFF32
{"SC_XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32},
#endif
#ifdef _SC_XBS5_ILP32_OFFBIG
{"SC_XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG},
#endif
#ifdef _SC_XBS5_LP64_OFF64
{"SC_XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64},
#endif
#ifdef _SC_XBS5_LPBIG_OFFBIG
{"SC_XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG},
#endif
#ifdef _SC_XOPEN_CRYPT
{"SC_XOPEN_CRYPT", _SC_XOPEN_CRYPT},
#endif
#ifdef _SC_XOPEN_ENH_I18N
{"SC_XOPEN_ENH_I18N", _SC_XOPEN_ENH_I18N},
#endif
#ifdef _SC_XOPEN_LEGACY
{"SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY},
#endif
#ifdef _SC_XOPEN_REALTIME
{"SC_XOPEN_REALTIME", _SC_XOPEN_REALTIME},
#endif
#ifdef _SC_XOPEN_REALTIME_THREADS
{"SC_XOPEN_REALTIME_THREADS", _SC_XOPEN_REALTIME_THREADS},
#endif
#ifdef _SC_XOPEN_SHM
{"SC_XOPEN_SHM", _SC_XOPEN_SHM},
#endif
#ifdef _SC_XOPEN_UNIX
{"SC_XOPEN_UNIX", _SC_XOPEN_UNIX},
#endif
#ifdef _SC_XOPEN_VERSION
{"SC_XOPEN_VERSION", _SC_XOPEN_VERSION},
#endif
#ifdef _SC_XOPEN_XCU_VERSION
{"SC_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION},
#endif
#ifdef _SC_XOPEN_XPG2
{"SC_XOPEN_XPG2", _SC_XOPEN_XPG2},
#endif
#ifdef _SC_XOPEN_XPG3
{"SC_XOPEN_XPG3", _SC_XOPEN_XPG3},
#endif
#ifdef _SC_XOPEN_XPG4
{"SC_XOPEN_XPG4", _SC_XOPEN_XPG4},
#endif
};
static int
conv_sysconf_confname(PyObject *arg, int *valuep)
{
return conv_confname(arg, valuep, posix_constants_sysconf,
sizeof(posix_constants_sysconf)
/ sizeof(struct constdef));
}
/*[clinic input]
os.sysconf -> long
name: sysconf_confname
/
Return an integer-valued system configuration variable.
[clinic start generated code]*/
PyDoc_STRVAR(os_sysconf__doc__,
"sysconf($module, name, /)\n"
"--\n"
"\n"
"Return an integer-valued system configuration variable.");
#define OS_SYSCONF_METHODDEF \
{"sysconf", (PyCFunction)os_sysconf, METH_VARARGS, os_sysconf__doc__},
static long
os_sysconf_impl(PyModuleDef *module, int name);
static PyObject *
os_sysconf(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int name;
long _return_value;
if (!PyArg_ParseTuple(args,
"O&:sysconf",
conv_sysconf_confname, &name))
goto exit;
_return_value = os_sysconf_impl(module, name);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong(_return_value);
exit:
return return_value;
}
static long
os_sysconf_impl(PyModuleDef *module, int name)
/*[clinic end generated code: output=7b06dfdc472431e4 input=279e3430a33f29e4]*/
{
long value;
errno = 0;
value = sysconf(name);
if (value == -1 && errno != 0)
posix_error();
return value;
}
#endif /* HAVE_SYSCONF */
/* This code is used to ensure that the tables of configuration value names
* are in sorted order as required by conv_confname(), and also to build the
* the exported dictionaries that are used to publish information about the
* names available on the host platform.
*
* Sorting the table at runtime ensures that the table is properly ordered
* when used, even for platforms we're not able to test on. It also makes
* it easier to add additional entries to the tables.
*/
static int
cmp_constdefs(const void *v1, const void *v2)
{
const struct constdef *c1 =
(const struct constdef *) v1;
const struct constdef *c2 =
(const struct constdef *) v2;
return strcmp(c1->name, c2->name);
}
static int
setup_confname_table(struct constdef *table, size_t tablesize,
char *tablename, PyObject *module)
{
PyObject *d = NULL;
size_t i;
qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
d = PyDict_New();
if (d == NULL)
return -1;
for (i=0; i < tablesize; ++i) {
PyObject *o = PyLong_FromLong(table[i].value);
if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
Py_XDECREF(o);
Py_DECREF(d);
return -1;
}
Py_DECREF(o);
}
return PyModule_AddObject(module, tablename, d);
}
/* Return -1 on failure, 0 on success. */
static int
setup_confname_tables(PyObject *module)
{
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
if (setup_confname_table(posix_constants_pathconf,
sizeof(posix_constants_pathconf)
/ sizeof(struct constdef),
"pathconf_names", module))
return -1;
#endif
#ifdef HAVE_CONFSTR
if (setup_confname_table(posix_constants_confstr,
sizeof(posix_constants_confstr)
/ sizeof(struct constdef),
"confstr_names", module))
return -1;
#endif
#ifdef HAVE_SYSCONF
if (setup_confname_table(posix_constants_sysconf,
sizeof(posix_constants_sysconf)
/ sizeof(struct constdef),
"sysconf_names", module))
return -1;
#endif
return 0;
}
/*[clinic input]
os.abort
Abort the interpreter immediately.
This function 'dumps core' or otherwise fails in the hardest way possible
on the hosting operating system. This function never returns.
[clinic start generated code]*/
PyDoc_STRVAR(os_abort__doc__,
"abort($module, /)\n"
"--\n"
"\n"
"Abort the interpreter immediately.\n"
"\n"
"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
"on the hosting operating system. This function never returns.");
#define OS_ABORT_METHODDEF \
{"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
static PyObject *
os_abort_impl(PyModuleDef *module);
static PyObject *
os_abort(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_abort_impl(module);
}
static PyObject *
os_abort_impl(PyModuleDef *module)
/*[clinic end generated code: output=cded2cc8c5453d3a input=cf2c7d98bc504047]*/
{
abort();
/*NOTREACHED*/
Py_FatalError("abort() called from Python code didn't abort!");
return NULL;
}
#ifdef MS_WINDOWS
/* AC 3.5: change to path_t? but that might change exceptions */
PyDoc_STRVAR(win32_startfile__doc__,
"startfile(filepath [, operation])\n\
\n\
Start a file with its associated application.\n\
\n\
When \"operation\" is not specified or \"open\", this acts like\n\
double-clicking the file in Explorer, or giving the file name as an\n\
argument to the DOS \"start\" command: the file is opened with whatever\n\
application (if any) its extension is associated.\n\
When another \"operation\" is given, it specifies what should be done with\n\
the file. A typical operation is \"print\".\n\
\n\
startfile returns as soon as the associated application is launched.\n\
There is no option to wait for the application to close, and no way\n\
to retrieve the application's exit status.\n\
\n\
The filepath is relative to the current directory. If you want to use\n\
an absolute path, make sure the first character is not a slash (\"/\");\n\
the underlying Win32 ShellExecute function doesn't work if it is.");
static PyObject *
win32_startfile(PyObject *self, PyObject *args)
{
PyObject *ofilepath;
char *filepath;
char *operation = NULL;
wchar_t *wpath, *woperation;
HINSTANCE rc;
PyObject *unipath, *uoperation = NULL;
if (!PyArg_ParseTuple(args, "U|s:startfile",
&unipath, &operation)) {
PyErr_Clear();
goto normal;
}
if (operation) {
uoperation = PyUnicode_DecodeASCII(operation,
strlen(operation), NULL);
if (!uoperation) {
PyErr_Clear();
operation = NULL;
goto normal;
}
}
wpath = PyUnicode_AsUnicode(unipath);
if (wpath == NULL)
goto normal;
if (uoperation) {
woperation = PyUnicode_AsUnicode(uoperation);
if (woperation == NULL)
goto normal;
}
else
woperation = NULL;
Py_BEGIN_ALLOW_THREADS
rc = ShellExecuteW((HWND)0, woperation, wpath,
NULL, NULL, SW_SHOWNORMAL);
Py_END_ALLOW_THREADS
Py_XDECREF(uoperation);
if (rc <= (HINSTANCE)32) {
win32_error_object("startfile", unipath);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
normal:
if (!PyArg_ParseTuple(args, "O&|s:startfile",
PyUnicode_FSConverter, &ofilepath,
&operation))
return NULL;
if (win32_warn_bytes_api()) {
Py_DECREF(ofilepath);
return NULL;
}
filepath = PyBytes_AsString(ofilepath);
Py_BEGIN_ALLOW_THREADS
rc = ShellExecute((HWND)0, operation, filepath,
NULL, NULL, SW_SHOWNORMAL);
Py_END_ALLOW_THREADS
if (rc <= (HINSTANCE)32) {
PyObject *errval = win32_error("startfile", filepath);
Py_DECREF(ofilepath);
return errval;
}
Py_DECREF(ofilepath);
Py_INCREF(Py_None);
return Py_None;
}
#endif /* MS_WINDOWS */
#ifdef HAVE_GETLOADAVG
/*[clinic input]
os.getloadavg
Return average recent system load information.
Return the number of processes in the system run queue averaged over
the last 1, 5, and 15 minutes as a tuple of three floats.
Raises OSError if the load average was unobtainable.
[clinic start generated code]*/
PyDoc_STRVAR(os_getloadavg__doc__,
"getloadavg($module, /)\n"
"--\n"
"\n"
"Return average recent system load information.\n"
"\n"
"Return the number of processes in the system run queue averaged over\n"
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
"Raises OSError if the load average was unobtainable.");
#define OS_GETLOADAVG_METHODDEF \
{"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
static PyObject *
os_getloadavg_impl(PyModuleDef *module);
static PyObject *
os_getloadavg(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getloadavg_impl(module);
}
static PyObject *
os_getloadavg_impl(PyModuleDef *module)
/*[clinic end generated code: output=67593a92457d55af input=3d6d826b76d8a34e]*/
{
double loadavg[3];
if (getloadavg(loadavg, 3)!=3) {
PyErr_SetString(PyExc_OSError, "Load averages are unobtainable");
return NULL;
} else
return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]);
}
#endif /* HAVE_GETLOADAVG */
/*[clinic input]
os.device_encoding
fd: int
Return a string describing the encoding of a terminal's file descriptor.
The file descriptor must be attached to a terminal.
If the device is not a terminal, return None.
[clinic start generated code]*/
PyDoc_STRVAR(os_device_encoding__doc__,
"device_encoding($module, /, fd)\n"
"--\n"
"\n"
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
"\n"
"The file descriptor must be attached to a terminal.\n"
"If the device is not a terminal, return None.");
#define OS_DEVICE_ENCODING_METHODDEF \
{"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__},
static PyObject *
os_device_encoding_impl(PyModuleDef *module, int fd);
static PyObject *
os_device_encoding(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"fd", NULL};
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:device_encoding", _keywords,
&fd))
goto exit;
return_value = os_device_encoding_impl(module, fd);
exit:
return return_value;
}
static PyObject *
os_device_encoding_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=e9f8274d42f5cce3 input=9e1d4a42b66df312]*/
{
return _Py_device_encoding(fd);
}
#ifdef HAVE_SETRESUID
/*[clinic input]
os.setresuid
ruid: uid_t
euid: uid_t
suid: uid_t
/
Set the current process's real, effective, and saved user ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_setresuid__doc__,
"setresuid($module, ruid, euid, suid, /)\n"
"--\n"
"\n"
"Set the current process\'s real, effective, and saved user ids.");
#define OS_SETRESUID_METHODDEF \
{"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
static PyObject *
os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid);
static PyObject *
os_setresuid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
uid_t ruid;
uid_t euid;
uid_t suid;
if (!PyArg_ParseTuple(args,
"O&O&O&:setresuid",
_Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid))
goto exit;
return_value = os_setresuid_impl(module, ruid, euid, suid);
exit:
return return_value;
}
static PyObject *
os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid)
/*[clinic end generated code: output=2e3457cfe7cd1f94 input=9e33cb79a82792f3]*/
{
if (setresuid(ruid, euid, suid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETRESUID */
#ifdef HAVE_SETRESGID
/*[clinic input]
os.setresgid
rgid: gid_t
egid: gid_t
sgid: gid_t
/
Set the current process's real, effective, and saved group ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_setresgid__doc__,
"setresgid($module, rgid, egid, sgid, /)\n"
"--\n"
"\n"
"Set the current process\'s real, effective, and saved group ids.");
#define OS_SETRESGID_METHODDEF \
{"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
static PyObject *
os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid);
static PyObject *
os_setresgid(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
gid_t rgid;
gid_t egid;
gid_t sgid;
if (!PyArg_ParseTuple(args,
"O&O&O&:setresgid",
_Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid))
goto exit;
return_value = os_setresgid_impl(module, rgid, egid, sgid);
exit:
return return_value;
}
static PyObject *
os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid)
/*[clinic end generated code: output=8a7ee6c1f2482362 input=33e9e0785ef426b1]*/
{
if (setresgid(rgid, egid, sgid) < 0)
return posix_error();
Py_RETURN_NONE;
}
#endif /* HAVE_SETRESGID */
#ifdef HAVE_GETRESUID
/*[clinic input]
os.getresuid
Return a tuple of the current process's real, effective, and saved user ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_getresuid__doc__,
"getresuid($module, /)\n"
"--\n"
"\n"
"Return a tuple of the current process\'s real, effective, and saved user ids.");
#define OS_GETRESUID_METHODDEF \
{"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
static PyObject *
os_getresuid_impl(PyModuleDef *module);
static PyObject *
os_getresuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getresuid_impl(module);
}
static PyObject *
os_getresuid_impl(PyModuleDef *module)
/*[clinic end generated code: output=d0786686a6ef1320 input=41ccfa8e1f6517ad]*/
{
uid_t ruid, euid, suid;
if (getresuid(&ruid, &euid, &suid) < 0)
return posix_error();
return Py_BuildValue("(NNN)", _PyLong_FromUid(ruid),
_PyLong_FromUid(euid),
_PyLong_FromUid(suid));
}
#endif /* HAVE_GETRESUID */
#ifdef HAVE_GETRESGID
/*[clinic input]
os.getresgid
Return a tuple of the current process's real, effective, and saved group ids.
[clinic start generated code]*/
PyDoc_STRVAR(os_getresgid__doc__,
"getresgid($module, /)\n"
"--\n"
"\n"
"Return a tuple of the current process\'s real, effective, and saved group ids.");
#define OS_GETRESGID_METHODDEF \
{"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
static PyObject *
os_getresgid_impl(PyModuleDef *module);
static PyObject *
os_getresgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_getresgid_impl(module);
}
static PyObject *
os_getresgid_impl(PyModuleDef *module)
/*[clinic end generated code: output=05249ac795fa759f input=517e68db9ca32df6]*/
{
gid_t rgid, egid, sgid;
if (getresgid(&rgid, &egid, &sgid) < 0)
return posix_error();
return Py_BuildValue("(NNN)", _PyLong_FromGid(rgid),
_PyLong_FromGid(egid),
_PyLong_FromGid(sgid));
}
#endif /* HAVE_GETRESGID */
#ifdef USE_XATTRS
/*[clinic input]
os.getxattr
path: path_t(allow_fd=True)
attribute: path_t
*
follow_symlinks: bool = True
Return the value of extended attribute attribute on path.
path may be either a string or an open file descriptor.
If follow_symlinks is False, and the last element of the path is a symbolic
link, getxattr will examine the symbolic link itself instead of the file
the link points to.
[clinic start generated code]*/
PyDoc_STRVAR(os_getxattr__doc__,
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
"--\n"
"\n"
"Return the value of extended attribute attribute on path.\n"
"\n"
"path may be either a string or an open file descriptor.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, getxattr will examine the symbolic link itself instead of the file\n"
" the link points to.");
#define OS_GETXATTR_METHODDEF \
{"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__},
static PyObject *
os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks);
static PyObject *
os_getxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|$p:getxattr", _keywords,
path_converter, &path, path_converter, &attribute, &follow_symlinks))
goto exit;
return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
/* Cleanup for attribute */
path_cleanup(&attribute);
return return_value;
}
static PyObject *
os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks)
/*[clinic end generated code: output=bbc9454fe2b9ea86 input=8c8ea3bab78d89c2]*/
{
Py_ssize_t i;
PyObject *buffer = NULL;
if (fd_and_follow_symlinks_invalid("getxattr", path->fd, follow_symlinks))
return NULL;
for (i = 0; ; i++) {
void *ptr;
ssize_t result;
static Py_ssize_t buffer_sizes[] = {128, XATTR_SIZE_MAX, 0};
Py_ssize_t buffer_size = buffer_sizes[i];
if (!buffer_size) {
path_error(path);
return NULL;
}
buffer = PyBytes_FromStringAndSize(NULL, buffer_size);
if (!buffer)
return NULL;
ptr = PyBytes_AS_STRING(buffer);
Py_BEGIN_ALLOW_THREADS;
if (path->fd >= 0)
result = fgetxattr(path->fd, attribute->narrow, ptr, buffer_size);
else if (follow_symlinks)
result = getxattr(path->narrow, attribute->narrow, ptr, buffer_size);
else
result = lgetxattr(path->narrow, attribute->narrow, ptr, buffer_size);
Py_END_ALLOW_THREADS;
if (result < 0) {
Py_DECREF(buffer);
if (errno == ERANGE)
continue;
path_error(path);
return NULL;
}
if (result != buffer_size) {
/* Can only shrink. */
_PyBytes_Resize(&buffer, result);
}
break;
}
return buffer;
}
/*[clinic input]
os.setxattr
path: path_t(allow_fd=True)
attribute: path_t
value: Py_buffer
flags: int = 0
*
follow_symlinks: bool = True
Set extended attribute attribute on path to value.
path may be either a string or an open file descriptor.
If follow_symlinks is False, and the last element of the path is a symbolic
link, setxattr will modify the symbolic link itself instead of the file
the link points to.
[clinic start generated code]*/
PyDoc_STRVAR(os_setxattr__doc__,
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
" follow_symlinks=True)\n"
"--\n"
"\n"
"Set extended attribute attribute on path to value.\n"
"\n"
"path may be either a string or an open file descriptor.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, setxattr will modify the symbolic link itself instead of the file\n"
" the link points to.");
#define OS_SETXATTR_METHODDEF \
{"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__},
static PyObject *
os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, Py_buffer *value, int flags, int follow_symlinks);
static PyObject *
os_setxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
Py_buffer value = {NULL, NULL};
int flags = 0;
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&y*|i$p:setxattr", _keywords,
path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks))
goto exit;
return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
/* Cleanup for attribute */
path_cleanup(&attribute);
/* Cleanup for value */
if (value.obj)
PyBuffer_Release(&value);
return return_value;
}
static PyObject *
os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, Py_buffer *value, int flags, int follow_symlinks)
/*[clinic end generated code: output=2ff845d8e024b218 input=f0d26833992015c2]*/
{
ssize_t result;
if (fd_and_follow_symlinks_invalid("setxattr", path->fd, follow_symlinks))
return NULL;
Py_BEGIN_ALLOW_THREADS;
if (path->fd > -1)
result = fsetxattr(path->fd, attribute->narrow,
value->buf, value->len, flags);
else if (follow_symlinks)
result = setxattr(path->narrow, attribute->narrow,
value->buf, value->len, flags);
else
result = lsetxattr(path->narrow, attribute->narrow,
value->buf, value->len, flags);
Py_END_ALLOW_THREADS;
if (result) {
path_error(path);
return NULL;
}
Py_RETURN_NONE;
}
/*[clinic input]
os.removexattr
path: path_t(allow_fd=True)
attribute: path_t
*
follow_symlinks: bool = True
Remove extended attribute attribute on path.
path may be either a string or an open file descriptor.
If follow_symlinks is False, and the last element of the path is a symbolic
link, removexattr will modify the symbolic link itself instead of the file
the link points to.
[clinic start generated code]*/
PyDoc_STRVAR(os_removexattr__doc__,
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
"--\n"
"\n"
"Remove extended attribute attribute on path.\n"
"\n"
"path may be either a string or an open file descriptor.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, removexattr will modify the symbolic link itself instead of the file\n"
" the link points to.");
#define OS_REMOVEXATTR_METHODDEF \
{"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__},
static PyObject *
os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks);
static PyObject *
os_removexattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O&O&|$p:removexattr", _keywords,
path_converter, &path, path_converter, &attribute, &follow_symlinks))
goto exit;
return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
/* Cleanup for attribute */
path_cleanup(&attribute);
return return_value;
}
static PyObject *
os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks)
/*[clinic end generated code: output=8dfc715bf607c4cf input=cdb54834161e3329]*/
{
ssize_t result;
if (fd_and_follow_symlinks_invalid("removexattr", path->fd, follow_symlinks))
return NULL;
Py_BEGIN_ALLOW_THREADS;
if (path->fd > -1)
result = fremovexattr(path->fd, attribute->narrow);
else if (follow_symlinks)
result = removexattr(path->narrow, attribute->narrow);
else
result = lremovexattr(path->narrow, attribute->narrow);
Py_END_ALLOW_THREADS;
if (result) {
return path_error(path);
}
Py_RETURN_NONE;
}
/*[clinic input]
os.listxattr
path: path_t(allow_fd=True, nullable=True) = None
*
follow_symlinks: bool = True
Return a list of extended attributes on path.
path may be either None, a string, or an open file descriptor.
if path is None, listxattr will examine the current directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, listxattr will examine the symbolic link itself instead of the file
the link points to.
[clinic start generated code]*/
PyDoc_STRVAR(os_listxattr__doc__,
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
"--\n"
"\n"
"Return a list of extended attributes on path.\n"
"\n"
"path may be either None, a string, or an open file descriptor.\n"
"if path is None, listxattr will examine the current directory.\n"
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
" link, listxattr will examine the symbolic link itself instead of the file\n"
" the link points to.");
#define OS_LISTXATTR_METHODDEF \
{"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__},
static PyObject *
os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks);
static PyObject *
os_listxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "follow_symlinks", NULL};
path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
int follow_symlinks = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|O&$p:listxattr", _keywords,
path_converter, &path, &follow_symlinks))
goto exit;
return_value = os_listxattr_impl(module, &path, follow_symlinks);
exit:
/* Cleanup for path */
path_cleanup(&path);
return return_value;
}
static PyObject *
os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks)
/*[clinic end generated code: output=3104cafda1a3d887 input=08cca53ac0b07c13]*/
{
Py_ssize_t i;
PyObject *result = NULL;
const char *name;
char *buffer = NULL;
if (fd_and_follow_symlinks_invalid("listxattr", path->fd, follow_symlinks))
goto exit;
name = path->narrow ? path->narrow : ".";
for (i = 0; ; i++) {
char *start, *trace, *end;
ssize_t length;
static Py_ssize_t buffer_sizes[] = { 256, XATTR_LIST_MAX, 0 };
Py_ssize_t buffer_size = buffer_sizes[i];
if (!buffer_size) {
/* ERANGE */
path_error(path);
break;
}
buffer = PyMem_MALLOC(buffer_size);
if (!buffer) {
PyErr_NoMemory();
break;
}
Py_BEGIN_ALLOW_THREADS;
if (path->fd > -1)
length = flistxattr(path->fd, buffer, buffer_size);
else if (follow_symlinks)
length = listxattr(name, buffer, buffer_size);
else
length = llistxattr(name, buffer, buffer_size);
Py_END_ALLOW_THREADS;
if (length < 0) {
if (errno == ERANGE) {
PyMem_FREE(buffer);
buffer = NULL;
continue;
}
path_error(path);
break;
}
result = PyList_New(0);
if (!result) {
goto exit;
}
end = buffer + length;
for (trace = start = buffer; trace != end; trace++) {
if (!*trace) {
int error;
PyObject *attribute = PyUnicode_DecodeFSDefaultAndSize(start,
trace - start);
if (!attribute) {
Py_DECREF(result);
result = NULL;
goto exit;
}
error = PyList_Append(result, attribute);
Py_DECREF(attribute);
if (error) {
Py_DECREF(result);
result = NULL;
goto exit;
}
start = trace + 1;
}
}
break;
}
exit:
if (buffer)
PyMem_FREE(buffer);
return result;
}
#endif /* USE_XATTRS */
/*[clinic input]
os.urandom
size: Py_ssize_t
/
Return a bytes object containing random bytes suitable for cryptographic use.
[clinic start generated code]*/
PyDoc_STRVAR(os_urandom__doc__,
"urandom($module, size, /)\n"
"--\n"
"\n"
"Return a bytes object containing random bytes suitable for cryptographic use.");
#define OS_URANDOM_METHODDEF \
{"urandom", (PyCFunction)os_urandom, METH_VARARGS, os_urandom__doc__},
static PyObject *
os_urandom_impl(PyModuleDef *module, Py_ssize_t size);
static PyObject *
os_urandom(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t size;
if (!PyArg_ParseTuple(args,
"n:urandom",
&size))
goto exit;
return_value = os_urandom_impl(module, size);
exit:
return return_value;
}
static PyObject *
os_urandom_impl(PyModuleDef *module, Py_ssize_t size)
/*[clinic end generated code: output=5dbff582cab94cb9 input=4067cdb1b6776c29]*/
{
PyObject *bytes;
int result;
if (size < 0)
return PyErr_Format(PyExc_ValueError,
"negative argument not allowed");
bytes = PyBytes_FromStringAndSize(NULL, size);
if (bytes == NULL)
return NULL;
result = _PyOS_URandom(PyBytes_AS_STRING(bytes),
PyBytes_GET_SIZE(bytes));
if (result == -1) {
Py_DECREF(bytes);
return NULL;
}
return bytes;
}
/* Terminal size querying */
static PyTypeObject TerminalSizeType;
PyDoc_STRVAR(TerminalSize_docstring,
"A tuple of (columns, lines) for holding terminal window size");
static PyStructSequence_Field TerminalSize_fields[] = {
{"columns", "width of the terminal window in characters"},
{"lines", "height of the terminal window in characters"},
{NULL, NULL}
};
static PyStructSequence_Desc TerminalSize_desc = {
"os.terminal_size",
TerminalSize_docstring,
TerminalSize_fields,
2,
};
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
/* AC 3.5: fd should accept None */
PyDoc_STRVAR(termsize__doc__,
"Return the size of the terminal window as (columns, lines).\n" \
"\n" \
"The optional argument fd (default standard output) specifies\n" \
"which file descriptor should be queried.\n" \
"\n" \
"If the file descriptor is not connected to a terminal, an OSError\n" \
"is thrown.\n" \
"\n" \
"This function will only be defined if an implementation is\n" \
"available for this system.\n" \
"\n" \
"shutil.get_terminal_size is the high-level function which should \n" \
"normally be used, os.get_terminal_size is the low-level implementation.");
static PyObject*
get_terminal_size(PyObject *self, PyObject *args)
{
int columns, lines;
PyObject *termsize;
int fd = fileno(stdout);
/* Under some conditions stdout may not be connected and
* fileno(stdout) may point to an invalid file descriptor. For example
* GUI apps don't have valid standard streams by default.
*
* If this happens, and the optional fd argument is not present,
* the ioctl below will fail returning EBADF. This is what we want.
*/
if (!PyArg_ParseTuple(args, "|i", &fd))
return NULL;
#ifdef TERMSIZE_USE_IOCTL
{
struct winsize w;
if (ioctl(fd, TIOCGWINSZ, &w))
return PyErr_SetFromErrno(PyExc_OSError);
columns = w.ws_col;
lines = w.ws_row;
}
#endif /* TERMSIZE_USE_IOCTL */
#ifdef TERMSIZE_USE_CONIO
{
DWORD nhandle;
HANDLE handle;
CONSOLE_SCREEN_BUFFER_INFO csbi;
switch (fd) {
case 0: nhandle = STD_INPUT_HANDLE;
break;
case 1: nhandle = STD_OUTPUT_HANDLE;
break;
case 2: nhandle = STD_ERROR_HANDLE;
break;
default:
return PyErr_Format(PyExc_ValueError, "bad file descriptor");
}
handle = GetStdHandle(nhandle);
if (handle == NULL)
return PyErr_Format(PyExc_OSError, "handle cannot be retrieved");
if (handle == INVALID_HANDLE_VALUE)
return PyErr_SetFromWindowsErr(0);
if (!GetConsoleScreenBufferInfo(handle, &csbi))
return PyErr_SetFromWindowsErr(0);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
}
#endif /* TERMSIZE_USE_CONIO */
termsize = PyStructSequence_New(&TerminalSizeType);
if (termsize == NULL)
return NULL;
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
if (PyErr_Occurred()) {
Py_DECREF(termsize);
return NULL;
}
return termsize;
}
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */
/*[clinic input]
os.cpu_count
Return the number of CPUs in the system; return None if indeterminable.
[clinic start generated code]*/
PyDoc_STRVAR(os_cpu_count__doc__,
"cpu_count($module, /)\n"
"--\n"
"\n"
"Return the number of CPUs in the system; return None if indeterminable.");
#define OS_CPU_COUNT_METHODDEF \
{"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
static PyObject *
os_cpu_count_impl(PyModuleDef *module);
static PyObject *
os_cpu_count(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
{
return os_cpu_count_impl(module);
}
static PyObject *
os_cpu_count_impl(PyModuleDef *module)
/*[clinic end generated code: output=92e2a4a729eb7740 input=d55e2f8f3823a628]*/
{
int ncpu = 0;
#ifdef MS_WINDOWS
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
ncpu = sysinfo.dwNumberOfProcessors;
#elif defined(__hpux)
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
ncpu = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(__DragonFly__) || \
defined(__OpenBSD__) || \
defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__APPLE__)
int mib[2];
size_t len = sizeof(ncpu);
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)
ncpu = 0;
#endif
if (ncpu >= 1)
return PyLong_FromLong(ncpu);
else
Py_RETURN_NONE;
}
/*[clinic input]
os.get_inheritable -> bool
fd: int
/
Get the close-on-exe flag of the specified file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_get_inheritable__doc__,
"get_inheritable($module, fd, /)\n"
"--\n"
"\n"
"Get the close-on-exe flag of the specified file descriptor.");
#define OS_GET_INHERITABLE_METHODDEF \
{"get_inheritable", (PyCFunction)os_get_inheritable, METH_VARARGS, os_get_inheritable__doc__},
static int
os_get_inheritable_impl(PyModuleDef *module, int fd);
static PyObject *
os_get_inheritable(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int _return_value;
if (!PyArg_ParseTuple(args,
"i:get_inheritable",
&fd))
goto exit;
_return_value = os_get_inheritable_impl(module, fd);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_get_inheritable_impl(PyModuleDef *module, int fd)
/*[clinic end generated code: output=261d1dd2b0dbdc35 input=89ac008dc9ab6b95]*/
{
if (!_PyVerify_fd(fd)){
posix_error();
return -1;
}
return _Py_get_inheritable(fd);
}
/*[clinic input]
os.set_inheritable
fd: int
inheritable: int
/
Set the inheritable flag of the specified file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_set_inheritable__doc__,
"set_inheritable($module, fd, inheritable, /)\n"
"--\n"
"\n"
"Set the inheritable flag of the specified file descriptor.");
#define OS_SET_INHERITABLE_METHODDEF \
{"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
static PyObject *
os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable);
static PyObject *
os_set_inheritable(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
int inheritable;
if (!PyArg_ParseTuple(args,
"ii:set_inheritable",
&fd, &inheritable))
goto exit;
return_value = os_set_inheritable_impl(module, fd, inheritable);
exit:
return return_value;
}
static PyObject *
os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable)
/*[clinic end generated code: output=64dfe5e15c906539 input=9ceaead87a1e2402]*/
{
if (!_PyVerify_fd(fd))
return posix_error();
if (_Py_set_inheritable(fd, inheritable, NULL) < 0)
return NULL;
Py_RETURN_NONE;
}
#ifdef MS_WINDOWS
/*[clinic input]
os.get_handle_inheritable -> bool
handle: Py_intptr_t
/
Get the close-on-exe flag of the specified file descriptor.
[clinic start generated code]*/
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
"get_handle_inheritable($module, handle, /)\n"
"--\n"
"\n"
"Get the close-on-exe flag of the specified file descriptor.");
#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
{"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_VARARGS, os_get_handle_inheritable__doc__},
static int
os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle);
static PyObject *
os_get_handle_inheritable(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
Py_intptr_t handle;
int _return_value;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_INTPTR ":get_handle_inheritable",
&handle))
goto exit;
_return_value = os_get_handle_inheritable_impl(module, handle);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyBool_FromLong((long)_return_value);
exit:
return return_value;
}
static int
os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle)
/*[clinic end generated code: output=d5bf9d86900bf457 input=5f7759443aae3dc5]*/
{
DWORD flags;
if (!GetHandleInformation((HANDLE)handle, &flags)) {
PyErr_SetFromWindowsErr(0);
return -1;
}
return flags & HANDLE_FLAG_INHERIT;
}
/*[clinic input]
os.set_handle_inheritable
handle: Py_intptr_t
inheritable: bool
/
Set the inheritable flag of the specified handle.
[clinic start generated code]*/
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
"set_handle_inheritable($module, handle, inheritable, /)\n"
"--\n"
"\n"
"Set the inheritable flag of the specified handle.");
#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
{"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
static PyObject *
os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle, int inheritable);
static PyObject *
os_set_handle_inheritable(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
Py_intptr_t handle;
int inheritable;
if (!PyArg_ParseTuple(args,
"" _Py_PARSE_INTPTR "p:set_handle_inheritable",
&handle, &inheritable))
goto exit;
return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
exit:
return return_value;
}
static PyObject *
os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle, int inheritable)
/*[clinic end generated code: output=ee5fcc6d9f0d4f8b input=e64b2b2730469def]*/
{
DWORD flags = inheritable ? HANDLE_FLAG_INHERIT : 0;
if (!SetHandleInformation((HANDLE)handle, HANDLE_FLAG_INHERIT, flags)) {
PyErr_SetFromWindowsErr(0);
return NULL;
}
Py_RETURN_NONE;
}
#endif /* MS_WINDOWS */
#ifndef MS_WINDOWS
PyDoc_STRVAR(get_blocking__doc__,
"get_blocking(fd) -> bool\n" \
"\n" \
"Get the blocking mode of the file descriptor:\n" \
"False if the O_NONBLOCK flag is set, True if the flag is cleared.");
static PyObject*
posix_get_blocking(PyObject *self, PyObject *args)
{
int fd;
int blocking;
if (!PyArg_ParseTuple(args, "i:get_blocking", &fd))
return NULL;
if (!_PyVerify_fd(fd))
return posix_error();
blocking = _Py_get_blocking(fd);
if (blocking < 0)
return NULL;
return PyBool_FromLong(blocking);
}
PyDoc_STRVAR(set_blocking__doc__,
"set_blocking(fd, blocking)\n" \
"\n" \
"Set the blocking mode of the specified file descriptor.\n" \
"Set the O_NONBLOCK flag if blocking is False,\n" \
"clear the O_NONBLOCK flag otherwise.");
static PyObject*
posix_set_blocking(PyObject *self, PyObject *args)
{
int fd, blocking;
if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
return NULL;
if (!_PyVerify_fd(fd))
return posix_error();
if (_Py_set_blocking(fd, blocking) < 0)
return NULL;
Py_RETURN_NONE;
}
#endif /* !MS_WINDOWS */
/*[clinic input]
dump buffer
[clinic start generated code]*/
#ifndef OS_TTYNAME_METHODDEF
#define OS_TTYNAME_METHODDEF
#endif /* !defined(OS_TTYNAME_METHODDEF) */
#ifndef OS_CTERMID_METHODDEF
#define OS_CTERMID_METHODDEF
#endif /* !defined(OS_CTERMID_METHODDEF) */
#ifndef OS_FCHDIR_METHODDEF
#define OS_FCHDIR_METHODDEF
#endif /* !defined(OS_FCHDIR_METHODDEF) */
#ifndef OS_FCHMOD_METHODDEF
#define OS_FCHMOD_METHODDEF
#endif /* !defined(OS_FCHMOD_METHODDEF) */
#ifndef OS_LCHMOD_METHODDEF
#define OS_LCHMOD_METHODDEF
#endif /* !defined(OS_LCHMOD_METHODDEF) */
#ifndef OS_CHFLAGS_METHODDEF
#define OS_CHFLAGS_METHODDEF
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
#ifndef OS_LCHFLAGS_METHODDEF
#define OS_LCHFLAGS_METHODDEF
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
#ifndef OS_CHROOT_METHODDEF
#define OS_CHROOT_METHODDEF
#endif /* !defined(OS_CHROOT_METHODDEF) */
#ifndef OS_FSYNC_METHODDEF
#define OS_FSYNC_METHODDEF
#endif /* !defined(OS_FSYNC_METHODDEF) */
#ifndef OS_SYNC_METHODDEF
#define OS_SYNC_METHODDEF
#endif /* !defined(OS_SYNC_METHODDEF) */
#ifndef OS_FDATASYNC_METHODDEF
#define OS_FDATASYNC_METHODDEF
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
#ifndef OS_CHOWN_METHODDEF
#define OS_CHOWN_METHODDEF
#endif /* !defined(OS_CHOWN_METHODDEF) */
#ifndef OS_FCHOWN_METHODDEF
#define OS_FCHOWN_METHODDEF
#endif /* !defined(OS_FCHOWN_METHODDEF) */
#ifndef OS_LCHOWN_METHODDEF
#define OS_LCHOWN_METHODDEF
#endif /* !defined(OS_LCHOWN_METHODDEF) */
#ifndef OS_LINK_METHODDEF
#define OS_LINK_METHODDEF
#endif /* !defined(OS_LINK_METHODDEF) */
#ifndef OS__GETFINALPATHNAME_METHODDEF
#define OS__GETFINALPATHNAME_METHODDEF
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
#define OS__GETVOLUMEPATHNAME_METHODDEF
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
#ifndef OS_NICE_METHODDEF
#define OS_NICE_METHODDEF
#endif /* !defined(OS_NICE_METHODDEF) */
#ifndef OS_GETPRIORITY_METHODDEF
#define OS_GETPRIORITY_METHODDEF
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
#ifndef OS_SETPRIORITY_METHODDEF
#define OS_SETPRIORITY_METHODDEF
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
#ifndef OS_SYSTEM_METHODDEF
#define OS_SYSTEM_METHODDEF
#endif /* !defined(OS_SYSTEM_METHODDEF) */
#ifndef OS_SYSTEM_METHODDEF
#define OS_SYSTEM_METHODDEF
#endif /* !defined(OS_SYSTEM_METHODDEF) */
#ifndef OS_UNAME_METHODDEF
#define OS_UNAME_METHODDEF
#endif /* !defined(OS_UNAME_METHODDEF) */
#ifndef OS_EXECV_METHODDEF
#define OS_EXECV_METHODDEF
#endif /* !defined(OS_EXECV_METHODDEF) */
#ifndef OS_EXECVE_METHODDEF
#define OS_EXECVE_METHODDEF
#endif /* !defined(OS_EXECVE_METHODDEF) */
#ifndef OS_SPAWNV_METHODDEF
#define OS_SPAWNV_METHODDEF
#endif /* !defined(OS_SPAWNV_METHODDEF) */
#ifndef OS_SPAWNVE_METHODDEF
#define OS_SPAWNVE_METHODDEF
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
#ifndef OS_FORK1_METHODDEF
#define OS_FORK1_METHODDEF
#endif /* !defined(OS_FORK1_METHODDEF) */
#ifndef OS_FORK_METHODDEF
#define OS_FORK_METHODDEF
#endif /* !defined(OS_FORK_METHODDEF) */
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
#define OS_SCHED_GETSCHEDULER_METHODDEF
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
#define OS_SCHED_SETSCHEDULER_METHODDEF
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
#ifndef OS_SCHED_GETPARAM_METHODDEF
#define OS_SCHED_GETPARAM_METHODDEF
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
#ifndef OS_SCHED_SETPARAM_METHODDEF
#define OS_SCHED_SETPARAM_METHODDEF
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
#ifndef OS_SCHED_YIELD_METHODDEF
#define OS_SCHED_YIELD_METHODDEF
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
#define OS_SCHED_SETAFFINITY_METHODDEF
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
#define OS_SCHED_GETAFFINITY_METHODDEF
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
#ifndef OS_OPENPTY_METHODDEF
#define OS_OPENPTY_METHODDEF
#endif /* !defined(OS_OPENPTY_METHODDEF) */
#ifndef OS_FORKPTY_METHODDEF
#define OS_FORKPTY_METHODDEF
#endif /* !defined(OS_FORKPTY_METHODDEF) */
#ifndef OS_GETEGID_METHODDEF
#define OS_GETEGID_METHODDEF
#endif /* !defined(OS_GETEGID_METHODDEF) */
#ifndef OS_GETEUID_METHODDEF
#define OS_GETEUID_METHODDEF
#endif /* !defined(OS_GETEUID_METHODDEF) */
#ifndef OS_GETGID_METHODDEF
#define OS_GETGID_METHODDEF
#endif /* !defined(OS_GETGID_METHODDEF) */
#ifndef OS_GETGROUPS_METHODDEF
#define OS_GETGROUPS_METHODDEF
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
#ifndef OS_GETPGID_METHODDEF
#define OS_GETPGID_METHODDEF
#endif /* !defined(OS_GETPGID_METHODDEF) */
#ifndef OS_GETPGRP_METHODDEF
#define OS_GETPGRP_METHODDEF
#endif /* !defined(OS_GETPGRP_METHODDEF) */
#ifndef OS_SETPGRP_METHODDEF
#define OS_SETPGRP_METHODDEF
#endif /* !defined(OS_SETPGRP_METHODDEF) */
#ifndef OS_GETPPID_METHODDEF
#define OS_GETPPID_METHODDEF
#endif /* !defined(OS_GETPPID_METHODDEF) */
#ifndef OS_GETLOGIN_METHODDEF
#define OS_GETLOGIN_METHODDEF
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
#ifndef OS_GETUID_METHODDEF
#define OS_GETUID_METHODDEF
#endif /* !defined(OS_GETUID_METHODDEF) */
#ifndef OS_KILL_METHODDEF
#define OS_KILL_METHODDEF
#endif /* !defined(OS_KILL_METHODDEF) */
#ifndef OS_KILLPG_METHODDEF
#define OS_KILLPG_METHODDEF
#endif /* !defined(OS_KILLPG_METHODDEF) */
#ifndef OS_PLOCK_METHODDEF
#define OS_PLOCK_METHODDEF
#endif /* !defined(OS_PLOCK_METHODDEF) */
#ifndef OS_SETUID_METHODDEF
#define OS_SETUID_METHODDEF
#endif /* !defined(OS_SETUID_METHODDEF) */
#ifndef OS_SETEUID_METHODDEF
#define OS_SETEUID_METHODDEF
#endif /* !defined(OS_SETEUID_METHODDEF) */
#ifndef OS_SETEGID_METHODDEF
#define OS_SETEGID_METHODDEF
#endif /* !defined(OS_SETEGID_METHODDEF) */
#ifndef OS_SETREUID_METHODDEF
#define OS_SETREUID_METHODDEF
#endif /* !defined(OS_SETREUID_METHODDEF) */
#ifndef OS_SETREGID_METHODDEF
#define OS_SETREGID_METHODDEF
#endif /* !defined(OS_SETREGID_METHODDEF) */
#ifndef OS_SETGID_METHODDEF
#define OS_SETGID_METHODDEF
#endif /* !defined(OS_SETGID_METHODDEF) */
#ifndef OS_SETGROUPS_METHODDEF
#define OS_SETGROUPS_METHODDEF
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
#ifndef OS_WAIT3_METHODDEF
#define OS_WAIT3_METHODDEF
#endif /* !defined(OS_WAIT3_METHODDEF) */
#ifndef OS_WAIT4_METHODDEF
#define OS_WAIT4_METHODDEF
#endif /* !defined(OS_WAIT4_METHODDEF) */
#ifndef OS_WAITID_METHODDEF
#define OS_WAITID_METHODDEF
#endif /* !defined(OS_WAITID_METHODDEF) */
#ifndef OS_WAITPID_METHODDEF
#define OS_WAITPID_METHODDEF
#endif /* !defined(OS_WAITPID_METHODDEF) */
#ifndef OS_WAITPID_METHODDEF
#define OS_WAITPID_METHODDEF
#endif /* !defined(OS_WAITPID_METHODDEF) */
#ifndef OS_WAIT_METHODDEF
#define OS_WAIT_METHODDEF
#endif /* !defined(OS_WAIT_METHODDEF) */
#ifndef OS_SYMLINK_METHODDEF
#define OS_SYMLINK_METHODDEF
#endif /* !defined(OS_SYMLINK_METHODDEF) */
#ifndef OS_TIMES_METHODDEF
#define OS_TIMES_METHODDEF
#endif /* !defined(OS_TIMES_METHODDEF) */
#ifndef OS_GETSID_METHODDEF
#define OS_GETSID_METHODDEF
#endif /* !defined(OS_GETSID_METHODDEF) */
#ifndef OS_SETSID_METHODDEF
#define OS_SETSID_METHODDEF
#endif /* !defined(OS_SETSID_METHODDEF) */
#ifndef OS_SETPGID_METHODDEF
#define OS_SETPGID_METHODDEF
#endif /* !defined(OS_SETPGID_METHODDEF) */
#ifndef OS_TCGETPGRP_METHODDEF
#define OS_TCGETPGRP_METHODDEF
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
#ifndef OS_TCSETPGRP_METHODDEF
#define OS_TCSETPGRP_METHODDEF
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
#ifndef OS_LOCKF_METHODDEF
#define OS_LOCKF_METHODDEF
#endif /* !defined(OS_LOCKF_METHODDEF) */
#ifndef OS_READV_METHODDEF
#define OS_READV_METHODDEF
#endif /* !defined(OS_READV_METHODDEF) */
#ifndef OS_PREAD_METHODDEF
#define OS_PREAD_METHODDEF
#endif /* !defined(OS_PREAD_METHODDEF) */
#ifndef OS_PIPE_METHODDEF
#define OS_PIPE_METHODDEF
#endif /* !defined(OS_PIPE_METHODDEF) */
#ifndef OS_PIPE2_METHODDEF
#define OS_PIPE2_METHODDEF
#endif /* !defined(OS_PIPE2_METHODDEF) */
#ifndef OS_WRITEV_METHODDEF
#define OS_WRITEV_METHODDEF
#endif /* !defined(OS_WRITEV_METHODDEF) */
#ifndef OS_PWRITE_METHODDEF
#define OS_PWRITE_METHODDEF
#endif /* !defined(OS_PWRITE_METHODDEF) */
#ifndef OS_MKFIFO_METHODDEF
#define OS_MKFIFO_METHODDEF
#endif /* !defined(OS_MKFIFO_METHODDEF) */
#ifndef OS_MKNOD_METHODDEF
#define OS_MKNOD_METHODDEF
#endif /* !defined(OS_MKNOD_METHODDEF) */
#ifndef OS_MAJOR_METHODDEF
#define OS_MAJOR_METHODDEF
#endif /* !defined(OS_MAJOR_METHODDEF) */
#ifndef OS_MINOR_METHODDEF
#define OS_MINOR_METHODDEF
#endif /* !defined(OS_MINOR_METHODDEF) */
#ifndef OS_MAKEDEV_METHODDEF
#define OS_MAKEDEV_METHODDEF
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
#ifndef OS_FTRUNCATE_METHODDEF
#define OS_FTRUNCATE_METHODDEF
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
#ifndef OS_TRUNCATE_METHODDEF
#define OS_TRUNCATE_METHODDEF
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
#ifndef OS_POSIX_FALLOCATE_METHODDEF
#define OS_POSIX_FALLOCATE_METHODDEF
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
#ifndef OS_POSIX_FADVISE_METHODDEF
#define OS_POSIX_FADVISE_METHODDEF
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
#ifndef OS_PUTENV_METHODDEF
#define OS_PUTENV_METHODDEF
#endif /* !defined(OS_PUTENV_METHODDEF) */
#ifndef OS_PUTENV_METHODDEF
#define OS_PUTENV_METHODDEF
#endif /* !defined(OS_PUTENV_METHODDEF) */
#ifndef OS_UNSETENV_METHODDEF
#define OS_UNSETENV_METHODDEF
#endif /* !defined(OS_UNSETENV_METHODDEF) */
#ifndef OS_WCOREDUMP_METHODDEF
#define OS_WCOREDUMP_METHODDEF
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
#ifndef OS_WIFCONTINUED_METHODDEF
#define OS_WIFCONTINUED_METHODDEF
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
#ifndef OS_WIFSTOPPED_METHODDEF
#define OS_WIFSTOPPED_METHODDEF
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
#ifndef OS_WIFSIGNALED_METHODDEF
#define OS_WIFSIGNALED_METHODDEF
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
#ifndef OS_WIFEXITED_METHODDEF
#define OS_WIFEXITED_METHODDEF
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
#ifndef OS_WEXITSTATUS_METHODDEF
#define OS_WEXITSTATUS_METHODDEF
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
#ifndef OS_WTERMSIG_METHODDEF
#define OS_WTERMSIG_METHODDEF
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
#ifndef OS_WSTOPSIG_METHODDEF
#define OS_WSTOPSIG_METHODDEF
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
#ifndef OS_FSTATVFS_METHODDEF
#define OS_FSTATVFS_METHODDEF
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
#ifndef OS_STATVFS_METHODDEF
#define OS_STATVFS_METHODDEF
#endif /* !defined(OS_STATVFS_METHODDEF) */
#ifndef OS__GETDISKUSAGE_METHODDEF
#define OS__GETDISKUSAGE_METHODDEF
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
#ifndef OS_FPATHCONF_METHODDEF
#define OS_FPATHCONF_METHODDEF
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
#ifndef OS_PATHCONF_METHODDEF
#define OS_PATHCONF_METHODDEF
#endif /* !defined(OS_PATHCONF_METHODDEF) */
#ifndef OS_CONFSTR_METHODDEF
#define OS_CONFSTR_METHODDEF
#endif /* !defined(OS_CONFSTR_METHODDEF) */
#ifndef OS_SYSCONF_METHODDEF
#define OS_SYSCONF_METHODDEF
#endif /* !defined(OS_SYSCONF_METHODDEF) */
#ifndef OS_GETLOADAVG_METHODDEF
#define OS_GETLOADAVG_METHODDEF
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
#ifndef OS_SETRESUID_METHODDEF
#define OS_SETRESUID_METHODDEF
#endif /* !defined(OS_SETRESUID_METHODDEF) */
#ifndef OS_SETRESGID_METHODDEF
#define OS_SETRESGID_METHODDEF
#endif /* !defined(OS_SETRESGID_METHODDEF) */
#ifndef OS_GETRESUID_METHODDEF
#define OS_GETRESUID_METHODDEF
#endif /* !defined(OS_GETRESUID_METHODDEF) */
#ifndef OS_GETRESGID_METHODDEF
#define OS_GETRESGID_METHODDEF
#endif /* !defined(OS_GETRESGID_METHODDEF) */
#ifndef OS_GETXATTR_METHODDEF
#define OS_GETXATTR_METHODDEF
#endif /* !defined(OS_GETXATTR_METHODDEF) */
#ifndef OS_SETXATTR_METHODDEF
#define OS_SETXATTR_METHODDEF
#endif /* !defined(OS_SETXATTR_METHODDEF) */
#ifndef OS_REMOVEXATTR_METHODDEF
#define OS_REMOVEXATTR_METHODDEF
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
#ifndef OS_LISTXATTR_METHODDEF
#define OS_LISTXATTR_METHODDEF
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
#define OS_GET_HANDLE_INHERITABLE_METHODDEF
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
#define OS_SET_HANDLE_INHERITABLE_METHODDEF
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
/*[clinic end generated code: output=52a6140b0b052ce6 input=524ce2e021e4eba6]*/
static PyMethodDef posix_methods[] = {
OS_STAT_METHODDEF
OS_ACCESS_METHODDEF
OS_TTYNAME_METHODDEF
OS_CHDIR_METHODDEF
OS_CHFLAGS_METHODDEF
OS_CHMOD_METHODDEF
OS_FCHMOD_METHODDEF
OS_LCHMOD_METHODDEF
OS_CHOWN_METHODDEF
OS_FCHOWN_METHODDEF
OS_LCHOWN_METHODDEF
OS_LCHFLAGS_METHODDEF
OS_CHROOT_METHODDEF
OS_CTERMID_METHODDEF
OS_GETCWD_METHODDEF
OS_GETCWDB_METHODDEF
OS_LINK_METHODDEF
OS_LISTDIR_METHODDEF
OS_LSTAT_METHODDEF
OS_MKDIR_METHODDEF
OS_NICE_METHODDEF
OS_GETPRIORITY_METHODDEF
OS_SETPRIORITY_METHODDEF
#ifdef HAVE_READLINK
{"readlink", (PyCFunction)posix_readlink,
METH_VARARGS | METH_KEYWORDS,
readlink__doc__},
#endif /* HAVE_READLINK */
#if !defined(HAVE_READLINK) && defined(MS_WINDOWS)
{"readlink", (PyCFunction)win_readlink,
METH_VARARGS | METH_KEYWORDS,
readlink__doc__},
#endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
OS_RENAME_METHODDEF
OS_REPLACE_METHODDEF
OS_RMDIR_METHODDEF
{"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
OS_SYMLINK_METHODDEF
OS_SYSTEM_METHODDEF
OS_UMASK_METHODDEF
OS_UNAME_METHODDEF
OS_UNLINK_METHODDEF
OS_REMOVE_METHODDEF
OS_UTIME_METHODDEF
OS_TIMES_METHODDEF
OS__EXIT_METHODDEF
OS_EXECV_METHODDEF
OS_EXECVE_METHODDEF
OS_SPAWNV_METHODDEF
OS_SPAWNVE_METHODDEF
OS_FORK1_METHODDEF
OS_FORK_METHODDEF
OS_SCHED_GET_PRIORITY_MAX_METHODDEF
OS_SCHED_GET_PRIORITY_MIN_METHODDEF
OS_SCHED_GETPARAM_METHODDEF
OS_SCHED_GETSCHEDULER_METHODDEF
OS_SCHED_RR_GET_INTERVAL_METHODDEF
OS_SCHED_SETPARAM_METHODDEF
OS_SCHED_SETSCHEDULER_METHODDEF
OS_SCHED_YIELD_METHODDEF
OS_SCHED_SETAFFINITY_METHODDEF
OS_SCHED_GETAFFINITY_METHODDEF
OS_OPENPTY_METHODDEF
OS_FORKPTY_METHODDEF
OS_GETEGID_METHODDEF
OS_GETEUID_METHODDEF
OS_GETGID_METHODDEF
#ifdef HAVE_GETGROUPLIST
{"getgrouplist", posix_getgrouplist, METH_VARARGS, posix_getgrouplist__doc__},
#endif
OS_GETGROUPS_METHODDEF
OS_GETPID_METHODDEF
OS_GETPGRP_METHODDEF
OS_GETPPID_METHODDEF
OS_GETUID_METHODDEF
OS_GETLOGIN_METHODDEF
OS_KILL_METHODDEF
OS_KILLPG_METHODDEF
OS_PLOCK_METHODDEF
#ifdef MS_WINDOWS
{"startfile", win32_startfile, METH_VARARGS, win32_startfile__doc__},
#endif
OS_SETUID_METHODDEF
OS_SETEUID_METHODDEF
OS_SETREUID_METHODDEF
OS_SETGID_METHODDEF
OS_SETEGID_METHODDEF
OS_SETREGID_METHODDEF
OS_SETGROUPS_METHODDEF
#ifdef HAVE_INITGROUPS
{"initgroups", posix_initgroups, METH_VARARGS, posix_initgroups__doc__},
#endif /* HAVE_INITGROUPS */
OS_GETPGID_METHODDEF
OS_SETPGRP_METHODDEF
OS_WAIT_METHODDEF
OS_WAIT3_METHODDEF
OS_WAIT4_METHODDEF
OS_WAITID_METHODDEF
OS_WAITPID_METHODDEF
OS_GETSID_METHODDEF
OS_SETSID_METHODDEF
OS_SETPGID_METHODDEF
OS_TCGETPGRP_METHODDEF
OS_TCSETPGRP_METHODDEF
OS_OPEN_METHODDEF
OS_CLOSE_METHODDEF
OS_CLOSERANGE_METHODDEF
OS_DEVICE_ENCODING_METHODDEF
OS_DUP_METHODDEF
OS_DUP2_METHODDEF
OS_LOCKF_METHODDEF
OS_LSEEK_METHODDEF
OS_READ_METHODDEF
OS_READV_METHODDEF
OS_PREAD_METHODDEF
OS_WRITE_METHODDEF
OS_WRITEV_METHODDEF
OS_PWRITE_METHODDEF
#ifdef HAVE_SENDFILE
{"sendfile", (PyCFunction)posix_sendfile, METH_VARARGS | METH_KEYWORDS,
posix_sendfile__doc__},
#endif
OS_FSTAT_METHODDEF
OS_ISATTY_METHODDEF
OS_PIPE_METHODDEF
OS_PIPE2_METHODDEF
OS_MKFIFO_METHODDEF
OS_MKNOD_METHODDEF
OS_MAJOR_METHODDEF
OS_MINOR_METHODDEF
OS_MAKEDEV_METHODDEF
OS_FTRUNCATE_METHODDEF
OS_TRUNCATE_METHODDEF
OS_POSIX_FALLOCATE_METHODDEF
OS_POSIX_FADVISE_METHODDEF
OS_PUTENV_METHODDEF
OS_UNSETENV_METHODDEF
OS_STRERROR_METHODDEF
OS_FCHDIR_METHODDEF
OS_FSYNC_METHODDEF
OS_SYNC_METHODDEF
OS_FDATASYNC_METHODDEF
OS_WCOREDUMP_METHODDEF
OS_WIFCONTINUED_METHODDEF
OS_WIFSTOPPED_METHODDEF
OS_WIFSIGNALED_METHODDEF
OS_WIFEXITED_METHODDEF
OS_WEXITSTATUS_METHODDEF
OS_WTERMSIG_METHODDEF
OS_WSTOPSIG_METHODDEF
OS_FSTATVFS_METHODDEF
OS_STATVFS_METHODDEF
OS_CONFSTR_METHODDEF
OS_SYSCONF_METHODDEF
OS_FPATHCONF_METHODDEF
OS_PATHCONF_METHODDEF
OS_ABORT_METHODDEF
#ifdef MS_WINDOWS
{"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
{"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
#endif
OS__GETDISKUSAGE_METHODDEF
OS__GETFINALPATHNAME_METHODDEF
OS__GETVOLUMEPATHNAME_METHODDEF
OS_GETLOADAVG_METHODDEF
OS_URANDOM_METHODDEF
OS_SETRESUID_METHODDEF
OS_SETRESGID_METHODDEF
OS_GETRESUID_METHODDEF
OS_GETRESGID_METHODDEF
OS_GETXATTR_METHODDEF
OS_SETXATTR_METHODDEF
OS_REMOVEXATTR_METHODDEF
OS_LISTXATTR_METHODDEF
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
{"get_terminal_size", get_terminal_size, METH_VARARGS, termsize__doc__},
#endif
OS_CPU_COUNT_METHODDEF
OS_GET_INHERITABLE_METHODDEF
OS_SET_INHERITABLE_METHODDEF
OS_GET_HANDLE_INHERITABLE_METHODDEF
OS_SET_HANDLE_INHERITABLE_METHODDEF
#ifndef MS_WINDOWS
{"get_blocking", posix_get_blocking, METH_VARARGS, get_blocking__doc__},
{"set_blocking", posix_set_blocking, METH_VARARGS, set_blocking__doc__},
#endif
{NULL, NULL} /* Sentinel */
};
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
static int
enable_symlink()
{
HANDLE tok;
TOKEN_PRIVILEGES tok_priv;
LUID luid;
int meth_idx = 0;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &tok))
return 0;
if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid))
return 0;
tok_priv.PrivilegeCount = 1;
tok_priv.Privileges[0].Luid = luid;
tok_priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(tok, FALSE, &tok_priv,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL))
return 0;
/* ERROR_NOT_ALL_ASSIGNED returned when the privilege can't be assigned. */
return GetLastError() == ERROR_NOT_ALL_ASSIGNED ? 0 : 1;
}
#endif /* defined(HAVE_SYMLINK) && defined(MS_WINDOWS) */
static int
all_ins(PyObject *m)
{
#ifdef F_OK
if (PyModule_AddIntMacro(m, F_OK)) return -1;
#endif
#ifdef R_OK
if (PyModule_AddIntMacro(m, R_OK)) return -1;
#endif
#ifdef W_OK
if (PyModule_AddIntMacro(m, W_OK)) return -1;
#endif
#ifdef X_OK
if (PyModule_AddIntMacro(m, X_OK)) return -1;
#endif
#ifdef NGROUPS_MAX
if (PyModule_AddIntMacro(m, NGROUPS_MAX)) return -1;
#endif
#ifdef TMP_MAX
if (PyModule_AddIntMacro(m, TMP_MAX)) return -1;
#endif
#ifdef WCONTINUED
if (PyModule_AddIntMacro(m, WCONTINUED)) return -1;
#endif
#ifdef WNOHANG
if (PyModule_AddIntMacro(m, WNOHANG)) return -1;
#endif
#ifdef WUNTRACED
if (PyModule_AddIntMacro(m, WUNTRACED)) return -1;
#endif
#ifdef O_RDONLY
if (PyModule_AddIntMacro(m, O_RDONLY)) return -1;
#endif
#ifdef O_WRONLY
if (PyModule_AddIntMacro(m, O_WRONLY)) return -1;
#endif
#ifdef O_RDWR
if (PyModule_AddIntMacro(m, O_RDWR)) return -1;
#endif
#ifdef O_NDELAY
if (PyModule_AddIntMacro(m, O_NDELAY)) return -1;
#endif
#ifdef O_NONBLOCK
if (PyModule_AddIntMacro(m, O_NONBLOCK)) return -1;
#endif
#ifdef O_APPEND
if (PyModule_AddIntMacro(m, O_APPEND)) return -1;
#endif
#ifdef O_DSYNC
if (PyModule_AddIntMacro(m, O_DSYNC)) return -1;
#endif
#ifdef O_RSYNC
if (PyModule_AddIntMacro(m, O_RSYNC)) return -1;
#endif
#ifdef O_SYNC
if (PyModule_AddIntMacro(m, O_SYNC)) return -1;
#endif
#ifdef O_NOCTTY
if (PyModule_AddIntMacro(m, O_NOCTTY)) return -1;
#endif
#ifdef O_CREAT
if (PyModule_AddIntMacro(m, O_CREAT)) return -1;
#endif
#ifdef O_EXCL
if (PyModule_AddIntMacro(m, O_EXCL)) return -1;
#endif
#ifdef O_TRUNC
if (PyModule_AddIntMacro(m, O_TRUNC)) return -1;
#endif
#ifdef O_BINARY
if (PyModule_AddIntMacro(m, O_BINARY)) return -1;
#endif
#ifdef O_TEXT
if (PyModule_AddIntMacro(m, O_TEXT)) return -1;
#endif
#ifdef O_XATTR
if (PyModule_AddIntMacro(m, O_XATTR)) return -1;
#endif
#ifdef O_LARGEFILE
if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1;
#endif
#ifdef O_SHLOCK
if (PyModule_AddIntMacro(m, O_SHLOCK)) return -1;
#endif
#ifdef O_EXLOCK
if (PyModule_AddIntMacro(m, O_EXLOCK)) return -1;
#endif
#ifdef O_EXEC
if (PyModule_AddIntMacro(m, O_EXEC)) return -1;
#endif
#ifdef O_SEARCH
if (PyModule_AddIntMacro(m, O_SEARCH)) return -1;
#endif
#ifdef O_PATH
if (PyModule_AddIntMacro(m, O_PATH)) return -1;
#endif
#ifdef O_TTY_INIT
if (PyModule_AddIntMacro(m, O_TTY_INIT)) return -1;
#endif
#ifdef O_TMPFILE
if (PyModule_AddIntMacro(m, O_TMPFILE)) return -1;
#endif
#ifdef PRIO_PROCESS
if (PyModule_AddIntMacro(m, PRIO_PROCESS)) return -1;
#endif
#ifdef PRIO_PGRP
if (PyModule_AddIntMacro(m, PRIO_PGRP)) return -1;
#endif
#ifdef PRIO_USER
if (PyModule_AddIntMacro(m, PRIO_USER)) return -1;
#endif
#ifdef O_CLOEXEC
if (PyModule_AddIntMacro(m, O_CLOEXEC)) return -1;
#endif
#ifdef O_ACCMODE
if (PyModule_AddIntMacro(m, O_ACCMODE)) return -1;
#endif
#ifdef SEEK_HOLE
if (PyModule_AddIntMacro(m, SEEK_HOLE)) return -1;
#endif
#ifdef SEEK_DATA
if (PyModule_AddIntMacro(m, SEEK_DATA)) return -1;
#endif
/* MS Windows */
#ifdef O_NOINHERIT
/* Don't inherit in child processes. */
if (PyModule_AddIntMacro(m, O_NOINHERIT)) return -1;
#endif
#ifdef _O_SHORT_LIVED
/* Optimize for short life (keep in memory). */
/* MS forgot to define this one with a non-underscore form too. */
if (PyModule_AddIntConstant(m, "O_SHORT_LIVED", _O_SHORT_LIVED)) return -1;
#endif
#ifdef O_TEMPORARY
/* Automatically delete when last handle is closed. */
if (PyModule_AddIntMacro(m, O_TEMPORARY)) return -1;
#endif
#ifdef O_RANDOM
/* Optimize for random access. */
if (PyModule_AddIntMacro(m, O_RANDOM)) return -1;
#endif
#ifdef O_SEQUENTIAL
/* Optimize for sequential access. */
if (PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1;
#endif
/* GNU extensions. */
#ifdef O_ASYNC
/* Send a SIGIO signal whenever input or output
becomes available on file descriptor */
if (PyModule_AddIntMacro(m, O_ASYNC)) return -1;
#endif
#ifdef O_DIRECT
/* Direct disk access. */
if (PyModule_AddIntMacro(m, O_DIRECT)) return -1;
#endif
#ifdef O_DIRECTORY
/* Must be a directory. */
if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1;
#endif
#ifdef O_NOFOLLOW
/* Do not follow links. */
if (PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1;
#endif
#ifdef O_NOLINKS
/* Fails if link count of the named file is greater than 1 */
if (PyModule_AddIntMacro(m, O_NOLINKS)) return -1;
#endif
#ifdef O_NOATIME
/* Do not update the access time. */
if (PyModule_AddIntMacro(m, O_NOATIME)) return -1;
#endif
/* These come from sysexits.h */
#ifdef EX_OK
if (PyModule_AddIntMacro(m, EX_OK)) return -1;
#endif /* EX_OK */
#ifdef EX_USAGE
if (PyModule_AddIntMacro(m, EX_USAGE)) return -1;
#endif /* EX_USAGE */
#ifdef EX_DATAERR
if (PyModule_AddIntMacro(m, EX_DATAERR)) return -1;
#endif /* EX_DATAERR */
#ifdef EX_NOINPUT
if (PyModule_AddIntMacro(m, EX_NOINPUT)) return -1;
#endif /* EX_NOINPUT */
#ifdef EX_NOUSER
if (PyModule_AddIntMacro(m, EX_NOUSER)) return -1;
#endif /* EX_NOUSER */
#ifdef EX_NOHOST
if (PyModule_AddIntMacro(m, EX_NOHOST)) return -1;
#endif /* EX_NOHOST */
#ifdef EX_UNAVAILABLE
if (PyModule_AddIntMacro(m, EX_UNAVAILABLE)) return -1;
#endif /* EX_UNAVAILABLE */
#ifdef EX_SOFTWARE
if (PyModule_AddIntMacro(m, EX_SOFTWARE)) return -1;
#endif /* EX_SOFTWARE */
#ifdef EX_OSERR
if (PyModule_AddIntMacro(m, EX_OSERR)) return -1;
#endif /* EX_OSERR */
#ifdef EX_OSFILE
if (PyModule_AddIntMacro(m, EX_OSFILE)) return -1;
#endif /* EX_OSFILE */
#ifdef EX_CANTCREAT
if (PyModule_AddIntMacro(m, EX_CANTCREAT)) return -1;
#endif /* EX_CANTCREAT */
#ifdef EX_IOERR
if (PyModule_AddIntMacro(m, EX_IOERR)) return -1;
#endif /* EX_IOERR */
#ifdef EX_TEMPFAIL
if (PyModule_AddIntMacro(m, EX_TEMPFAIL)) return -1;
#endif /* EX_TEMPFAIL */
#ifdef EX_PROTOCOL
if (PyModule_AddIntMacro(m, EX_PROTOCOL)) return -1;
#endif /* EX_PROTOCOL */
#ifdef EX_NOPERM
if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1;
#endif /* EX_NOPERM */
#ifdef EX_CONFIG
if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1;
#endif /* EX_CONFIG */
#ifdef EX_NOTFOUND
if (PyModule_AddIntMacro(m, EX_NOTFOUND)) return -1;
#endif /* EX_NOTFOUND */
/* statvfs */
#ifdef ST_RDONLY
if (PyModule_AddIntMacro(m, ST_RDONLY)) return -1;
#endif /* ST_RDONLY */
#ifdef ST_NOSUID
if (PyModule_AddIntMacro(m, ST_NOSUID)) return -1;
#endif /* ST_NOSUID */
/* GNU extensions */
#ifdef ST_NODEV
if (PyModule_AddIntMacro(m, ST_NODEV)) return -1;
#endif /* ST_NODEV */
#ifdef ST_NOEXEC
if (PyModule_AddIntMacro(m, ST_NOEXEC)) return -1;
#endif /* ST_NOEXEC */
#ifdef ST_SYNCHRONOUS
if (PyModule_AddIntMacro(m, ST_SYNCHRONOUS)) return -1;
#endif /* ST_SYNCHRONOUS */
#ifdef ST_MANDLOCK
if (PyModule_AddIntMacro(m, ST_MANDLOCK)) return -1;
#endif /* ST_MANDLOCK */
#ifdef ST_WRITE
if (PyModule_AddIntMacro(m, ST_WRITE)) return -1;
#endif /* ST_WRITE */
#ifdef ST_APPEND
if (PyModule_AddIntMacro(m, ST_APPEND)) return -1;
#endif /* ST_APPEND */
#ifdef ST_NOATIME
if (PyModule_AddIntMacro(m, ST_NOATIME)) return -1;
#endif /* ST_NOATIME */
#ifdef ST_NODIRATIME
if (PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1;
#endif /* ST_NODIRATIME */
#ifdef ST_RELATIME
if (PyModule_AddIntMacro(m, ST_RELATIME)) return -1;
#endif /* ST_RELATIME */
/* FreeBSD sendfile() constants */
#ifdef SF_NODISKIO
if (PyModule_AddIntMacro(m, SF_NODISKIO)) return -1;
#endif
#ifdef SF_MNOWAIT
if (PyModule_AddIntMacro(m, SF_MNOWAIT)) return -1;
#endif
#ifdef SF_SYNC
if (PyModule_AddIntMacro(m, SF_SYNC)) return -1;
#endif
/* constants for posix_fadvise */
#ifdef POSIX_FADV_NORMAL
if (PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1;
#endif
#ifdef POSIX_FADV_SEQUENTIAL
if (PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1;
#endif
#ifdef POSIX_FADV_RANDOM
if (PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1;
#endif
#ifdef POSIX_FADV_NOREUSE
if (PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1;
#endif
#ifdef POSIX_FADV_WILLNEED
if (PyModule_AddIntMacro(m, POSIX_FADV_WILLNEED)) return -1;
#endif
#ifdef POSIX_FADV_DONTNEED
if (PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1;
#endif
/* constants for waitid */
#if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID)
if (PyModule_AddIntMacro(m, P_PID)) return -1;
if (PyModule_AddIntMacro(m, P_PGID)) return -1;
if (PyModule_AddIntMacro(m, P_ALL)) return -1;
#endif
#ifdef WEXITED
if (PyModule_AddIntMacro(m, WEXITED)) return -1;
#endif
#ifdef WNOWAIT
if (PyModule_AddIntMacro(m, WNOWAIT)) return -1;
#endif
#ifdef WSTOPPED
if (PyModule_AddIntMacro(m, WSTOPPED)) return -1;
#endif
#ifdef CLD_EXITED
if (PyModule_AddIntMacro(m, CLD_EXITED)) return -1;
#endif
#ifdef CLD_DUMPED
if (PyModule_AddIntMacro(m, CLD_DUMPED)) return -1;
#endif
#ifdef CLD_TRAPPED
if (PyModule_AddIntMacro(m, CLD_TRAPPED)) return -1;
#endif
#ifdef CLD_CONTINUED
if (PyModule_AddIntMacro(m, CLD_CONTINUED)) return -1;
#endif
/* constants for lockf */
#ifdef F_LOCK
if (PyModule_AddIntMacro(m, F_LOCK)) return -1;
#endif
#ifdef F_TLOCK
if (PyModule_AddIntMacro(m, F_TLOCK)) return -1;
#endif
#ifdef F_ULOCK
if (PyModule_AddIntMacro(m, F_ULOCK)) return -1;
#endif
#ifdef F_TEST
if (PyModule_AddIntMacro(m, F_TEST)) return -1;
#endif
#ifdef HAVE_SPAWNV
if (PyModule_AddIntConstant(m, "P_WAIT", _P_WAIT)) return -1;
if (PyModule_AddIntConstant(m, "P_NOWAIT", _P_NOWAIT)) return -1;
if (PyModule_AddIntConstant(m, "P_OVERLAY", _OLD_P_OVERLAY)) return -1;
if (PyModule_AddIntConstant(m, "P_NOWAITO", _P_NOWAITO)) return -1;
if (PyModule_AddIntConstant(m, "P_DETACH", _P_DETACH)) return -1;
#endif
#ifdef HAVE_SCHED_H
if (PyModule_AddIntMacro(m, SCHED_OTHER)) return -1;
if (PyModule_AddIntMacro(m, SCHED_FIFO)) return -1;
if (PyModule_AddIntMacro(m, SCHED_RR)) return -1;
#ifdef SCHED_SPORADIC
if (PyModule_AddIntMacro(m, SCHED_SPORADIC) return -1;
#endif
#ifdef SCHED_BATCH
if (PyModule_AddIntMacro(m, SCHED_BATCH)) return -1;
#endif
#ifdef SCHED_IDLE
if (PyModule_AddIntMacro(m, SCHED_IDLE)) return -1;
#endif
#ifdef SCHED_RESET_ON_FORK
if (PyModule_AddIntMacro(m, SCHED_RESET_ON_FORK)) return -1;
#endif
#ifdef SCHED_SYS
if (PyModule_AddIntMacro(m, SCHED_SYS)) return -1;
#endif
#ifdef SCHED_IA
if (PyModule_AddIntMacro(m, SCHED_IA)) return -1;
#endif
#ifdef SCHED_FSS
if (PyModule_AddIntMacro(m, SCHED_FSS)) return -1;
#endif
#ifdef SCHED_FX
if (PyModule_AddIntConstant(m, "SCHED_FX", SCHED_FSS)) return -1;
#endif
#endif
#ifdef USE_XATTRS
if (PyModule_AddIntMacro(m, XATTR_CREATE)) return -1;
if (PyModule_AddIntMacro(m, XATTR_REPLACE)) return -1;
if (PyModule_AddIntMacro(m, XATTR_SIZE_MAX)) return -1;
#endif
#ifdef RTLD_LAZY
if (PyModule_AddIntMacro(m, RTLD_LAZY)) return -1;
#endif
#ifdef RTLD_NOW
if (PyModule_AddIntMacro(m, RTLD_NOW)) return -1;
#endif
#ifdef RTLD_GLOBAL
if (PyModule_AddIntMacro(m, RTLD_GLOBAL)) return -1;
#endif
#ifdef RTLD_LOCAL
if (PyModule_AddIntMacro(m, RTLD_LOCAL)) return -1;
#endif
#ifdef RTLD_NODELETE
if (PyModule_AddIntMacro(m, RTLD_NODELETE)) return -1;
#endif
#ifdef RTLD_NOLOAD
if (PyModule_AddIntMacro(m, RTLD_NOLOAD)) return -1;
#endif
#ifdef RTLD_DEEPBIND
if (PyModule_AddIntMacro(m, RTLD_DEEPBIND)) return -1;
#endif
return 0;
}
#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
#define INITFUNC PyInit_nt
#define MODNAME "nt"
#else
#define INITFUNC PyInit_posix
#define MODNAME "posix"
#endif
static struct PyModuleDef posixmodule = {
PyModuleDef_HEAD_INIT,
MODNAME,
posix__doc__,
-1,
posix_methods,
NULL,
NULL,
NULL,
NULL
};
static char *have_functions[] = {
#ifdef HAVE_FACCESSAT
"HAVE_FACCESSAT",
#endif
#ifdef HAVE_FCHDIR
"HAVE_FCHDIR",
#endif
#ifdef HAVE_FCHMOD
"HAVE_FCHMOD",
#endif
#ifdef HAVE_FCHMODAT
"HAVE_FCHMODAT",
#endif
#ifdef HAVE_FCHOWN
"HAVE_FCHOWN",
#endif
#ifdef HAVE_FCHOWNAT
"HAVE_FCHOWNAT",
#endif
#ifdef HAVE_FEXECVE
"HAVE_FEXECVE",
#endif
#ifdef HAVE_FDOPENDIR
"HAVE_FDOPENDIR",
#endif
#ifdef HAVE_FPATHCONF
"HAVE_FPATHCONF",
#endif
#ifdef HAVE_FSTATAT
"HAVE_FSTATAT",
#endif
#ifdef HAVE_FSTATVFS
"HAVE_FSTATVFS",
#endif
#ifdef HAVE_FTRUNCATE
"HAVE_FTRUNCATE",
#endif
#ifdef HAVE_FUTIMENS
"HAVE_FUTIMENS",
#endif
#ifdef HAVE_FUTIMES
"HAVE_FUTIMES",
#endif
#ifdef HAVE_FUTIMESAT
"HAVE_FUTIMESAT",
#endif
#ifdef HAVE_LINKAT
"HAVE_LINKAT",
#endif
#ifdef HAVE_LCHFLAGS
"HAVE_LCHFLAGS",
#endif
#ifdef HAVE_LCHMOD
"HAVE_LCHMOD",
#endif
#ifdef HAVE_LCHOWN
"HAVE_LCHOWN",
#endif
#ifdef HAVE_LSTAT
"HAVE_LSTAT",
#endif
#ifdef HAVE_LUTIMES
"HAVE_LUTIMES",
#endif
#ifdef HAVE_MKDIRAT
"HAVE_MKDIRAT",
#endif
#ifdef HAVE_MKFIFOAT
"HAVE_MKFIFOAT",
#endif
#ifdef HAVE_MKNODAT
"HAVE_MKNODAT",
#endif
#ifdef HAVE_OPENAT
"HAVE_OPENAT",
#endif
#ifdef HAVE_READLINKAT
"HAVE_READLINKAT",
#endif
#ifdef HAVE_RENAMEAT
"HAVE_RENAMEAT",
#endif
#ifdef HAVE_SYMLINKAT
"HAVE_SYMLINKAT",
#endif
#ifdef HAVE_UNLINKAT
"HAVE_UNLINKAT",
#endif
#ifdef HAVE_UTIMENSAT
"HAVE_UTIMENSAT",
#endif
#ifdef MS_WINDOWS
"MS_WINDOWS",
#endif
NULL
};
PyMODINIT_FUNC
INITFUNC(void)
{
PyObject *m, *v;
PyObject *list;
char **trace;
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
win32_can_symlink = enable_symlink();
#endif
m = PyModule_Create(&posixmodule);
if (m == NULL)
return NULL;
/* Initialize environ dictionary */
v = convertenviron();
Py_XINCREF(v);
if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
return NULL;
Py_DECREF(v);
if (all_ins(m))
return NULL;
if (setup_confname_tables(m))
return NULL;
Py_INCREF(PyExc_OSError);
PyModule_AddObject(m, "error", PyExc_OSError);
#ifdef HAVE_PUTENV
if (posix_putenv_garbage == NULL)
posix_putenv_garbage = PyDict_New();
#endif
if (!initialized) {
#if defined(HAVE_WAITID) && !defined(__APPLE__)
waitid_result_desc.name = MODNAME ".waitid_result";
if (PyStructSequence_InitType2(&WaitidResultType, &waitid_result_desc) < 0)
return NULL;
#endif
stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
if (PyStructSequence_InitType2(&StatResultType, &stat_result_desc) < 0)
return NULL;
structseq_new = StatResultType.tp_new;
StatResultType.tp_new = statresult_new;
statvfs_result_desc.name = "os.statvfs_result"; /* see issue #19209 */
if (PyStructSequence_InitType2(&StatVFSResultType,
&statvfs_result_desc) < 0)
return NULL;
#ifdef NEED_TICKS_PER_SECOND
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
ticks_per_second = sysconf(_SC_CLK_TCK);
# elif defined(HZ)
ticks_per_second = HZ;
# else
ticks_per_second = 60; /* magic fallback value; may be bogus */
# endif
#endif
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
sched_param_desc.name = MODNAME ".sched_param";
if (PyStructSequence_InitType2(&SchedParamType, &sched_param_desc) < 0)
return NULL;
SchedParamType.tp_new = os_sched_param;
#endif
/* initialize TerminalSize_info */
if (PyStructSequence_InitType2(&TerminalSizeType,
&TerminalSize_desc) < 0)
return NULL;
}
#if defined(HAVE_WAITID) && !defined(__APPLE__)
Py_INCREF((PyObject*) &WaitidResultType);
PyModule_AddObject(m, "waitid_result", (PyObject*) &WaitidResultType);
#endif
Py_INCREF((PyObject*) &StatResultType);
PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
Py_INCREF((PyObject*) &StatVFSResultType);
PyModule_AddObject(m, "statvfs_result",
(PyObject*) &StatVFSResultType);
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
Py_INCREF(&SchedParamType);
PyModule_AddObject(m, "sched_param", (PyObject *)&SchedParamType);
#endif
times_result_desc.name = MODNAME ".times_result";
if (PyStructSequence_InitType2(&TimesResultType, ×_result_desc) < 0)
return NULL;
PyModule_AddObject(m, "times_result", (PyObject *)&TimesResultType);
uname_result_desc.name = MODNAME ".uname_result";
if (PyStructSequence_InitType2(&UnameResultType, &uname_result_desc) < 0)
return NULL;
PyModule_AddObject(m, "uname_result", (PyObject *)&UnameResultType);
#ifdef __APPLE__
/*
* Step 2 of weak-linking support on Mac OS X.
*
* The code below removes functions that are not available on the
* currently active platform.
*
* This block allow one to use a python binary that was build on
* OSX 10.4 on OSX 10.3, without losing access to new APIs on
* OSX 10.4.
*/
#ifdef HAVE_FSTATVFS
if (fstatvfs == NULL) {
if (PyObject_DelAttrString(m, "fstatvfs") == -1) {
return NULL;
}
}
#endif /* HAVE_FSTATVFS */
#ifdef HAVE_STATVFS
if (statvfs == NULL) {
if (PyObject_DelAttrString(m, "statvfs") == -1) {
return NULL;
}
}
#endif /* HAVE_STATVFS */
# ifdef HAVE_LCHOWN
if (lchown == NULL) {
if (PyObject_DelAttrString(m, "lchown") == -1) {
return NULL;
}
}
#endif /* HAVE_LCHOWN */
#endif /* __APPLE__ */
Py_INCREF(&TerminalSizeType);
PyModule_AddObject(m, "terminal_size", (PyObject*) &TerminalSizeType);
billion = PyLong_FromLong(1000000000);
if (!billion)
return NULL;
/* suppress "function not used" warnings */
{
int ignored;
fd_specified("", -1);
follow_symlinks_specified("", 1);
dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1);
dir_fd_converter(Py_None, &ignored);
dir_fd_unavailable(Py_None, &ignored);
}
/*
* provide list of locally available functions
* so os.py can populate support_* lists
*/
list = PyList_New(0);
if (!list)
return NULL;
for (trace = have_functions; *trace; trace++) {
PyObject *unicode = PyUnicode_DecodeASCII(*trace, strlen(*trace), NULL);
if (!unicode)
return NULL;
if (PyList_Append(list, unicode))
return NULL;
Py_DECREF(unicode);
}
PyModule_AddObject(m, "_have_functions", list);
initialized = 1;
return m;
}
#ifdef __cplusplus
}
#endif
|