39
39
#endif
40
40
41
41
#include "pkg_editor/pkg_editor.h"
42
- #if USE_ZLIB
43
- #include "zlib_interface.h"
44
- #endif
42
+ #include "zlib.h"
45
43
46
44
typedef struct acl_pkg_file {
47
45
const char * fname ;
@@ -1200,7 +1198,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
1200
1198
int ret ;
1201
1199
z_info -> strm .avail_out = sizeof (z_info -> buffer );
1202
1200
z_info -> strm .next_out = z_info -> buffer ;
1203
- ret = zlib_deflate (& z_info -> strm , Z_FINISH );
1201
+ ret = deflate (& z_info -> strm , Z_FINISH );
1204
1202
assert (ret != Z_STREAM_ERROR );
1205
1203
output_size = sizeof (z_info -> buffer ) - z_info -> strm .avail_out ;
1206
1204
if (output_size > 0 ) {
@@ -1212,7 +1210,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
1212
1210
} else {
1213
1211
// Only dump the output buffer when it is full.
1214
1212
do {
1215
- int ret = zlib_deflate (& z_info -> strm , Z_NO_FLUSH );
1213
+ int ret = deflate (& z_info -> strm , Z_NO_FLUSH );
1216
1214
assert (ret != Z_STREAM_ERROR );
1217
1215
if (z_info -> strm .avail_out == 0 ) {
1218
1216
if (fwrite (z_info -> buffer , sizeof (z_info -> buffer ), 1 , of ) != 1 ) {
@@ -1477,7 +1475,8 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1477
1475
z_info .strm .opaque = Z_NULL ;
1478
1476
z_info .strm .avail_out = sizeof (z_info .buffer );
1479
1477
z_info .strm .next_out = z_info .buffer ;
1480
- ret = zlib_deflateInit (& z_info .strm , Z_BEST_COMPRESSION );
1478
+ ret = deflateInit_ (& z_info .strm , Z_BEST_COMPRESSION , ZLIB_VERSION ,
1479
+ (int )sizeof (z_stream ));
1481
1480
if (ret != Z_OK ) {
1482
1481
fprintf (stderr , "acl_pkg_pack: Unable to initialize zlib for writing %s\n" ,
1483
1482
out_file );
@@ -1492,7 +1491,7 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1492
1491
if (result == PACK_END ) {
1493
1492
// We had a failure; stop here.
1494
1493
fclose (of );
1495
- zlib_deflateEnd (& z_info .strm );
1494
+ deflateEnd (& z_info .strm );
1496
1495
return 0 ;
1497
1496
}
1498
1497
input_files_dirs ++ ;
@@ -1506,10 +1505,10 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
1506
1505
if (fclose (of ) != 0 ) {
1507
1506
fprintf (stderr , "acl_pkg_pack: Write of %s failed: %s\n" , out_file ,
1508
1507
strerror (errno ));
1509
- zlib_deflateEnd (& z_info .strm );
1508
+ deflateEnd (& z_info .strm );
1510
1509
return 0 ;
1511
1510
}
1512
- zlib_deflateEnd (& z_info .strm );
1511
+ deflateEnd (& z_info .strm );
1513
1512
return 1 /* success */ ;
1514
1513
}
1515
1514
@@ -1546,7 +1545,7 @@ static int read_data(void *data, size_t size, ZInfo *z_info, FILE *in_fd) {
1546
1545
z_info -> strm .next_in = z_info -> buffer ;
1547
1546
}
1548
1547
// Grab the next chunk of data from the input buffer.
1549
- ret = zlib_inflate (& z_info -> strm , Z_NO_FLUSH );
1548
+ ret = inflate (& z_info -> strm , Z_NO_FLUSH );
1550
1549
assert (ret != Z_STREAM_ERROR );
1551
1550
if (ret == Z_STREAM_END ) {
1552
1551
// Last bit of data.
@@ -1602,7 +1601,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1602
1601
z_info .strm .avail_in = 0 ;
1603
1602
z_info .strm .next_in = NULL ;
1604
1603
}
1605
- ret = zlib_inflateInit (& z_info .strm );
1604
+ ret = inflateInit_ (& z_info .strm , ZLIB_VERSION , ( int ) sizeof ( z_stream ) );
1606
1605
if (ret != Z_OK ) {
1607
1606
fprintf (stderr , "%s: Unable to initialize zlib for reading from buffer\n" ,
1608
1607
routine_name );
@@ -1618,13 +1617,13 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1618
1617
acl_pkg_pack_info info ;
1619
1618
if (!read_data (& info , sizeof (info ), & z_info , input )) {
1620
1619
fprintf (stderr , "%s: Error reading from buffer\n" , routine_name );
1621
- zlib_inflateEnd (& z_info .strm );
1620
+ inflateEnd (& z_info .strm );
1622
1621
return 0 ;
1623
1622
}
1624
1623
if (info .magic != PACK_MAGIC ) {
1625
1624
fprintf (stderr , "%s: Incorrect magic number read from buffer\n" ,
1626
1625
routine_name );
1627
- zlib_inflateEnd (& z_info .strm );
1626
+ inflateEnd (& z_info .strm );
1628
1627
return 0 ;
1629
1628
}
1630
1629
@@ -1637,7 +1636,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1637
1636
if (!read_data (name , info .name_length , & z_info , input )) {
1638
1637
fprintf (stderr , "%s: Error reading file name from buffer\n" ,
1639
1638
routine_name );
1640
- zlib_inflateEnd (& z_info .strm );
1639
+ inflateEnd (& z_info .strm );
1641
1640
return 0 ;
1642
1641
}
1643
1642
@@ -1662,7 +1661,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1662
1661
if (out_file == NULL ) {
1663
1662
fprintf (stderr , "%s: Unable to open %s for writing: %s\n" , routine_name ,
1664
1663
full_name , strerror (errno ));
1665
- zlib_inflateEnd (& z_info .strm );
1664
+ inflateEnd (& z_info .strm );
1666
1665
return 0 ;
1667
1666
}
1668
1667
if (info .file_length > 0 ) {
@@ -1672,14 +1671,14 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1672
1671
fprintf (stderr , "%s: Error reading file data for %s from buffer\n" ,
1673
1672
routine_name , full_name );
1674
1673
fclose (out_file );
1675
- zlib_inflateEnd (& z_info .strm );
1674
+ inflateEnd (& z_info .strm );
1676
1675
return 0 ;
1677
1676
}
1678
1677
if (fwrite (buf , info .file_length , 1 , out_file ) != 1 ) {
1679
1678
fprintf (stderr , "%s: Failed to write to %s: %s\n" , routine_name ,
1680
1679
full_name , strerror (errno ));
1681
1680
fclose (out_file );
1682
- zlib_inflateEnd (& z_info .strm );
1681
+ inflateEnd (& z_info .strm );
1683
1682
return 0 ;
1684
1683
}
1685
1684
} else {
@@ -1689,23 +1688,23 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1689
1688
routine_name , full_name , strerror (errno ));
1690
1689
fclose (out_file );
1691
1690
free (buf2 );
1692
- zlib_inflateEnd (& z_info .strm );
1691
+ inflateEnd (& z_info .strm );
1693
1692
return PACK_END ;
1694
1693
}
1695
1694
if (!read_data (buf2 , info .file_length , & z_info , input )) {
1696
1695
fprintf (stderr , "%s: Error reading file data for %s from buffer\n" ,
1697
1696
routine_name , full_name );
1698
1697
fclose (out_file );
1699
1698
free (buf2 );
1700
- zlib_inflateEnd (& z_info .strm );
1699
+ inflateEnd (& z_info .strm );
1701
1700
return 0 ;
1702
1701
}
1703
1702
if (fwrite (buf2 , info .file_length , 1 , out_file ) != 1 ) {
1704
1703
fprintf (stderr , "%s: Failed to write to %s: %s\n" , routine_name ,
1705
1704
full_name , strerror (errno ));
1706
1705
fclose (out_file );
1707
1706
free (buf2 );
1708
- zlib_inflateEnd (& z_info .strm );
1707
+ inflateEnd (& z_info .strm );
1709
1708
return 0 ;
1710
1709
}
1711
1710
free (buf2 );
@@ -1715,7 +1714,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
1715
1714
}
1716
1715
}
1717
1716
1718
- zlib_inflateEnd (& z_info .strm );
1717
+ inflateEnd (& z_info .strm );
1719
1718
return 1 ;
1720
1719
}
1721
1720
@@ -1750,22 +1749,4 @@ int acl_pkg_unpack(const char *in_file, const char *out_dir) {
1750
1749
return ret ;
1751
1750
}
1752
1751
1753
- #else // USE_ZLIB
1754
-
1755
- int acl_pkg_pack (const char * out_file , const char * * input_files_dirs ) {
1756
- // Not implemented if no ZLIB
1757
- return 0 ;
1758
- }
1759
-
1760
- int acl_pkg_unpack (const char * in_file , const char * out_dir ) {
1761
- // Not implemented if no ZLIB
1762
- return 0 ;
1763
- }
1764
-
1765
- int acl_pkg_unpack_buffer (const char * buffer , size_t buffer_size ,
1766
- const char * out_dir ) {
1767
- // Not implemented if no ZLIB
1768
- return 0 ;
1769
- }
1770
-
1771
1752
#endif // USE_ZLIB
0 commit comments