39
39
#endif
40
40
41
41
#include "pkg_editor/pkg_editor.h"
42
- #if USE_ZLIB
43
42
#include "zlib.h"
44
- #endif
45
43
46
44
typedef struct acl_pkg_file {
47
45
const char * fname ;
@@ -1160,23 +1158,6 @@ void acl_pkg_set_show_mode(acl_pkg_file *pkg, int show_mode) {
1160
1158
}
1161
1159
}
1162
1160
1163
- #if USE_ZLIB
1164
-
1165
- int zlib_deflateInit (z_streamp strm , int level ) {
1166
- return deflateInit_ (strm , level , ZLIB_VERSION , (int )sizeof (z_stream ));
1167
- }
1168
-
1169
- int zlib_deflate (z_streamp strm , int flush ) { return deflate (strm , flush ); }
1170
-
1171
- int zlib_deflateEnd (z_streamp strm ) { return deflateEnd (strm ); }
1172
-
1173
- int zlib_inflateInit (z_streamp strm ) {
1174
- return inflateInit_ (strm , ZLIB_VERSION , (int )sizeof (z_stream ));
1175
- }
1176
-
1177
- int zlib_inflate (z_streamp strm , int flush ) { return inflate (strm , flush ); }
1178
- int zlib_inflateEnd (z_streamp strm ) { return inflateEnd (strm ); }
1179
-
1180
1161
typedef struct ZInfo {
1181
1162
z_stream strm ;
1182
1163
unsigned char buffer [32 * 1024 ];
@@ -1209,7 +1190,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
1209
1190
int ret ;
1210
1191
z_info -> strm .avail_out = sizeof (z_info -> buffer );
1211
1192
z_info -> strm .next_out = z_info -> buffer ;
1212
- ret = zlib_deflate (& z_info -> strm , Z_FINISH );
1193
+ ret = deflate (& z_info -> strm , Z_FINISH );
1213
1194
assert (ret != Z_STREAM_ERROR );
1214
1195
output_size = sizeof (z_info -> buffer ) - z_info -> strm .avail_out ;
1215
1196
if (output_size > 0 ) {
@@ -1221,7 +1202,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
1221
1202
} else {
1222
1203
// Only dump the output buffer when it is full.
1223
1204
do {
1224
- int ret = zlib_deflate (& z_info -> strm , Z_NO_FLUSH );
1205
+ int ret = deflate (& z_info -> strm , Z_NO_FLUSH );
1225
1206
assert (ret != Z_STREAM_ERROR );
1226
1207
if (z_info -> strm .avail_out == 0 ) {
1227
1208
if (fwrite (z_info -> buffer , sizeof (z_info -> buffer ), 1 , of ) != 1 ) {
@@ -1491,7 +1472,8 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1491
1472
z_info .strm .opaque = Z_NULL ;
1492
1473
z_info .strm .avail_out = sizeof (z_info .buffer );
1493
1474
z_info .strm .next_out = z_info .buffer ;
1494
- ret = zlib_deflateInit (& z_info .strm , Z_BEST_COMPRESSION );
1475
+ deflateInit_ (& z_info .strm , Z_BEST_COMPRESSION , ZLIB_VERSION ,
1476
+ (int )sizeof (z_stream ));
1495
1477
if (ret != Z_OK ) {
1496
1478
fprintf (stderr , "acl_pkg_pack: Unable to initialize zlib for writing %s\n" ,
1497
1479
out_file );
@@ -1506,7 +1488,7 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1506
1488
if (result == PACK_END ) {
1507
1489
// We had a failure; stop here.
1508
1490
fclose (of );
1509
- zlib_deflateEnd (& z_info .strm );
1491
+ deflateEnd (& z_info .strm );
1510
1492
return 0 ;
1511
1493
}
1512
1494
input_files_dirs ++ ;
@@ -1520,10 +1502,10 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1520
1502
if (fclose (of ) != 0 ) {
1521
1503
fprintf (stderr , "acl_pkg_pack: Write of %s failed: %s\n" , out_file ,
1522
1504
strerror (errno ));
1523
- zlib_deflateEnd (& z_info .strm );
1505
+ deflateEnd (& z_info .strm );
1524
1506
return 0 ;
1525
1507
}
1526
- zlib_deflateEnd (& z_info .strm );
1508
+ deflateEnd (& z_info .strm );
1527
1509
return 1 /* success */ ;
1528
1510
}
1529
1511
@@ -1549,7 +1531,7 @@ static int read_data(void *data, size_t size, ZInfo *z_info, FILE *in_fd) {
1549
1531
z_info -> strm .next_in = z_info -> buffer ;
1550
1532
}
1551
1533
// Grab the next chunk of data from the input buffer.
1552
- ret = zlib_inflate (& z_info -> strm , Z_NO_FLUSH );
1534
+ ret = inflate (& z_info -> strm , Z_NO_FLUSH );
1553
1535
assert (ret != Z_STREAM_ERROR );
1554
1536
if (ret == Z_STREAM_END ) {
1555
1537
// Last bit of data.
@@ -1605,7 +1587,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1605
1587
z_info .strm .avail_in = 0 ;
1606
1588
z_info .strm .next_in = NULL ;
1607
1589
}
1608
- ret = zlib_inflateInit (& z_info .strm );
1590
+ ret = inflateInit_ (& z_info .strm , ZLIB_VERSION , ( int ) sizeof ( z_stream ) );
1609
1591
if (ret != Z_OK ) {
1610
1592
fprintf (stderr , "%s: Unable to initialize zlib for reading from buffer\n" ,
1611
1593
routine_name );
@@ -1626,13 +1608,13 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1626
1608
acl_pkg_pack_info info ;
1627
1609
if (!read_data (& info , sizeof (info ), & z_info , input )) {
1628
1610
fprintf (stderr , "%s: Error reading from buffer\n" , routine_name );
1629
- zlib_inflateEnd (& z_info .strm );
1611
+ inflateEnd (& z_info .strm );
1630
1612
return 0 ;
1631
1613
}
1632
1614
if (info .magic != PACK_MAGIC ) {
1633
1615
fprintf (stderr , "%s: Incorrect magic number read from buffer\n" ,
1634
1616
routine_name );
1635
- zlib_inflateEnd (& z_info .strm );
1617
+ inflateEnd (& z_info .strm );
1636
1618
return 0 ;
1637
1619
}
1638
1620
@@ -1645,7 +1627,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1645
1627
if (!read_data (name , info .name_length , & z_info , input )) {
1646
1628
fprintf (stderr , "%s: Error reading file name from buffer\n" ,
1647
1629
routine_name );
1648
- zlib_inflateEnd (& z_info .strm );
1630
+ inflateEnd (& z_info .strm );
1649
1631
return 0 ;
1650
1632
}
1651
1633
@@ -1671,7 +1653,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1671
1653
if (out_file == NULL ) {
1672
1654
fprintf (stderr , "%s: Unable to open %s for writing: %s\n" , routine_name ,
1673
1655
full_name , strerror (errno ));
1674
- zlib_inflateEnd (& z_info .strm );
1656
+ inflateEnd (& z_info .strm );
1675
1657
return 0 ;
1676
1658
}
1677
1659
if (info .file_length > 0 ) {
@@ -1681,14 +1663,14 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1681
1663
fprintf (stderr , "%s: Error reading file data for %s from buffer\n" ,
1682
1664
routine_name , full_name );
1683
1665
fclose (out_file );
1684
- zlib_inflateEnd (& z_info .strm );
1666
+ inflateEnd (& z_info .strm );
1685
1667
return 0 ;
1686
1668
}
1687
1669
if (fwrite (buf , info .file_length , 1 , out_file ) != 1 ) {
1688
1670
fprintf (stderr , "%s: Failed to write to %s: %s\n" , routine_name ,
1689
1671
full_name , strerror (errno ));
1690
1672
fclose (out_file );
1691
- zlib_inflateEnd (& z_info .strm );
1673
+ inflateEnd (& z_info .strm );
1692
1674
return 0 ;
1693
1675
}
1694
1676
} else {
@@ -1698,23 +1680,23 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1698
1680
routine_name , full_name , strerror (errno ));
1699
1681
fclose (out_file );
1700
1682
free (buf2 );
1701
- zlib_inflateEnd (& z_info .strm );
1683
+ inflateEnd (& z_info .strm );
1702
1684
return PACK_END ;
1703
1685
}
1704
1686
if (!read_data (buf2 , info .file_length , & z_info , input )) {
1705
1687
fprintf (stderr , "%s: Error reading file data for %s from buffer\n" ,
1706
1688
routine_name , full_name );
1707
1689
fclose (out_file );
1708
1690
free (buf2 );
1709
- zlib_inflateEnd (& z_info .strm );
1691
+ inflateEnd (& z_info .strm );
1710
1692
return 0 ;
1711
1693
}
1712
1694
if (fwrite (buf2 , info .file_length , 1 , out_file ) != 1 ) {
1713
1695
fprintf (stderr , "%s: Failed to write to %s: %s\n" , routine_name ,
1714
1696
full_name , strerror (errno ));
1715
1697
fclose (out_file );
1716
1698
free (buf2 );
1717
- zlib_inflateEnd (& z_info .strm );
1699
+ inflateEnd (& z_info .strm );
1718
1700
return 0 ;
1719
1701
}
1720
1702
free (buf2 );
@@ -1724,7 +1706,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1724
1706
}
1725
1707
}
1726
1708
1727
- zlib_inflateEnd (& z_info .strm );
1709
+ inflateEnd (& z_info .strm );
1728
1710
return 1 ;
1729
1711
}
1730
1712
@@ -1758,23 +1740,3 @@ int acl_pkg_unpack(const char *in_file, const char *out_dir) {
1758
1740
}
1759
1741
return ret ;
1760
1742
}
1761
-
1762
- #else // USE_ZLIB
1763
-
1764
- int acl_pkg_pack (const char * out_file , const char * * input_files_dirs ) {
1765
- // Not implemented if no ZLIB
1766
- return 0 ;
1767
- }
1768
-
1769
- int acl_pkg_unpack (const char * in_file , const char * out_dir ) {
1770
- // Not implemented if no ZLIB
1771
- return 0 ;
1772
- }
1773
-
1774
- int acl_pkg_unpack_buffer (const char * buffer , size_t buffer_size ,
1775
- const char * out_dir ) {
1776
- // Not implemented if no ZLIB
1777
- return 0 ;
1778
- }
1779
-
1780
- #endif // USE_ZLIB
0 commit comments