summaryrefslogtreecommitdiffstats
path: root/cd42728d67ca5146e7903e00e7593e216c80fecb.patch
blob: d8bf69b6ed078b3b9adeef1c81daffa3901215ba (plain)
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
From cd42728d67ca5146e7903e00e7593e216c80fecb Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Wed, 22 May 2019 10:23:49 +0200
Subject: [PATCH] fix build with 7.4

---
 config.m4          |   41 +-
 package.xml        |    7 +-
 php74/php_zip.c    | 3158 ++++++++++++++++++++++++++++++++++++++++++++
 php74/php_zip.h    |   82 ++
 php74/zip_stream.c |  370 ++++++
 5 files changed, 3629 insertions(+), 29 deletions(-)
 create mode 100644 php74/php_zip.c
 create mode 100644 php74/php_zip.h
 create mode 100644 php74/zip_stream.c

diff --git a/config.m4 b/config.m4
index 8edcc90..e5d3c59 100644
--- a/config.m4
+++ b/config.m4
@@ -10,37 +10,22 @@ PHP_ARG_WITH(libzip, libzip,
 
 if test "$PHP_ZIP" != "no"; then
 
+  PHP_VERSION=$($PHP_CONFIG --vernum)
   AC_MSG_CHECKING(PHP version)
-  if test -d $abs_srcdir/php7 ; then
-    dnl # only when for PECL, not for PHP
-    export OLD_CPPFLAGS="$CPPFLAGS"
-    export CPPFLAGS="$CPPFLAGS $INCLUDES"
-    AC_TRY_COMPILE([#include <php_version.h>], [
-#if PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 3
-#error  PHP >= 7.3
-#endif
-    ], [
-      AC_TRY_COMPILE([#include <php_version.h>], [
-#if PHP_MAJOR_VERSION > 5
-#error  PHP > 5
-#endif
-      ], [
-        subdir=php5
-        AC_MSG_RESULT([PHP 5.x])
-      ], [
-        subdir=php7
-        AC_MSG_RESULT([PHP 7.0 - 7.2])
-      ])
-    ], [
-      subdir=php73
-      AC_MSG_RESULT([PHP >= 7.3])
-    ])
-    export CPPFLAGS="$OLD_CPPFLAGS"
-    PHP_ZIP_SOURCES="$subdir/php_zip.c $subdir/zip_stream.c"
+  if test $PHP_VERSION -lt 70000; then
+    AC_MSG_RESULT(5.x)
+    subdir=php5
+  elif test $PHP_VERSION -lt 70300; then
+    AC_MSG_RESULT(7.0/7.1/7.2)
+    subdir=php7
+  elif test $PHP_VERSION -lt 70400; then
+    AC_MSG_RESULT(7.3)
+    subdir=php73
   else
-    AC_MSG_ERROR([unknown])
-    PHP_ZIP_SOURCES="php_zip.c zip_stream.c"
+    AC_MSG_RESULT(7.4)
+    subdir=php74
   fi
+  PHP_ZIP_SOURCES="$subdir/php_zip.c $subdir/zip_stream.c"
 
   if test "$PHP_LIBZIP" != "no"; then
 
diff --git a/php74/php_zip.c b/php74/php_zip.c
new file mode 100644
index 0000000..df3eade
--- /dev/null
+++ b/php74/php_zip.c
@@ -0,0 +1,3158 @@
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 7                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) The PHP Group                                          |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.01 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available through the world-wide-web at the following url:           |
+  | http://www.php.net/license/3_01.txt.                                 |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Piere-Alain Joye <pierre@php.net>                            |
+  +----------------------------------------------------------------------+
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "ext/standard/file.h"
+#include "ext/standard/php_string.h"
+#include "ext/pcre/php_pcre.h"
+#include "ext/standard/php_filestat.h"
+#include "zend_interfaces.h"
+#include "php_zip.h"
+
+/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
+static PHP_NAMED_FUNCTION(zif_zip_open);
+static PHP_NAMED_FUNCTION(zif_zip_read);
+static PHP_NAMED_FUNCTION(zif_zip_close);
+static PHP_NAMED_FUNCTION(zif_zip_entry_read);
+static PHP_NAMED_FUNCTION(zif_zip_entry_filesize);
+static PHP_NAMED_FUNCTION(zif_zip_entry_name);
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize);
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod);
+static PHP_NAMED_FUNCTION(zif_zip_entry_open);
+static PHP_NAMED_FUNCTION(zif_zip_entry_close);
+
+#ifdef HAVE_GLOB
+#ifndef PHP_WIN32
+#include <glob.h>
+#else
+#include "win32/glob.h"
+#endif
+#endif
+
+/* {{{ Resource le */
+static int le_zip_dir;
+#define le_zip_dir_name "Zip Directory"
+static int le_zip_entry;
+#define le_zip_entry_name "Zip Entry"
+/* }}} */
+
+/* {{{ PHP_ZIP_STAT_INDEX(za, index, flags, sb) */
+#define PHP_ZIP_STAT_INDEX(za, index, flags, sb) \
+	if (zip_stat_index(za, index, flags, &sb) != 0) { \
+		RETURN_FALSE; \
+	}
+/* }}} */
+
+/* {{{  PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) */
+#define PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) \
+	if (path_len < 1) { \
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); \
+		RETURN_FALSE; \
+	} \
+	if (zip_stat(za, path, flags, &sb) != 0) { \
+		RETURN_FALSE; \
+	}
+/* }}} */
+
+/* {{{ PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) */
+#define PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) \
+	if (comment_len == 0) { \
+		/* Passing NULL remove the existing comment */ \
+		if (zip_set_file_comment(za, index, NULL, 0) < 0) { \
+			RETURN_FALSE; \
+		} \
+	} else if (zip_set_file_comment(za, index, comment, comment_len) < 0) { \
+		RETURN_FALSE; \
+	} \
+	RETURN_TRUE;
+/* }}} */
+
+# define add_ascii_assoc_string add_assoc_string
+# define add_ascii_assoc_long add_assoc_long
+
+/* Flatten a path by making a relative path (to .)*/
+static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
+{
+	char *path_begin = path;
+	size_t i;
+
+	if (path_len < 1 || path == NULL) {
+		return NULL;
+	}
+
+	if (IS_SLASH(path[0])) {
+		return path + 1;
+	}
+
+	i = path_len;
+
+	while (1) {
+		while (i > 0 && !IS_SLASH(path[i])) {
+			i--;
+		}
+
+		if (!i) {
+			return path;
+		}
+
+		if (i >= 2 && (path[i -1] == '.' || path[i -1] == ':')) {
+			/* i is the position of . or :, add 1 for / */
+			path_begin = path + i + 1;
+			break;
+		}
+		i--;
+	}
+
+	return path_begin;
+}
+/* }}} */
+
+# define CWD_STATE_ALLOC(l) emalloc(l)
+# define CWD_STATE_FREE(s)  efree(s)
+
+/* {{{ php_zip_extract_file */
+static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t file_len)
+{
+	php_stream_statbuf ssb;
+	struct zip_file *zf;
+	struct zip_stat sb;
+	char b[8192];
+	int n, ret;
+	php_stream *stream;
+	char *fullpath;
+	char *file_dirname_fullpath;
+	char file_dirname[MAXPATHLEN];
+	size_t dir_len, len;
+	int is_dir_only = 0;
+	char *path_cleaned;
+	size_t path_cleaned_len;
+	cwd_state new_state;
+	zend_string *file_basename;
+
+	new_state.cwd = CWD_STATE_ALLOC(1);
+	new_state.cwd[0] = '\0';
+	new_state.cwd_length = 0;
+
+	/* Clean/normlize the path and then transform any path (absolute or relative)
+		 to a path relative to cwd (../../mydir/foo.txt > mydir/foo.txt)
+	 */
+	virtual_file_ex(&new_state, file, NULL, CWD_EXPAND);
+	path_cleaned =  php_zip_make_relative_path(new_state.cwd, new_state.cwd_length);
+	if(!path_cleaned) {
+		return 0;
+	}
+	path_cleaned_len = strlen(path_cleaned);
+
+	if (path_cleaned_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb) != 0) {
+		return 0;
+	}
+
+	/* it is a directory only, see #40228 */
+	if (path_cleaned_len > 1 && IS_SLASH(path_cleaned[path_cleaned_len - 1])) {
+		len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, path_cleaned);
+		is_dir_only = 1;
+	} else {
+		memcpy(file_dirname, path_cleaned, path_cleaned_len);
+		dir_len = php_dirname(file_dirname, path_cleaned_len);
+
+		if (!dir_len || (dir_len == 1 && file_dirname[0] == '.')) {
+			len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
+		} else {
+			len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);
+		}
+
+		file_basename =	php_basename(path_cleaned, path_cleaned_len, NULL, 0);
+
+		if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname_fullpath)) {
+			efree(file_dirname_fullpath);
+			zend_string_release_ex(file_basename, 0);
+			CWD_STATE_FREE(new_state.cwd);
+			return 0;
+		}
+	}
+
+	/* let see if the path already exists */
+	if (php_stream_stat_path_ex(file_dirname_fullpath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
+		ret = php_stream_mkdir(file_dirname_fullpath, 0777,  PHP_STREAM_MKDIR_RECURSIVE|REPORT_ERRORS, NULL);
+		if (!ret) {
+			efree(file_dirname_fullpath);
+			if (!is_dir_only) {
+				zend_string_release_ex(file_basename, 0);
+				CWD_STATE_FREE(new_state.cwd);
+			}
+			return 0;
+		}
+	}
+
+	/* it is a standalone directory, job done */
+	if (is_dir_only) {
+		efree(file_dirname_fullpath);
+		CWD_STATE_FREE(new_state.cwd);
+		return 1;
+	}
+
+	len = spprintf(&fullpath, 0, "%s/%s", file_dirname_fullpath, ZSTR_VAL(file_basename));
+	if (!len) {
+		efree(file_dirname_fullpath);
+		zend_string_release_ex(file_basename, 0);
+		CWD_STATE_FREE(new_state.cwd);
+		return 0;
+	} else if (len > MAXPATHLEN) {
+		php_error_docref(NULL, E_WARNING, "Full extraction path exceed MAXPATHLEN (%i)", MAXPATHLEN);
+		efree(file_dirname_fullpath);
+		zend_string_release_ex(file_basename, 0);
+		CWD_STATE_FREE(new_state.cwd);
+		return 0;
+	}
+
+	/* check again the full path, not sure if it
+	 * is required, does a file can have a different
+	 * safemode status as its parent folder?
+	 */
+	if (ZIP_OPENBASEDIR_CHECKPATH(fullpath)) {
+		efree(fullpath);
+		efree(file_dirname_fullpath);
+		zend_string_release_ex(file_basename, 0);
+		CWD_STATE_FREE(new_state.cwd);
+		return 0;
+	}
+
+	zf = zip_fopen(za, file, 0);
+	if (zf == NULL) {
+		n = -1;
+		goto done;
+	}
+
+	stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
+
+	if (stream == NULL) {
+		n = -1;
+		zip_fclose(zf);
+		goto done;
+	}
+
+	n = 0;
+
+	while ((n=zip_fread(zf, b, sizeof(b))) > 0) {
+		php_stream_write(stream, b, n);
+	}
+
+	php_stream_close(stream);
+	n = zip_fclose(zf);
+
+done:
+	efree(fullpath);
+	zend_string_release_ex(file_basename, 0);
+	efree(file_dirname_fullpath);
+	CWD_STATE_FREE(new_state.cwd);
+
+	if (n<0) {
+		return 0;
+	} else {
+		return 1;
+	}
+}
+/* }}} */
+
+static int php_zip_add_file(struct zip *za, const char *filename, size_t filename_len,
+	char *entry_name, size_t entry_name_len, long offset_start, long offset_len) /* {{{ */
+{
+	struct zip_source *zs;
+	char resolved_path[MAXPATHLEN];
+	zval exists_flag;
+
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(filename)) {
+		return -1;
+	}
+
+	if (!expand_filepath(filename, resolved_path)) {
+		return -1;
+	}
+
+	php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag);
+	if (Z_TYPE(exists_flag) == IS_FALSE) {
+		return -1;
+	}
+
+	zs = zip_source_file(za, resolved_path, offset_start, offset_len);
+	if (!zs) {
+		return -1;
+	}
+	if (zip_file_add(za, entry_name, zs, ZIP_FL_OVERWRITE) < 0) {
+		zip_source_free(zs);
+		return -1;
+	} else {
+		zip_error_clear(za);
+		return 1;
+	}
+}
+/* }}} */
+
+static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char **remove_path, size_t *remove_path_len, char **add_path, size_t *add_path_len) /* {{{ */
+{
+	zval *option;
+	if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
+		*remove_all_path = zval_get_long(option);
+	}
+
+	/* If I add more options, it would make sense to create a nice static struct and loop over it. */
+	if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_path", sizeof("remove_path") - 1)) != NULL) {
+		if (Z_TYPE_P(option) != IS_STRING) {
+			php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
+			return -1;
+		}
+
+		if (Z_STRLEN_P(option) < 1) {
+			php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option");
+			return -1;
+		}
+
+		if (Z_STRLEN_P(option) >= MAXPATHLEN) {
+			php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %d, %zd given)",
+						MAXPATHLEN - 1, Z_STRLEN_P(option));
+			return -1;
+		}
+		*remove_path_len = Z_STRLEN_P(option);
+		*remove_path = Z_STRVAL_P(option);
+	}
+
+	if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "add_path", sizeof("add_path") - 1)) != NULL) {
+		if (Z_TYPE_P(option) != IS_STRING) {
+			php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
+			return -1;
+		}
+
+		if (Z_STRLEN_P(option) < 1) {
+			php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option");
+			return -1;
+		}
+
+		if (Z_STRLEN_P(option) >= MAXPATHLEN) {
+			php_error_docref(NULL, E_WARNING, "add_path string too long (max: %d, %zd given)",
+						MAXPATHLEN - 1, Z_STRLEN_P(option));
+			return -1;
+		}
+		*add_path_len = Z_STRLEN_P(option);
+		*add_path = Z_STRVAL_P(option);
+	}
+	return 1;
+}
+/* }}} */
+
+/* {{{ REGISTER_ZIP_CLASS_CONST_LONG */
+#define REGISTER_ZIP_CLASS_CONST_LONG(const_name, value) \
+	    zend_declare_class_constant_long(zip_class_entry, const_name, sizeof(const_name)-1, (zend_long)value);
+/* }}} */
+
+/* {{{ ZIP_FROM_OBJECT */
+#define ZIP_FROM_OBJECT(intern, object) \
+	{ \
+		ze_zip_object *obj = Z_ZIP_P(object); \
+		intern = obj->za; \
+		if (!intern) { \
+			php_error_docref(NULL, E_WARNING, "Invalid or uninitialized Zip object"); \
+			RETURN_FALSE; \
+		} \
+	}
+/* }}} */
+
+/* {{{ RETURN_SB(sb) */
+#ifdef HAVE_ENCRYPTION
+#define RETURN_SB(sb) \
+	{ \
+		array_init(return_value); \
+		add_ascii_assoc_string(return_value, "name", (char *)(sb)->name); \
+		add_ascii_assoc_long(return_value, "index", (zend_long) (sb)->index); \
+		add_ascii_assoc_long(return_value, "crc", (zend_long) (sb)->crc); \
+		add_ascii_assoc_long(return_value, "size", (zend_long) (sb)->size); \
+		add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
+		add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
+		add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
+		add_ascii_assoc_long(return_value, "encryption_method", (zend_long) (sb)->encryption_method); \
+	}
+#else
+#define RETURN_SB(sb) \
+	{ \
+		array_init(return_value); \
+		add_ascii_assoc_string(return_value, "name", (char *)(sb)->name); \
+		add_ascii_assoc_long(return_value, "index", (zend_long) (sb)->index); \
+		add_ascii_assoc_long(return_value, "crc", (zend_long) (sb)->crc); \
+		add_ascii_assoc_long(return_value, "size", (zend_long) (sb)->size); \
+		add_ascii_assoc_long(return_value, "mtime", (zend_long) (sb)->mtime); \
+		add_ascii_assoc_long(return_value, "comp_size", (zend_long) (sb)->comp_size); \
+		add_ascii_assoc_long(return_value, "comp_method", (zend_long) (sb)->comp_method); \
+	}
+#endif
+/* }}} */
+
+static int php_zip_status(struct zip *za) /* {{{ */
+{
+#if LIBZIP_VERSION_MAJOR < 1
+	int zep, syp;
+
+	zip_error_get(za, &zep, &syp);
+#else
+	int zep;
+	zip_error_t *err;
+
+	err = zip_get_error(za);
+	zep = zip_error_code_zip(err);
+	zip_error_fini(err);
+#endif
+	return zep;
+}
+/* }}} */
+
+static int php_zip_status_sys(struct zip *za) /* {{{ */
+{
+#if LIBZIP_VERSION_MAJOR < 1
+	int zep, syp;
+
+	zip_error_get(za, &zep, &syp);
+#else
+	int syp;
+	zip_error_t *err;
+
+	err = zip_get_error(za);
+	syp = zip_error_code_system(err);
+	zip_error_fini(err);
+#endif
+	return syp;
+}
+/* }}} */
+
+static int php_zip_get_num_files(struct zip *za) /* {{{ */
+{
+	return zip_get_num_files(za);
+}
+/* }}} */
+
+static char * php_zipobj_get_filename(ze_zip_object *obj) /* {{{ */
+{
+
+	if (!obj) {
+		return NULL;
+	}
+
+	if (obj->filename) {
+		return obj->filename;
+	}
+	return NULL;
+}
+/* }}} */
+
+static char * php_zipobj_get_zip_comment(struct zip *za, int *len) /* {{{ */
+{
+	if (za) {
+		return (char *)zip_get_archive_comment(za, len, 0);
+	}
+	return NULL;
+}
+/* }}} */
+
+#ifdef HAVE_GLOB /* {{{ */
+#ifndef GLOB_ONLYDIR
+#define GLOB_ONLYDIR (1<<30)
+#define GLOB_EMULATE_ONLYDIR
+#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
+#else
+#define GLOB_FLAGMASK (~0)
+#endif
+#ifndef GLOB_BRACE
+# define GLOB_BRACE 0
+#endif
+#ifndef GLOB_MARK
+# define GLOB_MARK 0
+#endif
+#ifndef GLOB_NOSORT
+# define GLOB_NOSORT 0
+#endif
+#ifndef GLOB_NOCHECK
+# define GLOB_NOCHECK 0
+#endif
+#ifndef GLOB_NOESCAPE
+# define GLOB_NOESCAPE 0
+#endif
+#ifndef GLOB_ERR
+# define GLOB_ERR 0
+#endif
+
+/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
+#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
+
+#endif /* }}} */
+
+int php_zip_glob(char *pattern, int pattern_len, zend_long flags, zval *return_value) /* {{{ */
+{
+#ifdef HAVE_GLOB
+	char cwd[MAXPATHLEN];
+	int cwd_skip = 0;
+#ifdef ZTS
+	char work_pattern[MAXPATHLEN];
+	char *result;
+#endif
+	glob_t globbuf;
+	size_t n;
+	int ret;
+
+	if (pattern_len >= MAXPATHLEN) {
+		php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
+		return -1;
+	}
+
+	if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
+		php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
+		return -1;
+	}
+
+#ifdef ZTS
+	if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
+		result = VCWD_GETCWD(cwd, MAXPATHLEN);
+		if (!result) {
+			cwd[0] = '\0';
+		}
+#ifdef PHP_WIN32
+		if (IS_SLASH(*pattern)) {
+			cwd[2] = '\0';
+		}
+#endif
+		cwd_skip = strlen(cwd)+1;
+
+		snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
+		pattern = work_pattern;
+	}
+#endif
+
+	globbuf.gl_offs = 0;
+	if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
+#ifdef GLOB_NOMATCH
+		if (GLOB_NOMATCH == ret) {
+			/* Some glob implementation simply return no data if no matches
+			   were found, others return the GLOB_NOMATCH error code.
+			   We don't want to treat GLOB_NOMATCH as an error condition
+			   so that PHP glob() behaves the same on both types of
+			   implementations and so that 'foreach (glob() as ...'
+			   can be used for simple glob() calls without further error
+			   checking.
+			*/
+			array_init(return_value);
+			return 0;
+		}
+#endif
+		return 0;
+	}
+
+	/* now catch the FreeBSD style of "no matches" */
+	if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
+		array_init(return_value);
+		return 0;
+	}
+
+	/* we assume that any glob pattern will match files from one directory only
+	   so checking the dirname of the first match should be sufficient */
+	strncpy(cwd, globbuf.gl_pathv[0], MAXPATHLEN);
+	if (ZIP_OPENBASEDIR_CHECKPATH(cwd)) {
+		return -1;
+	}
+
+	array_init(return_value);
+	for (n = 0; n < globbuf.gl_pathc; n++) {
+		/* we need to do this every time since GLOB_ONLYDIR does not guarantee that
+		 * all directories will be filtered. GNU libc documentation states the
+		 * following:
+		 * If the information about the type of the file is easily available
+		 * non-directories will be rejected but no extra work will be done to
+		 * determine the information for each file. I.e., the caller must still be
+		 * able to filter directories out.
+		 */
+		if (flags & GLOB_ONLYDIR) {
+			zend_stat_t s;
+
+			if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
+				continue;
+			}
+
+			if (S_IFDIR != (s.st_mode & S_IFMT)) {
+				continue;
+			}
+		}
+		add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip);
+	}
+
+	globfree(&globbuf);
+	return globbuf.gl_pathc;
+#else
+	zend_throw_error(NULL, "Glob support is not available");
+	return 0;
+#endif  /* HAVE_GLOB */
+}
+/* }}} */
+
+int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_value) /* {{{ */
+{
+#ifdef ZTS
+	char cwd[MAXPATHLEN];
+	char work_path[MAXPATHLEN];
+	char *result;
+#endif
+	int files_cnt;
+	zend_string **namelist;
+	pcre2_match_context *mctx = php_pcre_mctx();
+
+#ifdef ZTS
+	if (!IS_ABSOLUTE_PATH(path, path_len)) {
+		result = VCWD_GETCWD(cwd, MAXPATHLEN);
+		if (!result) {
+			cwd[0] = '\0';
+		}
+#ifdef PHP_WIN32
+		if (IS_SLASH(*path)) {
+			cwd[2] = '\0';
+		}
+#endif
+		snprintf(work_path, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, path);
+		path = work_path;
+	}
+#endif
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(path)) {
+		return -1;
+	}
+
+	files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort);
+
+	if (files_cnt > 0) {
+		pcre2_code *re = NULL;
+		pcre2_match_data *match_data = NULL;
+		uint32_t i, capture_count;
+		int rc;
+
+		re = pcre_get_compiled_regex(regexp, &capture_count);
+		if (!re) {
+			php_error_docref(NULL, E_WARNING, "Invalid expression");
+			return -1;
+		}
+
+		array_init(return_value);
+
+		/* only the files, directories are ignored */
+		for (i = 0; i < files_cnt; i++) {
+			zend_stat_t s;
+			char   fullpath[MAXPATHLEN];
+			size_t    namelist_len = ZSTR_LEN(namelist[i]);
+
+			if ((namelist_len == 1 && ZSTR_VAL(namelist[i])[0] == '.') ||
+				(namelist_len == 2 && ZSTR_VAL(namelist[i])[0] == '.' && ZSTR_VAL(namelist[i])[1] == '.')) {
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
+			if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
+				php_error_docref(NULL, E_WARNING, "add_path string too long (max: %u, %zu given)",
+						MAXPATHLEN - 1, (path_len + namelist_len + 1));
+				zend_string_release_ex(namelist[i], 0);
+				break;
+			}
+
+			snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, ZSTR_VAL(namelist[i]));
+
+			if (0 != VCWD_STAT(fullpath, &s)) {
+				php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath);
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
+			if (S_IFDIR == (s.st_mode & S_IFMT)) {
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
+			match_data = php_pcre_create_match_data(capture_count, re);
+			if (!match_data) {
+				/* Allocation failed, but can proceed to the next pattern. */
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+			rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, 0, match_data, mctx);
+			php_pcre_free_match_data(match_data);
+			/* 0 means that the vector is too small to hold all the captured substring offsets */
+			if (rc < 0) {
+				zend_string_release_ex(namelist[i], 0);
+				continue;
+			}
+
+			add_next_index_string(return_value, fullpath);
+			zend_string_release_ex(namelist[i], 0);
+		}
+		efree(namelist);
+	}
+	return files_cnt;
+}
+/* }}} */
+
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_open, 0, 0, 1)
+	ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_close, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_read, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_open, 0, 0, 2)
+	ZEND_ARG_INFO(0, zip_dp)
+	ZEND_ARG_INFO(0, zip_entry)
+	ZEND_ARG_INFO(0, mode)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_close, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_ent)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_read, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_entry)
+	ZEND_ARG_INFO(0, len)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_name, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressedsize, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_filesize, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_entry_compressionmethod, 0, 0, 1)
+	ZEND_ARG_INFO(0, zip_entry)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+/* {{{ zend_function_entry */
+static const zend_function_entry zip_functions[] = {
+	ZEND_RAW_FENTRY("zip_open", zif_zip_open, arginfo_zip_open, 0)
+	ZEND_RAW_FENTRY("zip_close", zif_zip_close, arginfo_zip_close, 0)
+	ZEND_RAW_FENTRY("zip_read", zif_zip_read, arginfo_zip_read, 0)
+	PHP_FE(zip_entry_open,		arginfo_zip_entry_open)
+	PHP_FE(zip_entry_close,		arginfo_zip_entry_close)
+	PHP_FE(zip_entry_read,		arginfo_zip_entry_read)
+	PHP_FE(zip_entry_filesize,	arginfo_zip_entry_filesize)
+	PHP_FE(zip_entry_name,		arginfo_zip_entry_name)
+	PHP_FE(zip_entry_compressedsize,		arginfo_zip_entry_compressedsize)
+	PHP_FE(zip_entry_compressionmethod,		arginfo_zip_entry_compressionmethod)
+#ifdef  PHP_FE_END
+	PHP_FE_END
+#else
+	{NULL,NULL,NULL}
+#endif
+};
+/* }}} */
+
+/* {{{ ZE2 OO definitions */
+static zend_class_entry *zip_class_entry;
+static zend_object_handlers zip_object_handlers;
+
+static HashTable zip_prop_handlers;
+
+typedef int (*zip_read_int_t)(struct zip *za);
+typedef char *(*zip_read_const_char_t)(struct zip *za, int *len);
+typedef char *(*zip_read_const_char_from_ze_t)(ze_zip_object *obj);
+
+typedef struct _zip_prop_handler {
+	zip_read_int_t read_int_func;
+	zip_read_const_char_t read_const_char_func;
+	zip_read_const_char_from_ze_t read_const_char_from_obj_func;
+
+	int type;
+} zip_prop_handler;
+/* }}} */
+
+static void php_zip_register_prop_handler(HashTable *prop_handler, char *name, zip_read_int_t read_int_func, zip_read_const_char_t read_char_func, zip_read_const_char_from_ze_t read_char_from_obj_func, int rettype) /* {{{ */
+{
+	zip_prop_handler hnd;
+	zend_string *str;
+	zval tmp;
+
+	hnd.read_const_char_func = read_char_func;
+	hnd.read_int_func = read_int_func;
+	hnd.read_const_char_from_obj_func = read_char_from_obj_func;
+	hnd.type = rettype;
+	str = zend_string_init_interned(name, strlen(name), 1);
+	zend_hash_add_mem(prop_handler, str, &hnd, sizeof(zip_prop_handler));
+
+	/* Register for reflection */
+	ZVAL_NULL(&tmp);
+	zend_declare_property_ex(zip_class_entry, str, &tmp, ZEND_ACC_PUBLIC, NULL);
+	zend_string_release_ex(str, 1);
+}
+/* }}} */
+
+static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval *rv) /* {{{ */
+{
+	const char *retchar = NULL;
+	int retint = 0;
+	int len = 0;
+
+	if (obj && obj->za != NULL) {
+		if (hnd->read_const_char_func) {
+			retchar = hnd->read_const_char_func(obj->za, &len);
+		} else {
+			if (hnd->read_int_func) {
+				retint = hnd->read_int_func(obj->za);
+				if (retint == -1) {
+					php_error_docref(NULL, E_WARNING, "Internal zip error returned");
+					return NULL;
+				}
+			} else {
+				if (hnd->read_const_char_from_obj_func) {
+					retchar = hnd->read_const_char_from_obj_func(obj);
+					len = strlen(retchar);
+				}
+			}
+		}
+	}
+
+	switch (hnd->type) {
+		case IS_STRING:
+			if (retchar) {
+				ZVAL_STRINGL(rv, (char *) retchar, len);
+			} else {
+				ZVAL_EMPTY_STRING(rv);
+			}
+			break;
+		/* case IS_TRUE */
+		case IS_FALSE:
+			ZVAL_BOOL(rv, (long)retint);
+			break;
+		case IS_LONG:
+			ZVAL_LONG(rv, (long)retint);
+			break;
+		default:
+			ZVAL_NULL(rv);
+	}
+
+	return rv;
+}
+/* }}} */
+
+static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
+{
+	ze_zip_object *obj;
+	zval tmp_member;
+	zval *retval = NULL;
+	zip_prop_handler *hnd = NULL;
+
+	if (Z_TYPE_P(member) != IS_STRING) {
+		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		member = &tmp_member;
+		cache_slot = NULL;
+	}
+
+	obj = Z_ZIP_P(object);
+
+	if (obj->prop_handler != NULL) {
+		hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
+	}
+
+	if (hnd == NULL) {
+		retval = zend_std_get_property_ptr_ptr(object, member, type, cache_slot);
+	}
+
+	if (member == &tmp_member) {
+		zval_ptr_dtor_str(&tmp_member);
+	}
+
+	return retval;
+}
+/* }}} */
+
+static zval *php_zip_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
+{
+	ze_zip_object *obj;
+	zval tmp_member;
+	zval *retval = NULL;
+	zip_prop_handler *hnd = NULL;
+
+	if (Z_TYPE_P(member) != IS_STRING) {
+		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		member = &tmp_member;
+		cache_slot = NULL;
+	}
+
+	obj = Z_ZIP_P(object);
+
+	if (obj->prop_handler != NULL) {
+		hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
+	}
+
+	if (hnd != NULL) {
+		retval = php_zip_property_reader(obj, hnd, rv);
+		if (retval == NULL) {
+			retval = &EG(uninitialized_zval);
+		}
+	} else {
+		retval = zend_std_read_property(object, member, type, cache_slot, rv);
+	}
+
+	if (member == &tmp_member) {
+		zval_ptr_dtor_str(&tmp_member);
+	}
+
+	return retval;
+}
+/* }}} */
+
+static int php_zip_has_property(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
+{
+	ze_zip_object *obj;
+	zval tmp_member;
+	zip_prop_handler *hnd = NULL;
+	int retval = 0;
+
+	if (Z_TYPE_P(member) != IS_STRING) {
+		ZVAL_STR(&tmp_member, zval_get_string_func(member));
+		member = &tmp_member;
+		cache_slot = NULL;
+	}
+
+	obj = Z_ZIP_P(object);
+
+	if (obj->prop_handler != NULL) {
+		hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
+	}
+
+	if (hnd != NULL) {
+		zval tmp, *prop;
+
+		if (type == 2) {
+			retval = 1;
+		} else if ((prop = php_zip_property_reader(obj, hnd, &tmp)) != NULL) {
+			if (type == 1) {
+				retval = zend_is_true(&tmp);
+			} else if (type == 0) {
+				retval = (Z_TYPE(tmp) != IS_NULL);
+			}
+		}
+
+		zval_ptr_dtor(&tmp);
+	} else {
+		retval = zend_std_has_property(object, member, type, cache_slot);
+	}
+
+	if (member == &tmp_member) {
+		zval_ptr_dtor_str(&tmp_member);
+	}
+
+	return retval;
+}
+/* }}} */
+
+static HashTable *php_zip_get_gc(zval *object, zval **gc_data, int *gc_data_count) /* {{{ */
+{
+	*gc_data = NULL;
+	*gc_data_count = 0;
+	return zend_std_get_properties(object);
+}
+/* }}} */
+
+static HashTable *php_zip_get_properties(zval *object)/* {{{ */
+{
+	ze_zip_object *obj;
+	HashTable *props;
+	zip_prop_handler *hnd;
+	zend_string *key;
+
+	obj = Z_ZIP_P(object);
+	props = zend_std_get_properties(object);
+
+	if (obj->prop_handler == NULL) {
+		return NULL;
+	}
+
+	ZEND_HASH_FOREACH_STR_KEY_PTR(obj->prop_handler, key, hnd) {
+		zval *ret, val;
+		ret = php_zip_property_reader(obj, hnd, &val);
+		if (ret == NULL) {
+			ret = &EG(uninitialized_zval);
+		}
+		zend_hash_update(props, key, ret);
+	} ZEND_HASH_FOREACH_END();
+
+	return props;
+}
+/* }}} */
+
+static void php_zip_object_free_storage(zend_object *object) /* {{{ */
+{
+	ze_zip_object * intern = php_zip_fetch_object(object);
+	int i;
+
+	if (!intern) {
+		return;
+	}
+	if (intern->za) {
+		if (zip_close(intern->za) != 0) {
+#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
+			php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: zip_close have failed");
+#else
+			php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za));
+			zip_discard(intern->za);
+#endif
+		}
+	}
+
+	if (intern->buffers_cnt>0) {
+		for (i=0; i<intern->buffers_cnt; i++) {
+			efree(intern->buffers[i]);
+		}
+		efree(intern->buffers);
+	}
+
+	intern->za = NULL;
+	zend_object_std_dtor(&intern->zo);
+
+	if (intern->filename) {
+		efree(intern->filename);
+	}
+}
+/* }}} */
+
+static zend_object *php_zip_object_new(zend_class_entry *class_type) /* {{{ */
+{
+	ze_zip_object *intern;
+
+	intern = zend_object_alloc(sizeof(ze_zip_object), class_type);
+	intern->prop_handler = &zip_prop_handlers;
+	zend_object_std_init(&intern->zo, class_type);
+	object_properties_init(&intern->zo, class_type);
+	intern->zo.handlers = &zip_object_handlers;
+
+	return &intern->zo;
+}
+/* }}} */
+
+/* {{{ Resource dtors */
+
+/* {{{ php_zip_free_dir */
+static void php_zip_free_dir(zend_resource *rsrc)
+{
+	zip_rsrc * zip_int = (zip_rsrc *) rsrc->ptr;
+
+	if (zip_int) {
+		if (zip_int->za) {
+			if (zip_close(zip_int->za) != 0) {
+				php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
+			}
+			zip_int->za = NULL;
+		}
+
+		efree(rsrc->ptr);
+
+		rsrc->ptr = NULL;
+	}
+}
+/* }}} */
+
+/* {{{ php_zip_free_entry */
+static void php_zip_free_entry(zend_resource *rsrc)
+{
+	zip_read_rsrc *zr_rsrc = (zip_read_rsrc *) rsrc->ptr;
+
+	if (zr_rsrc) {
+		if (zr_rsrc->zf) {
+			zip_fclose(zr_rsrc->zf);
+			zr_rsrc->zf = NULL;
+		}
+		efree(zr_rsrc);
+		rsrc->ptr = NULL;
+	}
+}
+/* }}} */
+
+/* }}}*/
+
+/* reset macro */
+
+/* {{{ function prototypes */
+static PHP_MINIT_FUNCTION(zip);
+static PHP_MSHUTDOWN_FUNCTION(zip);
+static PHP_MINFO_FUNCTION(zip);
+/* }}} */
+
+/* {{{ zip_module_entry
+ */
+zend_module_entry zip_module_entry = {
+	STANDARD_MODULE_HEADER,
+	"zip",
+	zip_functions,
+	PHP_MINIT(zip),
+	PHP_MSHUTDOWN(zip),
+	NULL,
+	NULL,
+	PHP_MINFO(zip),
+	PHP_ZIP_VERSION,
+	STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+#ifdef COMPILE_DL_ZIP
+ZEND_GET_MODULE(zip)
+#endif
+/* set macro */
+
+/* {{{ proto resource zip_open(string filename)
+Create new zip using source uri for output */
+static PHP_NAMED_FUNCTION(zif_zip_open)
+{
+	char resolved_path[MAXPATHLEN + 1];
+	zip_rsrc *rsrc_int;
+	int err = 0;
+	zend_string *filename;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
+		return;
+	}
+
+	if (ZSTR_LEN(filename) == 0) {
+		php_error_docref(NULL, E_WARNING, "Empty string as source");
+		RETURN_FALSE;
+	}
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) {
+		RETURN_FALSE;
+	}
+
+	if(!expand_filepath(ZSTR_VAL(filename), resolved_path)) {
+		RETURN_FALSE;
+	}
+
+	rsrc_int = (zip_rsrc *)emalloc(sizeof(zip_rsrc));
+
+	rsrc_int->za = zip_open(resolved_path, 0, &err);
+	if (rsrc_int->za == NULL) {
+		efree(rsrc_int);
+		RETURN_LONG((zend_long)err);
+	}
+
+	rsrc_int->index_current = 0;
+	rsrc_int->num_files = zip_get_num_files(rsrc_int->za);
+
+	RETURN_RES(zend_register_resource(rsrc_int, le_zip_dir));
+}
+/* }}} */
+
+/* {{{ proto void zip_close(resource zip)
+   Close a Zip archive */
+static PHP_NAMED_FUNCTION(zif_zip_close)
+{
+	zval * zip;
+	zip_rsrc *z_rsrc = NULL;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip) == FAILURE) {
+		return;
+	}
+
+	if ((z_rsrc = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip), le_zip_dir_name, le_zip_dir)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	/* really close the zip will break BC :-D */
+	zend_list_close(Z_RES_P(zip));
+}
+/* }}} */
+
+/* {{{ proto resource zip_read(resource zip)
+   Returns the next file in the archive */
+static PHP_NAMED_FUNCTION(zif_zip_read)
+{
+	zval *zip_dp;
+	zip_read_rsrc *zr_rsrc;
+	int ret;
+	zip_rsrc *rsrc_int;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_dp) == FAILURE) {
+		return;
+	}
+
+	if ((rsrc_int = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip_dp), le_zip_dir_name, le_zip_dir)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	if (rsrc_int && rsrc_int->za) {
+		if (rsrc_int->index_current >= rsrc_int->num_files) {
+			RETURN_FALSE;
+		}
+
+		zr_rsrc = emalloc(sizeof(zip_read_rsrc));
+
+		ret = zip_stat_index(rsrc_int->za, rsrc_int->index_current, 0, &zr_rsrc->sb);
+
+		if (ret != 0) {
+			efree(zr_rsrc);
+			RETURN_FALSE;
+		}
+
+		zr_rsrc->zf = zip_fopen_index(rsrc_int->za, rsrc_int->index_current, 0);
+		if (zr_rsrc->zf) {
+			rsrc_int->index_current++;
+			RETURN_RES(zend_register_resource(zr_rsrc, le_zip_entry));
+		} else {
+			efree(zr_rsrc);
+			RETURN_FALSE;
+		}
+
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool zip_entry_open(resource zip_dp, resource zip_entry [, string mode])
+   Open a Zip File, pointed by the resource entry */
+/* Dummy function to follow the old API */
+static PHP_NAMED_FUNCTION(zif_zip_entry_open)
+{
+	zval * zip;
+	zval * zip_entry;
+	char *mode = NULL;
+	size_t mode_len = 0;
+	zip_read_rsrc * zr_rsrc;
+	zip_rsrc *z_rsrc;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr|s", &zip, &zip_entry, &mode, &mode_len) == FAILURE) {
+		return;
+	}
+
+	if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	if ((z_rsrc = (zip_rsrc *)zend_fetch_resource(Z_RES_P(zip), le_zip_dir_name, le_zip_dir)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	if (zr_rsrc->zf != NULL) {
+		RETURN_TRUE;
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool zip_entry_close(resource zip_ent)
+   Close a zip entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_close)
+{
+	zval * zip_entry;
+	zip_read_rsrc * zr_rsrc;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
+		return;
+	}
+
+	if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zip_entry)));
+}
+/* }}} */
+
+/* {{{ proto mixed zip_entry_read(resource zip_entry [, int len])
+   Read from an open directory entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_read)
+{
+	zval * zip_entry;
+	zend_long len = 0;
+	zip_read_rsrc * zr_rsrc;
+	zend_string *buffer;
+	int n = 0;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zip_entry, &len) == FAILURE) {
+		return;
+	}
+
+	if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	if (len <= 0) {
+		len = 1024;
+	}
+
+	if (zr_rsrc->zf) {
+		buffer = zend_string_safe_alloc(1, len, 0, 0);
+		n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
+		if (n > 0) {
+			ZSTR_VAL(buffer)[n] = '\0';
+			ZSTR_LEN(buffer) = n;
+			RETURN_NEW_STR(buffer);
+		} else {
+			zend_string_efree(buffer);
+			RETURN_EMPTY_STRING()
+		}
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ */
+{
+	zval * zip_entry;
+	zip_read_rsrc * zr_rsrc;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zip_entry) == FAILURE) {
+		return;
+	}
+
+	if ((zr_rsrc = (zip_read_rsrc *)zend_fetch_resource(Z_RES_P(zip_entry), le_zip_entry_name, le_zip_entry)) == NULL) {
+		RETURN_FALSE;
+	}
+
+	if (!zr_rsrc->zf) {
+		RETURN_FALSE;
+	}
+
+	switch (opt) {
+		case 0:
+			RETURN_STRING((char *)zr_rsrc->sb.name);
+			break;
+		case 1:
+			RETURN_LONG((zend_long) (zr_rsrc->sb.comp_size));
+			break;
+		case 2:
+			RETURN_LONG((zend_long) (zr_rsrc->sb.size));
+			break;
+		case 3:
+			switch (zr_rsrc->sb.comp_method) {
+				case 0:
+					RETURN_STRING("stored");
+					break;
+				case 1:
+					RETURN_STRING("shrunk");
+					break;
+				case 2:
+				case 3:
+				case 4:
+				case 5:
+					RETURN_STRING("reduced");
+					break;
+				case 6:
+					RETURN_STRING("imploded");
+					break;
+				case 7:
+					RETURN_STRING("tokenized");
+					break;
+				case 8:
+					RETURN_STRING("deflated");
+					break;
+				case 9:
+					RETURN_STRING("deflatedX");
+					break;
+				case 10:
+					RETURN_STRING("implodedX");
+					break;
+				default:
+					RETURN_FALSE;
+			}
+			RETURN_LONG((zend_long) (zr_rsrc->sb.comp_method));
+			break;
+	}
+
+}
+/* }}} */
+
+/* {{{ proto string zip_entry_name(resource zip_entry)
+   Return the name given a ZZip entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_name)
+{
+	php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto int zip_entry_compressedsize(resource zip_entry)
+   Return the compressed size of a ZZip entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressedsize)
+{
+	php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
+/* {{{ proto int zip_entry_filesize(resource zip_entry)
+   Return the actual filesize of a ZZip entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_filesize)
+{
+	php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
+}
+/* }}} */
+
+/* {{{ proto string zip_entry_compressionmethod(resource zip_entry)
+   Return a string containing the compression method used on a particular entry */
+static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
+{
+	php_zip_entry_get_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
+}
+/* }}} */
+
+/* {{{ proto mixed ZipArchive::open(string source [, int flags])
+Create new zip using source uri for output, return TRUE on success or the error code */
+static ZIPARCHIVE_METHOD(open)
+{
+	struct zip *intern;
+	int err = 0;
+	zend_long flags = 0;
+	char *resolved_path;
+	zend_string *filename;
+	zval *self = ZEND_THIS;
+	ze_zip_object *ze_obj;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &filename, &flags) == FAILURE) {
+		return;
+	}
+
+	/* We do not use ZIP_FROM_OBJECT, zip init function here */
+	ze_obj = Z_ZIP_P(self);
+
+	if (ZSTR_LEN(filename) == 0) {
+		php_error_docref(NULL, E_WARNING, "Empty string as source");
+		RETURN_FALSE;
+	}
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) {
+		RETURN_FALSE;
+	}
+
+	if (!(resolved_path = expand_filepath(ZSTR_VAL(filename), NULL))) {
+		RETURN_FALSE;
+	}
+
+	if (ze_obj->za) {
+		/* we already have an opened zip, free it */
+		if (zip_close(ze_obj->za) != 0) {
+			php_error_docref(NULL, E_WARNING, "Empty string as source");
+			efree(resolved_path);
+			RETURN_FALSE;
+		}
+		ze_obj->za = NULL;
+	}
+	if (ze_obj->filename) {
+		efree(ze_obj->filename);
+		ze_obj->filename = NULL;
+	}
+
+	intern = zip_open(resolved_path, flags, &err);
+	if (!intern || err) {
+		efree(resolved_path);
+		RETURN_LONG((zend_long)err);
+	}
+	ze_obj->filename = resolved_path;
+	ze_obj->filename_len = strlen(resolved_path);
+	ze_obj->za = intern;
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto resource ZipArchive::setPassword(string password)
+Set the password for the active archive */
+static ZIPARCHIVE_METHOD(setPassword)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	char *password;
+	size_t	password_len;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) {
+		return;
+	}
+
+	if (password_len < 1) {
+		RETURN_FALSE;
+	} else {
+		int res = zip_set_default_password(intern, (const char *)password);
+		if (res == 0) {
+			RETURN_TRUE;
+		} else {
+			RETURN_FALSE;
+		}
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::close()
+close the zip archive */
+static ZIPARCHIVE_METHOD(close)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	ze_zip_object *ze_obj;
+	int err;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	ze_obj = Z_ZIP_P(self);
+
+	if ((err = zip_close(intern))) {
+#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
+		php_error_docref(NULL, E_WARNING, "zip_close have failed");
+#else
+		php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern));
+		zip_discard(intern);
+#endif
+	}
+
+	efree(ze_obj->filename);
+	ze_obj->filename = NULL;
+	ze_obj->filename_len = 0;
+	ze_obj->za = NULL;
+
+	if (!err) {
+		RETURN_TRUE;
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::count()
+close the zip archive */
+static ZIPARCHIVE_METHOD(count)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	RETVAL_LONG(zip_get_num_files(intern));
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getStatusString()
+ * Returns the status error message, system and/or zip messages */
+static ZIPARCHIVE_METHOD(getStatusString)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+#if LIBZIP_VERSION_MAJOR < 1
+	int zep, syp, len;
+	char error_string[128];
+#else
+	zip_error_t *err;
+#endif
+
+	ZIP_FROM_OBJECT(intern, self);
+
+#if LIBZIP_VERSION_MAJOR < 1
+	zip_error_get(intern, &zep, &syp);
+
+	len = zip_error_to_str(error_string, 128, zep, syp);
+	RETVAL_STRINGL(error_string, len);
+#else
+	err = zip_get_error(intern);
+	RETVAL_STRING(zip_error_strerror(err));
+	zip_error_fini(err);
+#endif
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::createEmptyDir(string dirname)
+Returns the index of the entry named filename in the archive */
+static ZIPARCHIVE_METHOD(addEmptyDir)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	char *dirname;
+	size_t   dirname_len;
+	int idx;
+	struct zip_stat sb;
+	char *s;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
+				&dirname, &dirname_len) == FAILURE) {
+		return;
+	}
+
+	if (dirname_len<1) {
+		RETURN_FALSE;
+	}
+
+	if (dirname[dirname_len-1] != '/') {
+		s=(char *)safe_emalloc(dirname_len, 1, 2);
+		strcpy(s, dirname);
+		s[dirname_len] = '/';
+		s[dirname_len+1] = '\0';
+	} else {
+		s = dirname;
+	}
+
+	idx = zip_stat(intern, s, 0, &sb);
+	if (idx >= 0) {
+		RETVAL_FALSE;
+	} else {
+		if (zip_add_dir(intern, (const char *)s) == -1) {
+			RETVAL_FALSE;
+		}
+		zip_error_clear(intern);
+		RETVAL_TRUE;
+	}
+
+	if (s != dirname) {
+		efree(s);
+	}
+}
+/* }}} */
+
+static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	char *path = ".";
+	char *remove_path = NULL;
+	char *add_path = NULL;
+	size_t  add_path_len, remove_path_len = 0, path_len = 1;
+	zend_long remove_all_path = 0;
+	zend_long flags = 0;
+	zval *options = NULL;
+	int found;
+	zend_string *pattern;
+
+	ZIP_FROM_OBJECT(intern, self);
+	/* 1 == glob, 2 == pcre */
+	if (type == 1) {
+		if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|la",
+					&pattern, &flags, &options) == FAILURE) {
+			return;
+		}
+	} else {
+		if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sa",
+					&pattern, &path, &path_len, &options) == FAILURE) {
+			return;
+		}
+	}
+
+	if (ZSTR_LEN(pattern) == 0) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
+		RETURN_FALSE;
+	}
+	if (options && (php_zip_parse_options(options, &remove_all_path, &remove_path, &remove_path_len,
+			&add_path, &add_path_len) < 0)) {
+		RETURN_FALSE;
+	}
+
+	if (remove_path && remove_path_len > 1) {
+		size_t real_len = strlen(remove_path);
+		if ((real_len > 1) && ((remove_path[real_len - 1] == '/') || (remove_path[real_len - 1] == '\\'))) {
+			remove_path[real_len - 1] = '\0';
+		}
+	}
+
+	if (type == 1) {
+		found = php_zip_glob(ZSTR_VAL(pattern), ZSTR_LEN(pattern), flags, return_value);
+	} else {
+		found = php_zip_pcre(pattern, path, path_len, return_value);
+	}
+
+	if (found > 0) {
+		int i;
+		zval *zval_file;
+
+		for (i = 0; i < found; i++) {
+			char *file_stripped, *entry_name;
+			size_t entry_name_len, file_stripped_len;
+			char entry_name_buf[MAXPATHLEN];
+			zend_string *basename = NULL;
+
+			if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(return_value), i)) != NULL) {
+				if (remove_all_path) {
+					basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
+					file_stripped = ZSTR_VAL(basename);
+					file_stripped_len = ZSTR_LEN(basename);
+				} else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) {
+					file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1;
+					file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1;
+				} else {
+					file_stripped = Z_STRVAL_P(zval_file);
+					file_stripped_len = Z_STRLEN_P(zval_file);
+				}
+
+				if (add_path) {
+					if ((add_path_len + file_stripped_len) > MAXPATHLEN) {
+						php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %zd given)",
+						MAXPATHLEN - 1, (add_path_len + file_stripped_len));
+						zend_array_destroy(Z_ARR_P(return_value));
+						RETURN_FALSE;
+					}
+					snprintf(entry_name_buf, MAXPATHLEN, "%s%s", add_path, file_stripped);
+				} else {
+					snprintf(entry_name_buf, MAXPATHLEN, "%s", file_stripped);
+				}
+
+				entry_name = entry_name_buf;
+				entry_name_len = strlen(entry_name);
+				if (basename) {
+					zend_string_release_ex(basename, 0);
+					basename = NULL;
+				}
+
+				if (php_zip_add_file(intern, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file),
+					entry_name, entry_name_len, 0, 0) < 0) {
+					zend_array_destroy(Z_ARR_P(return_value));
+					RETURN_FALSE;
+				}
+			}
+		}
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::addGlob(string pattern[,int flags [, array options]])
+Add files matching the glob pattern. See php's glob for the pattern syntax. */
+static ZIPARCHIVE_METHOD(addGlob)
+{
+	php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::addPattern(string pattern[, string path [, array options]])
+Add files matching the pcre pattern. See php's pcre for the pattern syntax. */
+static ZIPARCHIVE_METHOD(addPattern)
+{
+	php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::addFile(string filepath[, string entryname[, int start [, int length]]])
+Add a file in a Zip archive using its path and the name to use. */
+static ZIPARCHIVE_METHOD(addFile)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	char *entry_name = NULL;
+	size_t entry_name_len = 0;
+	zend_long offset_start = 0, offset_len = 0;
+	zend_string *filename;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sll",
+			&filename, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) {
+		return;
+	}
+
+	if (ZSTR_LEN(filename) == 0) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as filename");
+		RETURN_FALSE;
+	}
+
+	if (entry_name_len == 0) {
+		entry_name = ZSTR_VAL(filename);
+		entry_name_len = ZSTR_LEN(filename);
+	}
+
+	if (php_zip_add_file(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), entry_name, entry_name_len, 0, 0) < 0) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::addFromString(string name, string content)
+Add a file using content and the entry name */
+static ZIPARCHIVE_METHOD(addFromString)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_string *buffer;
+	char *name;
+	size_t name_len;
+	ze_zip_object *ze_obj;
+	struct zip_source *zs;
+	int pos = 0;
+	int cur_idx;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS",
+			&name, &name_len, &buffer) == FAILURE) {
+		return;
+	}
+
+	ze_obj = Z_ZIP_P(self);
+	if (ze_obj->buffers_cnt) {
+		ze_obj->buffers = (char **)safe_erealloc(ze_obj->buffers, sizeof(char *), (ze_obj->buffers_cnt+1), 0);
+		pos = ze_obj->buffers_cnt++;
+	} else {
+		ze_obj->buffers = (char **)emalloc(sizeof(char *));
+		ze_obj->buffers_cnt++;
+		pos = 0;
+	}
+	ze_obj->buffers[pos] = (char *)safe_emalloc(ZSTR_LEN(buffer), 1, 1);
+	memcpy(ze_obj->buffers[pos], ZSTR_VAL(buffer), ZSTR_LEN(buffer) + 1);
+
+	zs = zip_source_buffer(intern, ze_obj->buffers[pos], ZSTR_LEN(buffer), 0);
+
+	if (zs == NULL) {
+		RETURN_FALSE;
+	}
+
+	cur_idx = zip_name_locate(intern, (const char *)name, 0);
+	/* TODO: fix  _zip_replace */
+	if (cur_idx >= 0) {
+		if (zip_delete(intern, cur_idx) == -1) {
+			zip_source_free(zs);
+			RETURN_FALSE;
+		}
+	}
+
+	if (zip_add(intern, name, zs) == -1) {
+		zip_source_free(zs);
+		RETURN_FALSE;
+	} else {
+		zip_error_clear(intern);
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto array ZipArchive::statName(string filename[, int flags])
+Returns the information about a the zip entry filename */
+static ZIPARCHIVE_METHOD(statName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long flags = 0;
+	struct zip_stat sb;
+	zend_string *name;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
+		return;
+	}
+
+	PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(name), ZSTR_LEN(name), flags, sb);
+
+	RETURN_SB(&sb);
+}
+/* }}} */
+
+/* {{{ proto resource ZipArchive::statIndex(int index[, int flags])
+Returns the zip entry information using its index */
+static ZIPARCHIVE_METHOD(statIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index, flags = 0;
+
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
+			&index, &flags) == FAILURE) {
+		return;
+	}
+
+	if (zip_stat_index(intern, index, flags, &sb) != 0) {
+		RETURN_FALSE;
+	}
+	RETURN_SB(&sb);
+}
+/* }}} */
+
+/* {{{ proto int ZipArchive::locateName(string filename[, int flags])
+Returns the index of the entry named filename in the archive */
+static ZIPARCHIVE_METHOD(locateName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long flags = 0;
+	zend_long idx = -1;
+	zend_string *name;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
+		return;
+	}
+
+	if (ZSTR_LEN(name) < 1) {
+		RETURN_FALSE;
+	}
+
+	idx = (zend_long)zip_name_locate(intern, (const char *)ZSTR_VAL(name), flags);
+
+	if (idx >= 0) {
+		RETURN_LONG(idx);
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getNameIndex(int index [, int flags])
+Returns the name of the file at position index */
+static ZIPARCHIVE_METHOD(getNameIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	const char *name;
+	zend_long flags = 0, index = 0;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
+			&index, &flags) == FAILURE) {
+		return;
+	}
+
+	name = zip_get_name(intern, (int) index, flags);
+
+	if (name) {
+		RETVAL_STRING((char *)name);
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setArchiveComment(string comment)
+Set or remove (NULL/'') the comment of the archive */
+static ZIPARCHIVE_METHOD(setArchiveComment)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	size_t comment_len;
+	char * comment;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) {
+		return;
+	}
+	if (zip_set_archive_comment(intern, (const char *)comment, (int)comment_len)) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getArchiveComment([int flags])
+Returns the comment of an entry using its index */
+static ZIPARCHIVE_METHOD(getArchiveComment)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long flags = 0;
+	const char * comment;
+	int comment_len = 0;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
+		return;
+	}
+
+	comment = zip_get_archive_comment(intern, &comment_len, (int)flags);
+	if(comment==NULL) {
+		RETURN_FALSE;
+	}
+	RETURN_STRINGL((char *)comment, (zend_long)comment_len);
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setCommentName(string name, string comment)
+Set or remove (NULL/'') the comment of an entry using its Name */
+static ZIPARCHIVE_METHOD(setCommentName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	size_t comment_len, name_len;
+	char * comment, *name;
+	int idx;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
+			&name, &name_len, &comment, &comment_len) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+	PHP_ZIP_SET_FILE_COMMENT(intern, idx, comment, comment_len);
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setCommentIndex(int index, string comment)
+Set or remove (NULL/'') the comment of an entry using its index */
+static ZIPARCHIVE_METHOD(setCommentIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index;
+	size_t comment_len;
+	char * comment;
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls",
+			&index, &comment, &comment_len) == FAILURE) {
+		return;
+	}
+
+	PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
+	PHP_ZIP_SET_FILE_COMMENT(intern, index, comment, comment_len);
+}
+/* }}} */
+
+/* those constants/functions are only available in libzip since 0.11.2 */
+#ifdef ZIP_OPSYS_DEFAULT
+
+/* {{{ proto bool ZipArchive::setExternalAttributesName(string name, int opsys, int attr [, int flags])
+Set external attributes for file in zip, using its name */
+static ZIPARCHIVE_METHOD(setExternalAttributesName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	size_t name_len;
+	char *name;
+	zend_long flags=0, opsys, attr;
+	zip_int64_t idx;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l",
+			&name, &name_len, &opsys, &attr, &flags) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+	if (zip_file_set_external_attributes(intern, idx, (zip_flags_t)flags,
+			(zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setExternalAttributesIndex(int index, int opsys, int attr [, int flags])
+Set external attributes for file in zip, using its index */
+static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index, flags=0, opsys, attr;
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l",
+			&index, &opsys, &attr, &flags) == FAILURE) {
+		return;
+	}
+
+	PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
+	if (zip_file_set_external_attributes(intern, (zip_uint64_t)index,
+			(zip_flags_t)flags, (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::getExternalAttributesName(string name, int &opsys, int &attr [, int flags])
+Get external attributes for file in zip, using its name */
+static ZIPARCHIVE_METHOD(getExternalAttributesName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS, *z_opsys, *z_attr;
+	size_t name_len;
+	char *name;
+	zend_long flags=0;
+	zip_uint8_t opsys;
+	zip_uint32_t attr;
+	zip_int64_t idx;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "szz|l",
+			&name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+	if (zip_file_get_external_attributes(intern, idx,
+			(zip_flags_t)flags, &opsys, &attr) < 0) {
+		RETURN_FALSE;
+	}
+	ZEND_TRY_ASSIGN_REF_LONG(z_opsys, opsys);
+	ZEND_TRY_ASSIGN_REF_LONG(z_attr, attr);
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::getExternalAttributesIndex(int index, int &opsys, int &attr [, int flags])
+Get external attributes for file in zip, using its index */
+static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS, *z_opsys, *z_attr;
+	zend_long index, flags=0;
+	zip_uint8_t opsys;
+	zip_uint32_t attr;
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "lzz|l",
+			&index, &z_opsys, &z_attr, &flags) == FAILURE) {
+		return;
+	}
+
+	PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
+	if (zip_file_get_external_attributes(intern, (zip_uint64_t)index,
+			(zip_flags_t)flags, &opsys, &attr) < 0) {
+		RETURN_FALSE;
+	}
+	ZEND_TRY_ASSIGN_REF_LONG(z_opsys, opsys);
+	ZEND_TRY_ASSIGN_REF_LONG(z_attr, attr);
+	RETURN_TRUE;
+}
+/* }}} */
+#endif /* ifdef ZIP_OPSYS_DEFAULT */
+
+#ifdef HAVE_ENCRYPTION
+/* {{{ proto bool ZipArchive::setEncryptionName(string name, int method, [string password])
+Set encryption method for file in zip, using its name */
+static ZIPARCHIVE_METHOD(setEncryptionName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long method;
+	zip_int64_t idx;
+	char *name, *password = NULL;
+	size_t name_len, password_len;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s",
+			&name, &name_len, &method, &password, &password_len) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+
+	if (zip_file_set_encryption(intern, idx, (zip_uint16_t)method, password)) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setEncryptionIndex(int index, int method, [string password])
+Set encryption method for file in zip, using its index */
+static ZIPARCHIVE_METHOD(setEncryptionIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index, method;
+	char *password = NULL;
+	size_t password_len;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s",
+			&index, &method, &password, &password_len) == FAILURE) {
+		return;
+	}
+
+	if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+/* {{{ proto string ZipArchive::getCommentName(string name[, int flags])
+Returns the comment of an entry using its name */
+static ZIPARCHIVE_METHOD(getCommentName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	size_t name_len;
+	int idx;
+	zend_long flags = 0;
+	int comment_len = 0;
+	const char * comment;
+	char *name;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l",
+			&name, &name_len, &flags) == FAILURE) {
+		return;
+	}
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+		RETURN_FALSE;
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+
+	comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags);
+	RETURN_STRINGL((char *)comment, (zend_long)comment_len);
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getCommentIndex(int index[, int flags])
+Returns the comment of an entry using its index */
+static ZIPARCHIVE_METHOD(getCommentIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index, flags = 0;
+	const char * comment;
+	int comment_len = 0;
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
+				&index, &flags) == FAILURE) {
+		return;
+	}
+
+	PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
+	comment = zip_get_file_comment(intern, index, &comment_len, (int)flags);
+	RETURN_STRINGL((char *)comment, (zend_long)comment_len);
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setCompressionName(string name, int comp_method[, int comp_flags])
+Set the compression of a file in zip, using its name */
+static ZIPARCHIVE_METHOD(setCompressionName)
+ {
+	struct zip *intern;
+	zval *this = ZEND_THIS;
+	size_t name_len;
+	char *name;
+	zip_int64_t idx;
+	zend_long comp_method, comp_flags = 0;
+
+	ZIP_FROM_OBJECT(intern, this);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l",
+			&name, &name_len, &comp_method, &comp_flags) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
+	}
+
+	idx = zip_name_locate(intern, name, 0);
+	if (idx < 0) {
+		RETURN_FALSE;
+	}
+
+	if (zip_set_file_compression(intern, (zip_uint64_t)idx,
+			(zip_int32_t)comp_method, (zip_uint32_t)comp_flags) != 0) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::setCompressionIndex(int index, int comp_method[, int comp_flags])
+Set the compression of a file in zip, using its index */
+static ZIPARCHIVE_METHOD(setCompressionIndex)
+{
+	struct zip *intern;
+	zval *this = ZEND_THIS;
+	zend_long index;
+	zend_long comp_method, comp_flags = 0;
+
+	ZIP_FROM_OBJECT(intern, this);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
+			&index, &comp_method, &comp_flags) == FAILURE) {
+		return;
+	}
+
+	if (zip_set_file_compression(intern, (zip_uint64_t)index,
+			(zip_int32_t)comp_method, (zip_uint32_t)comp_flags) != 0) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::deleteIndex(int index)
+Delete a file using its index */
+static ZIPARCHIVE_METHOD(deleteIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
+		return;
+	}
+
+	if (index < 0) {
+		RETURN_FALSE;
+	}
+
+	if (zip_delete(intern, index) < 0) {
+		RETURN_FALSE;
+	}
+
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::deleteName(string name)
+Delete a file using its index */
+static ZIPARCHIVE_METHOD(deleteName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	size_t name_len;
+	char *name;
+	struct zip_stat sb;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
+		return;
+	}
+	if (name_len < 1) {
+		RETURN_FALSE;
+	}
+
+	PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
+	if (zip_delete(intern, sb.index)) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::renameIndex(int index, string new_name)
+Rename an entry selected by its index to new_name */
+static ZIPARCHIVE_METHOD(renameIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	char *new_name;
+	size_t new_name_len;
+	zend_long index;
+
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &new_name, &new_name_len) == FAILURE) {
+		return;
+	}
+
+	if (index < 0) {
+		RETURN_FALSE;
+	}
+
+	if (new_name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
+		RETURN_FALSE;
+	}
+	if (zip_rename(intern, index, (const char *)new_name) != 0) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::renameName(string name, string new_name)
+Rename an entry selected by its name to new_name */
+static ZIPARCHIVE_METHOD(renameName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	struct zip_stat sb;
+	char *name, *new_name;
+	size_t name_len, new_name_len;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) {
+		return;
+	}
+
+	if (new_name_len < 1) {
+		php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
+		RETURN_FALSE;
+	}
+
+	PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
+
+	if (zip_rename(intern, sb.index, (const char *)new_name)) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::unchangeIndex(int index)
+Changes to the file at position index are reverted */
+static ZIPARCHIVE_METHOD(unchangeIndex)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	zend_long index;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
+		return;
+	}
+
+	if (index < 0) {
+		RETURN_FALSE;
+	}
+
+	if (zip_unchange(intern, index) != 0) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::unchangeName(string name)
+Changes to the file named 'name' are reverted */
+static ZIPARCHIVE_METHOD(unchangeName)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	struct zip_stat sb;
+	char *name;
+	size_t name_len;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
+		return;
+	}
+
+	if (name_len < 1) {
+		RETURN_FALSE;
+	}
+
+	PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
+
+	if (zip_unchange(intern, sb.index) != 0) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::unchangeAll()
+All changes to files and global information in archive are reverted */
+static ZIPARCHIVE_METHOD(unchangeAll)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zip_unchange_all(intern) != 0) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::unchangeArchive()
+Revert all global changes to the archive archive.  For now, this only reverts archive comment changes. */
+static ZIPARCHIVE_METHOD(unchangeArchive)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zip_unchange_archive(intern) != 0) {
+		RETURN_FALSE;
+	} else {
+		RETURN_TRUE;
+	}
+}
+/* }}} */
+
+/* {{{ proto bool ZipArchive::extractTo(string pathto[, mixed files])
+Extract one or more file from a zip archive */
+/* TODO:
+ * - allow index or array of indices
+ * - replace path
+ * - patterns
+ */
+static ZIPARCHIVE_METHOD(extractTo)
+{
+	struct zip *intern;
+
+	zval *self = ZEND_THIS;
+	zval *zval_files = NULL;
+	zval *zval_file = NULL;
+	php_stream_statbuf ssb;
+	char *pathto;
+	size_t pathto_len;
+	int ret, i;
+
+	int nelems;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
+		return;
+	}
+
+	if (pathto_len < 1) {
+		RETURN_FALSE;
+	}
+
+	if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
+			ret = php_stream_mkdir(pathto, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
+			if (!ret) {
+					RETURN_FALSE;
+			}
+	}
+
+	ZIP_FROM_OBJECT(intern, self);
+	if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) {
+		switch (Z_TYPE_P(zval_files)) {
+			case IS_STRING:
+				if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_files), Z_STRLEN_P(zval_files))) {
+					RETURN_FALSE;
+				}
+				break;
+			case IS_ARRAY:
+				nelems = zend_hash_num_elements(Z_ARRVAL_P(zval_files));
+				if (nelems == 0 ) {
+					RETURN_FALSE;
+				}
+				for (i = 0; i < nelems; i++) {
+					if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(zval_files), i)) != NULL) {
+						switch (Z_TYPE_P(zval_file)) {
+							case IS_LONG:
+								break;
+							case IS_STRING:
+								if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file))) {
+									RETURN_FALSE;
+								}
+								break;
+						}
+					}
+				}
+				break;
+			case IS_LONG:
+			default:
+				php_error_docref(NULL, E_WARNING, "Invalid argument, expect string or array of strings");
+				break;
+		}
+	} else {
+		/* Extract all files */
+		int filecount = zip_get_num_files(intern);
+
+		if (filecount == -1) {
+				php_error_docref(NULL, E_WARNING, "Illegal archive");
+				RETURN_FALSE;
+		}
+
+		for (i = 0; i < filecount; i++) {
+			char *file = (char*)zip_get_name(intern, i, ZIP_FL_UNCHANGED);
+			if (!file || !php_zip_extract_file(intern, pathto, file, strlen(file))) {
+					RETURN_FALSE;
+			}
+		}
+	}
+	RETURN_TRUE;
+}
+/* }}} */
+
+static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+
+	struct zip_stat sb;
+	struct zip_file *zf;
+
+	zend_long index = -1;
+	zend_long flags = 0;
+	zend_long len = 0;
+
+	zend_string *filename;
+	zend_string *buffer;
+
+	int n = 0;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (type == 1) {
+		if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
+			return;
+		}
+		PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), flags, sb);
+	} else {
+		if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &index, &len, &flags) == FAILURE) {
+			return;
+		}
+		PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
+	}
+
+	if (sb.size < 1) {
+		RETURN_EMPTY_STRING();
+	}
+
+	if (len < 1) {
+		len = sb.size;
+	}
+	if (index >= 0) {
+		zf = zip_fopen_index(intern, index, flags);
+	} else {
+		zf = zip_fopen(intern, ZSTR_VAL(filename), flags);
+	}
+
+	if (zf == NULL) {
+		RETURN_FALSE;
+	}
+
+	buffer = zend_string_safe_alloc(1, len, 0, 0);
+	n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
+	if (n < 1) {
+		zend_string_efree(buffer);
+		RETURN_EMPTY_STRING();
+	}
+
+	zip_fclose(zf);
+	ZSTR_VAL(buffer)[n] = '\0';
+	ZSTR_LEN(buffer) = n;
+	RETURN_NEW_STR(buffer);
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getFromName(string entryname[, int len [, int flags]])
+get the contents of an entry using its name */
+static ZIPARCHIVE_METHOD(getFromName)
+{
+	php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
+/* {{{ proto string ZipArchive::getFromIndex(int index[, int len [, int flags]])
+get the contents of an entry using its index */
+static ZIPARCHIVE_METHOD(getFromIndex)
+{
+	php_zip_get_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto resource ZipArchive::getStream(string entryname)
+get a stream for an entry using its name */
+static ZIPARCHIVE_METHOD(getStream)
+{
+	struct zip *intern;
+	zval *self = ZEND_THIS;
+	struct zip_stat sb;
+	char *mode = "rb";
+	zend_string *filename;
+	php_stream *stream;
+	ze_zip_object *obj;
+
+	ZIP_FROM_OBJECT(intern, self);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
+		return;
+	}
+
+	if (zip_stat(intern, ZSTR_VAL(filename), 0, &sb) != 0) {
+		RETURN_FALSE;
+	}
+
+	obj = Z_ZIP_P(self);
+
+	stream = php_stream_zip_open(obj->filename, ZSTR_VAL(filename), mode STREAMS_CC);
+	if (stream) {
+		php_stream_to_zval(stream, return_value);
+	} else {
+		RETURN_FALSE;
+	}
+}
+/* }}} */
+
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_open, 0, 0, 1)
+	ZEND_ARG_INFO(0, filename)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setpassword, 0, 0, 1)
+	ZEND_ARG_INFO(0, password)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_ziparchive__void, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addemptydir, 0, 0, 1)
+	ZEND_ARG_INFO(0, dirname)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addglob, 0, 0, 1)
+	ZEND_ARG_INFO(0, pattern)
+	ZEND_ARG_INFO(0, flags)
+	ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addpattern, 0, 0, 1)
+	ZEND_ARG_INFO(0, pattern)
+	ZEND_ARG_INFO(0, path)
+	ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfile, 0, 0, 1)
+	ZEND_ARG_INFO(0, filepath)
+	ZEND_ARG_INFO(0, entryname)
+	ZEND_ARG_INFO(0, start)
+	ZEND_ARG_INFO(0, length)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_addfromstring, 0, 0, 2)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, content)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statname, 0, 0, 1)
+	ZEND_ARG_INFO(0, filename)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_statindex, 0, 0, 1)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setarchivecomment, 0, 0, 1)
+	ZEND_ARG_INFO(0, comment)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentindex, 0, 0, 2)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, comment)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentname, 0, 0, 1)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getcommentindex, 0, 0, 1)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renameindex, 0, 0, 2)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, new_name)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_renamename, 0, 0, 2)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, new_name)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangeindex, 0, 0, 1)
+	ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_unchangename, 0, 0, 1)
+	ZEND_ARG_INFO(0, name)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_extractto, 0, 0, 1)
+	ZEND_ARG_INFO(0, pathto)
+	ZEND_ARG_INFO(0, files)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromname, 0, 0, 1)
+	ZEND_ARG_INFO(0, entryname)
+	ZEND_ARG_INFO(0, len)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getfromindex, 0, 0, 1)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, len)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getarchivecomment, 0, 0, 0)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcommentname, 0, 0, 2)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, comment)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getstream, 0, 0, 1)
+	ZEND_ARG_INFO(0, entryname)
+ZEND_END_ARG_INFO()
+
+#ifdef ZIP_OPSYS_DEFAULT
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrname, 0, 0, 3)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, opsys)
+	ZEND_ARG_INFO(0, attr)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setextattrindex, 0, 0, 3)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, opsys)
+	ZEND_ARG_INFO(0, attr)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrname, 0, 0, 3)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(1, opsys)
+	ZEND_ARG_INFO(1, attr)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_getextattrindex, 0, 0, 3)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(1, opsys)
+	ZEND_ARG_INFO(1, attr)
+	ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+#endif /* ifdef ZIP_OPSYS_DEFAULT */
+/* }}} */
+
+#ifdef HAVE_ENCRYPTION
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setencryption_name, 0, 0, 2)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, method)
+	ZEND_ARG_INFO(0, password)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setencryption_index, 0, 0, 2)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, method)
+	ZEND_ARG_INFO(0, password)
+ZEND_END_ARG_INFO()
+#endif
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcompname, 0, 0, 2)
+	ZEND_ARG_INFO(0, name)
+	ZEND_ARG_INFO(0, method)
+	ZEND_ARG_INFO(0, compflags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ziparchive_setcompindex, 0, 0, 2)
+	ZEND_ARG_INFO(0, index)
+	ZEND_ARG_INFO(0, method)
+	ZEND_ARG_INFO(0, compflags)
+ZEND_END_ARG_INFO()
+
+/* {{{ ze_zip_object_class_functions */
+static const zend_function_entry zip_class_functions[] = {
+	ZIPARCHIVE_ME(open,					arginfo_ziparchive_open, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setPassword,			arginfo_ziparchive_setpassword, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(close,				arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(count,				arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getStatusString,		arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(addEmptyDir,			arginfo_ziparchive_addemptydir, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(addFromString,		arginfo_ziparchive_addfromstring, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(addFile,				arginfo_ziparchive_addfile, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(addGlob,				arginfo_ziparchive_addglob, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(addPattern,			arginfo_ziparchive_addpattern, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(renameIndex,			arginfo_ziparchive_renameindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(renameName,			arginfo_ziparchive_renamename, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setArchiveComment,	arginfo_ziparchive_setarchivecomment, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getArchiveComment,	arginfo_ziparchive_getarchivecomment, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setCommentIndex,		arginfo_ziparchive_setcommentindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setCommentName,		arginfo_ziparchive_setcommentname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getCommentIndex,		arginfo_ziparchive_getcommentindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getCommentName,		arginfo_ziparchive_getcommentname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(deleteIndex,			arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(deleteName,			arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(statName,				arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(statIndex,			arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(locateName,			arginfo_ziparchive_statname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getNameIndex,			arginfo_ziparchive_statindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(unchangeArchive,		arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(unchangeAll,			arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(unchangeIndex,		arginfo_ziparchive_unchangeindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(unchangeName,			arginfo_ziparchive_unchangename, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(extractTo,			arginfo_ziparchive_extractto, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getFromName,			arginfo_ziparchive_getfromname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getFromIndex,			arginfo_ziparchive_getfromindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getStream,			arginfo_ziparchive_getstream, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setExternalAttributesName,	arginfo_ziparchive_setextattrname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setExternalAttributesIndex,	arginfo_ziparchive_setextattrindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getExternalAttributesName,	arginfo_ziparchive_getextattrname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(getExternalAttributesIndex,	arginfo_ziparchive_getextattrindex, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setCompressionName,		arginfo_ziparchive_setcompname, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setCompressionIndex,		arginfo_ziparchive_setcompindex, ZEND_ACC_PUBLIC)
+#ifdef HAVE_ENCRYPTION
+	ZIPARCHIVE_ME(setEncryptionName,		arginfo_ziparchive_setencryption_name, ZEND_ACC_PUBLIC)
+	ZIPARCHIVE_ME(setEncryptionIndex,		arginfo_ziparchive_setencryption_index, ZEND_ACC_PUBLIC)
+#endif
+	PHP_FE_END
+};
+/* }}} */
+
+static void php_zip_free_prop_handler(zval *el) /* {{{ */ {
+	pefree(Z_PTR_P(el), 1);
+} /* }}} */
+
+/* {{{ PHP_MINIT_FUNCTION */
+static PHP_MINIT_FUNCTION(zip)
+{
+	zend_class_entry ce;
+
+	memcpy(&zip_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
+	zip_object_handlers.offset = XtOffsetOf(ze_zip_object, zo);
+	zip_object_handlers.free_obj = php_zip_object_free_storage;
+	zip_object_handlers.clone_obj = NULL;
+	zip_object_handlers.get_property_ptr_ptr = php_zip_get_property_ptr_ptr;
+
+	zip_object_handlers.get_gc          = php_zip_get_gc;
+	zip_object_handlers.get_properties = php_zip_get_properties;
+	zip_object_handlers.read_property	= php_zip_read_property;
+	zip_object_handlers.has_property	= php_zip_has_property;
+
+	INIT_CLASS_ENTRY(ce, "ZipArchive", zip_class_functions);
+	ce.create_object = php_zip_object_new;
+	zip_class_entry = zend_register_internal_class(&ce);
+
+	zend_hash_init(&zip_prop_handlers, 0, NULL, php_zip_free_prop_handler, 1);
+	php_zip_register_prop_handler(&zip_prop_handlers, "status",    php_zip_status, NULL, NULL, IS_LONG);
+	php_zip_register_prop_handler(&zip_prop_handlers, "statusSys", php_zip_status_sys, NULL, NULL, IS_LONG);
+	php_zip_register_prop_handler(&zip_prop_handlers, "numFiles",  php_zip_get_num_files, NULL, NULL, IS_LONG);
+	php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING);
+	php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING);
+	zend_class_implements(zip_class_entry, 1, zend_ce_countable);
+
+	REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
+	REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);
+	REGISTER_ZIP_CLASS_CONST_LONG("CHECKCONS", ZIP_CHECKCONS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OVERWRITE", ZIP_OVERWRITE);
+
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_NOCASE", ZIP_FL_NOCASE);
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_NODIR", ZIP_FL_NODIR);
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_COMPRESSED", ZIP_FL_COMPRESSED);
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_UNCHANGED", ZIP_FL_UNCHANGED);
+
+#ifdef ZIP_FL_ENC_GUESS
+	/* Default filename encoding policy. */
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_GUESS", ZIP_FL_ENC_GUESS);
+#endif
+#ifdef ZIP_FL_ENC_RAW
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_RAW", ZIP_FL_ENC_RAW);
+#endif
+#ifdef ZIP_FL_ENC_STRICT
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_STRICT", ZIP_FL_ENC_STRICT);
+#endif
+#ifdef ZIP_FL_ENC_UTF_8
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_UTF_8", ZIP_FL_ENC_UTF_8);
+#endif
+#ifdef ZIP_FL_ENC_CP437
+	REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_CP437", ZIP_FL_ENC_CP437);
+#endif
+
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFAULT", ZIP_CM_DEFAULT);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_STORE", ZIP_CM_STORE);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_SHRINK", ZIP_CM_SHRINK);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_1", ZIP_CM_REDUCE_1);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_2", ZIP_CM_REDUCE_2);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_3", ZIP_CM_REDUCE_3);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_REDUCE_4", ZIP_CM_REDUCE_4);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_IMPLODE", ZIP_CM_IMPLODE);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE", ZIP_CM_DEFLATE);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE64", ZIP_CM_DEFLATE64);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_PKWARE_IMPLODE", ZIP_CM_PKWARE_IMPLODE);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_BZIP2", ZIP_CM_BZIP2);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_LZMA", ZIP_CM_LZMA);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_TERSE", ZIP_CM_TERSE);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_LZ77", ZIP_CM_LZ77);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_WAVPACK", ZIP_CM_WAVPACK);
+	REGISTER_ZIP_CLASS_CONST_LONG("CM_PPMD", ZIP_CM_PPMD);
+
+	/* Error code */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_OK",			ZIP_ER_OK);			/* N No error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_MULTIDISK",	ZIP_ER_MULTIDISK);	/* N Multi-disk zip archives not supported */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_RENAME",		ZIP_ER_RENAME);		/* S Renaming temporary file failed */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_CLOSE",		ZIP_ER_CLOSE);		/* S Closing zip archive failed */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_SEEK",		ZIP_ER_SEEK);		/* S Seek error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_READ",		ZIP_ER_READ);		/* S Read error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_WRITE",		ZIP_ER_WRITE);		/* S Write error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_CRC",			ZIP_ER_CRC);		/* N CRC error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_ZIPCLOSED",	ZIP_ER_ZIPCLOSED);	/* N Containing zip archive was closed */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_NOENT",		ZIP_ER_NOENT);		/* N No such file */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_EXISTS",		ZIP_ER_EXISTS);		/* N File already exists */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_OPEN",		ZIP_ER_OPEN);		/* S Can't open file */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_TMPOPEN",		ZIP_ER_TMPOPEN);	/* S Failure to create temporary file */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_ZLIB",		ZIP_ER_ZLIB);		/* Z Zlib error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_MEMORY",		ZIP_ER_MEMORY);		/* N Malloc failure */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_CHANGED",		ZIP_ER_CHANGED);	/* N Entry has been changed */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_COMPNOTSUPP",	ZIP_ER_COMPNOTSUPP);/* N Compression method not supported */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_EOF",			ZIP_ER_EOF);		/* N Premature EOF */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_INVAL",		ZIP_ER_INVAL);		/* N Invalid argument */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_NOZIP",		ZIP_ER_NOZIP);		/* N Not a zip archive */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_INTERNAL",	ZIP_ER_INTERNAL);	/* N Internal error */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_INCONS",		ZIP_ER_INCONS);		/* N Zip archive inconsistent */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_REMOVE",		ZIP_ER_REMOVE);		/* S Can't remove file */
+	REGISTER_ZIP_CLASS_CONST_LONG("ER_DELETED",  	ZIP_ER_DELETED);	/* N Entry has been deleted */
+
+#ifdef ZIP_OPSYS_DEFAULT
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DOS",				ZIP_OPSYS_DOS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_AMIGA",			ZIP_OPSYS_AMIGA);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OPENVMS",			ZIP_OPSYS_OPENVMS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_UNIX",				ZIP_OPSYS_UNIX);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VM_CMS",			ZIP_OPSYS_VM_CMS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ATARI_ST",			ZIP_OPSYS_ATARI_ST);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_2",				ZIP_OPSYS_OS_2);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MACINTOSH",		ZIP_OPSYS_MACINTOSH);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_SYSTEM",			ZIP_OPSYS_Z_SYSTEM);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_CPM",			ZIP_OPSYS_CPM);  // typo kept for BC
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_CPM",				ZIP_OPSYS_CPM);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_WINDOWS_NTFS",		ZIP_OPSYS_WINDOWS_NTFS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MVS",				ZIP_OPSYS_MVS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VSE",				ZIP_OPSYS_VSE);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ACORN_RISC",		ZIP_OPSYS_ACORN_RISC);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_VFAT",				ZIP_OPSYS_VFAT);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_ALTERNATE_MVS",	ZIP_OPSYS_ALTERNATE_MVS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_BEOS",				ZIP_OPSYS_BEOS);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_TANDEM",			ZIP_OPSYS_TANDEM);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_400",			ZIP_OPSYS_OS_400);
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_X",				ZIP_OPSYS_OS_X);
+
+	REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_DEFAULT", ZIP_OPSYS_DEFAULT);
+#endif /* ifdef ZIP_OPSYS_DEFAULT */
+
+#ifdef HAVE_ENCRYPTION
+	REGISTER_ZIP_CLASS_CONST_LONG("EM_NONE",				ZIP_EM_NONE);
+	REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_128",				ZIP_EM_AES_128);
+	REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_192",				ZIP_EM_AES_192);
+	REGISTER_ZIP_CLASS_CONST_LONG("EM_AES_256",				ZIP_EM_AES_256);
+#endif
+
+	php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper);
+
+	le_zip_dir   = zend_register_list_destructors_ex(php_zip_free_dir,   NULL, le_zip_dir_name,   module_number);
+	le_zip_entry = zend_register_list_destructors_ex(php_zip_free_entry, NULL, le_zip_entry_name, module_number);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MSHUTDOWN_FUNCTION
+ */
+static PHP_MSHUTDOWN_FUNCTION(zip)
+{
+	zend_hash_destroy(&zip_prop_handlers);
+	php_unregister_url_stream_wrapper("zip");
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION
+ */
+static PHP_MINFO_FUNCTION(zip)
+{
+	php_info_print_table_start();
+
+	php_info_print_table_row(2, "Zip", "enabled");
+	php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION);
+#if HAVE_LIBZIP_VERSION
+	php_info_print_table_row(2, "Libzip headers version", LIBZIP_VERSION);
+	php_info_print_table_row(2, "Libzip library version", zip_libzip_version());
+#else
+	php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
+#endif
+
+	php_info_print_table_end();
+}
+/* }}} */
diff --git a/php74/php_zip.h b/php74/php_zip.h
new file mode 100644
index 0000000..191be54
--- /dev/null
+++ b/php74/php_zip.h
@@ -0,0 +1,82 @@
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 7                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) The PHP Group                                          |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.01 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available through the world-wide-web at the following url:           |
+  | http://www.php.net/license/3_01.txt.                                 |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Pierre-Alain Joye <pajoye@php.net>                           |
+  +----------------------------------------------------------------------+
+*/
+
+
+#ifndef PHP_ZIP_H
+#define PHP_ZIP_H
+
+extern zend_module_entry zip_module_entry;
+#define phpext_zip_ptr &zip_module_entry
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
+#if defined(HAVE_LIBZIP)
+#include <zip.h>
+#else
+#include "lib/zip.h"
+#endif
+
+#ifndef ZIP_OVERWRITE
+#define ZIP_OVERWRITE ZIP_TRUNCATE
+#endif
+
+#define PHP_ZIP_VERSION "1.15.4"
+
+#define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
+
+typedef struct _ze_zip_rsrc {
+	struct zip *za;
+	int index_current;
+	int num_files;
+} zip_rsrc;
+
+typedef zip_rsrc * zip_rsrc_ptr;
+
+typedef struct _ze_zip_read_rsrc {
+	struct zip_file *zf;
+	struct zip_stat sb;
+} zip_read_rsrc;
+
+#define ZIPARCHIVE_ME(name, arg_info, flags) {#name, c_ziparchive_ ##name, arg_info,(uint32_t) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
+#define ZIPARCHIVE_METHOD(name)	ZEND_NAMED_FUNCTION(c_ziparchive_ ##name)
+
+/* Extends zend object */
+typedef struct _ze_zip_object {
+	struct zip *za;
+	char **buffers;
+	HashTable *prop_handler;
+	char *filename;
+	int filename_len;
+	int buffers_cnt;
+	zend_object zo;
+} ze_zip_object;
+
+static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
+	return (ze_zip_object *)((char*)(obj) - XtOffsetOf(ze_zip_object, zo));
+}
+
+#define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
+
+php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
+php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC);
+
+extern const php_stream_wrapper php_stream_zip_wrapper;
+
+#endif	/* PHP_ZIP_H */
diff --git a/php74/zip_stream.c b/php74/zip_stream.c
new file mode 100644
index 0000000..f24a91f
--- /dev/null
+++ b/php74/zip_stream.c
@@ -0,0 +1,370 @@
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 7                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) The PHP Group                                          |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.01 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available through the world-wide-web at the following url:           |
+  | http://www.php.net/license/3_01.txt.                                 |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Piere-Alain Joye <pierre@php.net>                            |
+  +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+#   include "config.h"
+#endif
+#include "php.h"
+#if HAVE_ZIP
+
+#include "php_streams.h"
+#include "ext/standard/file.h"
+#include "ext/standard/php_string.h"
+#include "fopen_wrappers.h"
+#include "php_zip.h"
+
+#include "ext/standard/url.h"
+
+/* needed for ssize_t definition */
+#include <sys/types.h>
+
+struct php_zip_stream_data_t {
+	struct zip *za;
+	struct zip_file *zf;
+	size_t cursor;
+	php_stream *stream;
+};
+
+#define STREAM_DATA_FROM_STREAM() \
+	struct php_zip_stream_data_t *self = (struct php_zip_stream_data_t *) stream->abstract;
+
+
+/* {{{ php_zip_ops_read */
+static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count)
+{
+	ssize_t n = 0;
+	STREAM_DATA_FROM_STREAM();
+
+	if (self->za && self->zf) {
+		n = zip_fread(self->zf, buf, count);
+		if (n < 0) {
+#if LIBZIP_VERSION_MAJOR < 1
+			int ze, se;
+			zip_file_error_get(self->zf, &ze, &se);
+			stream->eof = 1;
+			php_error_docref(NULL, E_WARNING, "Zip stream error: %s", zip_file_strerror(self->zf));
+#else
+			zip_error_t *err;
+			err = zip_file_get_error(self->zf);
+			stream->eof = 1;
+			php_error_docref(NULL, E_WARNING, "Zip stream error: %s", zip_error_strerror(err));
+			zip_error_fini(err);
+#endif
+			return 0;
+		}
+		/* cast count to signed value to avoid possibly negative n
+		 * being cast to unsigned value */
+		if (n == 0 || n < (ssize_t)count) {
+			stream->eof = 1;
+		} else {
+			self->cursor += n;
+		}
+	}
+	return (n < 1 ? 0 : (size_t)n);
+}
+/* }}} */
+
+/* {{{ php_zip_ops_write */
+static size_t php_zip_ops_write(php_stream *stream, const char *buf, size_t count)
+{
+	if (!stream) {
+		return 0;
+	}
+
+	return count;
+}
+/* }}} */
+
+/* {{{ php_zip_ops_close */
+static int php_zip_ops_close(php_stream *stream, int close_handle)
+{
+	STREAM_DATA_FROM_STREAM();
+	if (close_handle) {
+		if (self->zf) {
+			zip_fclose(self->zf);
+			self->zf = NULL;
+		}
+
+		if (self->za) {
+			zip_close(self->za);
+			self->za = NULL;
+		}
+	}
+	efree(self);
+	stream->abstract = NULL;
+	return EOF;
+}
+/* }}} */
+
+/* {{{ php_zip_ops_flush */
+static int php_zip_ops_flush(php_stream *stream)
+{
+	if (!stream) {
+		return 0;
+	}
+
+	return 0;
+}
+/* }}} */
+
+static int php_zip_ops_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{ */
+{
+	struct zip_stat sb;
+	const char *path = stream->orig_path;
+	size_t path_len = strlen(stream->orig_path);
+	char file_dirname[MAXPATHLEN];
+	struct zip *za;
+	char *fragment;
+	size_t fragment_len;
+	int err;
+	zend_string *file_basename;
+
+	fragment = strchr(path, '#');
+	if (!fragment) {
+		return -1;
+	}
+
+
+	if (strncasecmp("zip://", path, 6) == 0) {
+		path += 6;
+	}
+
+	fragment_len = strlen(fragment);
+
+	if (fragment_len < 1) {
+		return -1;
+	}
+	path_len = strlen(path);
+	if (path_len >= MAXPATHLEN) {
+		return -1;
+	}
+
+	memcpy(file_dirname, path, path_len - fragment_len);
+	file_dirname[path_len - fragment_len] = '\0';
+
+	file_basename = php_basename((char *)path, path_len - fragment_len, NULL, 0);
+	fragment++;
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname)) {
+		zend_string_release_ex(file_basename, 0);
+		return -1;
+	}
+
+	za = zip_open(file_dirname, ZIP_CREATE, &err);
+	if (za) {
+		memset(ssb, 0, sizeof(php_stream_statbuf));
+		if (zip_stat(za, fragment, ZIP_FL_NOCASE, &sb) != 0) {
+			zip_close(za);
+			zend_string_release_ex(file_basename, 0);
+			return -1;
+		}
+		zip_close(za);
+
+		if (path[path_len-1] != '/') {
+			ssb->sb.st_size = sb.size;
+			ssb->sb.st_mode |= S_IFREG; /* regular file */
+		} else {
+			ssb->sb.st_size = 0;
+			ssb->sb.st_mode |= S_IFDIR; /* regular directory */
+		}
+
+		ssb->sb.st_mtime = sb.mtime;
+		ssb->sb.st_atime = sb.mtime;
+		ssb->sb.st_ctime = sb.mtime;
+		ssb->sb.st_nlink = 1;
+		ssb->sb.st_rdev = -1;
+#ifndef PHP_WIN32
+		ssb->sb.st_blksize = -1;
+		ssb->sb.st_blocks = -1;
+#endif
+		ssb->sb.st_ino = -1;
+	}
+	zend_string_release_ex(file_basename, 0);
+	return 0;
+}
+/* }}} */
+
+const php_stream_ops php_stream_zipio_ops = {
+	php_zip_ops_write, php_zip_ops_read,
+	php_zip_ops_close, php_zip_ops_flush,
+	"zip",
+	NULL, /* seek */
+	NULL, /* cast */
+	php_zip_ops_stat, /* stat */
+	NULL  /* set_option */
+};
+
+/* {{{ php_stream_zip_open */
+php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC)
+{
+	struct zip_file *zf = NULL;
+	int err = 0;
+
+	php_stream *stream = NULL;
+	struct php_zip_stream_data_t *self;
+	struct zip *stream_za;
+
+	if (strncmp(mode,"r", strlen("r")) != 0) {
+		return NULL;
+	}
+
+	if (filename) {
+		if (ZIP_OPENBASEDIR_CHECKPATH(filename)) {
+			return NULL;
+		}
+
+		/* duplicate to make the stream za independent (esp. for MSHUTDOWN) */
+		stream_za = zip_open(filename, ZIP_CREATE, &err);
+		if (!stream_za) {
+			return NULL;
+		}
+
+		zf = zip_fopen(stream_za, path, 0);
+		if (zf) {
+			self = emalloc(sizeof(*self));
+
+			self->za = stream_za;
+			self->zf = zf;
+			self->stream = NULL;
+			self->cursor = 0;
+			stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode);
+			stream->orig_path = estrdup(path);
+		} else {
+			zip_close(stream_za);
+		}
+	}
+
+	if (!stream) {
+		return NULL;
+	} else {
+		return stream;
+	}
+
+}
+/* }}} */
+
+/* {{{ php_stream_zip_opener */
+php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper,
+											const char *path,
+											const char *mode,
+											int options,
+											zend_string **opened_path,
+											php_stream_context *context STREAMS_DC)
+{
+	size_t path_len;
+
+	zend_string *file_basename;
+	char file_dirname[MAXPATHLEN];
+
+	struct zip *za;
+	struct zip_file *zf = NULL;
+	char *fragment;
+	size_t fragment_len;
+	int err;
+
+	php_stream *stream = NULL;
+	struct php_zip_stream_data_t *self;
+
+	fragment = strchr(path, '#');
+	if (!fragment) {
+		return NULL;
+	}
+
+	if (strncasecmp("zip://", path, 6) == 0) {
+		path += 6;
+	}
+
+	fragment_len = strlen(fragment);
+
+	if (fragment_len < 1) {
+		return NULL;
+	}
+	path_len = strlen(path);
+	if (path_len >= MAXPATHLEN || mode[0] != 'r') {
+		return NULL;
+	}
+
+	memcpy(file_dirname, path, path_len - fragment_len);
+	file_dirname[path_len - fragment_len] = '\0';
+
+	file_basename = php_basename(path, path_len - fragment_len, NULL, 0);
+	fragment++;
+
+	if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname)) {
+		zend_string_release_ex(file_basename, 0);
+		return NULL;
+	}
+
+	za = zip_open(file_dirname, ZIP_CREATE, &err);
+	if (za) {
+		zval *tmpzval;
+
+		if (context && NULL != (tmpzval = php_stream_context_get_option(context, "zip", "password"))) {
+			if (Z_TYPE_P(tmpzval) != IS_STRING || zip_set_default_password(za, Z_STRVAL_P(tmpzval))) {
+				php_error_docref(NULL, E_WARNING, "Can't set zip password");
+			}
+		}
+
+		zf = zip_fopen(za, fragment, 0);
+		if (zf) {
+			self = emalloc(sizeof(*self));
+
+			self->za = za;
+			self->zf = zf;
+			self->stream = NULL;
+			self->cursor = 0;
+			stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode);
+
+			if (opened_path) {
+				*opened_path = zend_string_init(path, strlen(path), 0);
+			}
+		} else {
+			zip_close(za);
+		}
+	}
+
+	zend_string_release_ex(file_basename, 0);
+
+	if (!stream) {
+		return NULL;
+	} else {
+		return stream;
+	}
+}
+/* }}} */
+
+static const php_stream_wrapper_ops zip_stream_wops = {
+	php_stream_zip_opener,
+	NULL,	/* close */
+	NULL,	/* fstat */
+	NULL,	/* stat */
+	NULL,	/* opendir */
+	"zip wrapper",
+	NULL,	/* unlink */
+	NULL,	/* rename */
+	NULL,	/* mkdir */
+	NULL,	/* rmdir */
+	NULL	/* metadata */
+};
+
+const php_stream_wrapper php_stream_zip_wrapper = {
+	&zip_stream_wops,
+	NULL,
+	0 /* is_url */
+};
+#endif /* HAVE_ZIP */