Skip to content

Commit 1a80459

Browse files
authored
Merge branch 'main' into checked-return-1
2 parents 1bce18d + e169855 commit 1a80459

File tree

5 files changed

+20
-226
lines changed

5 files changed

+20
-226
lines changed

lib/pkg_editor/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if(ZLIB_FOUND)
2020
target_compile_definitions(pkg_editor PRIVATE WINDOWS_ZLIB_PATH="${WINDOWS_ZLIB_DLL_PATH}")
2121
endif()
2222
target_link_libraries(pkg_editor PRIVATE ZLIB::ZLIB)
23-
target_sources(pkg_editor PRIVATE src/zlib.c)
2423
endif()
2524

2625
install(TARGETS pkg_editor

lib/pkg_editor/src/pkg_editor.c

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
#endif
4040

4141
#include "pkg_editor/pkg_editor.h"
42-
#if USE_ZLIB
43-
#include "zlib_interface.h"
44-
#endif
42+
#include "zlib.h"
4543

4644
typedef struct acl_pkg_file {
4745
const char *fname;
@@ -1200,7 +1198,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
12001198
int ret;
12011199
z_info->strm.avail_out = sizeof(z_info->buffer);
12021200
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);
12041202
assert(ret != Z_STREAM_ERROR);
12051203
output_size = sizeof(z_info->buffer) - z_info->strm.avail_out;
12061204
if (output_size > 0) {
@@ -1212,7 +1210,7 @@ static int append_data(const void *data, size_t size, ZInfo *z_info, FILE *of,
12121210
} else {
12131211
// Only dump the output buffer when it is full.
12141212
do {
1215-
int ret = zlib_deflate(&z_info->strm, Z_NO_FLUSH);
1213+
int ret = deflate(&z_info->strm, Z_NO_FLUSH);
12161214
assert(ret != Z_STREAM_ERROR);
12171215
if (z_info->strm.avail_out == 0) {
12181216
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) {
14771475
z_info.strm.opaque = Z_NULL;
14781476
z_info.strm.avail_out = sizeof(z_info.buffer);
14791477
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));
14811480
if (ret != Z_OK) {
14821481
fprintf(stderr, "acl_pkg_pack: Unable to initialize zlib for writing %s\n",
14831482
out_file);
@@ -1492,7 +1491,7 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
14921491
if (result == PACK_END) {
14931492
// We had a failure; stop here.
14941493
fclose(of);
1495-
zlib_deflateEnd(&z_info.strm);
1494+
deflateEnd(&z_info.strm);
14961495
return 0;
14971496
}
14981497
input_files_dirs++;
@@ -1506,10 +1505,10 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
15061505
if (fclose(of) != 0) {
15071506
fprintf(stderr, "acl_pkg_pack: Write of %s failed: %s\n", out_file,
15081507
strerror(errno));
1509-
zlib_deflateEnd(&z_info.strm);
1508+
deflateEnd(&z_info.strm);
15101509
return 0;
15111510
}
1512-
zlib_deflateEnd(&z_info.strm);
1511+
deflateEnd(&z_info.strm);
15131512
return 1 /* success */;
15141513
}
15151514

@@ -1546,7 +1545,7 @@ static int read_data(void *data, size_t size, ZInfo *z_info, FILE *in_fd) {
15461545
z_info->strm.next_in = z_info->buffer;
15471546
}
15481547
// 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);
15501549
assert(ret != Z_STREAM_ERROR);
15511550
if (ret == Z_STREAM_END) {
15521551
// Last bit of data.
@@ -1602,7 +1601,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16021601
z_info.strm.avail_in = 0;
16031602
z_info.strm.next_in = NULL;
16041603
}
1605-
ret = zlib_inflateInit(&z_info.strm);
1604+
ret = inflateInit_(&z_info.strm, ZLIB_VERSION, (int)sizeof(z_stream));
16061605
if (ret != Z_OK) {
16071606
fprintf(stderr, "%s: Unable to initialize zlib for reading from buffer\n",
16081607
routine_name);
@@ -1618,13 +1617,13 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16181617
acl_pkg_pack_info info;
16191618
if (!read_data(&info, sizeof(info), &z_info, input)) {
16201619
fprintf(stderr, "%s: Error reading from buffer\n", routine_name);
1621-
zlib_inflateEnd(&z_info.strm);
1620+
inflateEnd(&z_info.strm);
16221621
return 0;
16231622
}
16241623
if (info.magic != PACK_MAGIC) {
16251624
fprintf(stderr, "%s: Incorrect magic number read from buffer\n",
16261625
routine_name);
1627-
zlib_inflateEnd(&z_info.strm);
1626+
inflateEnd(&z_info.strm);
16281627
return 0;
16291628
}
16301629

@@ -1637,7 +1636,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16371636
if (!read_data(name, info.name_length, &z_info, input)) {
16381637
fprintf(stderr, "%s: Error reading file name from buffer\n",
16391638
routine_name);
1640-
zlib_inflateEnd(&z_info.strm);
1639+
inflateEnd(&z_info.strm);
16411640
return 0;
16421641
}
16431642

@@ -1662,7 +1661,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16621661
if (out_file == NULL) {
16631662
fprintf(stderr, "%s: Unable to open %s for writing: %s\n", routine_name,
16641663
full_name, strerror(errno));
1665-
zlib_inflateEnd(&z_info.strm);
1664+
inflateEnd(&z_info.strm);
16661665
return 0;
16671666
}
16681667
if (info.file_length > 0) {
@@ -1672,14 +1671,14 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16721671
fprintf(stderr, "%s: Error reading file data for %s from buffer\n",
16731672
routine_name, full_name);
16741673
fclose(out_file);
1675-
zlib_inflateEnd(&z_info.strm);
1674+
inflateEnd(&z_info.strm);
16761675
return 0;
16771676
}
16781677
if (fwrite(buf, info.file_length, 1, out_file) != 1) {
16791678
fprintf(stderr, "%s: Failed to write to %s: %s\n", routine_name,
16801679
full_name, strerror(errno));
16811680
fclose(out_file);
1682-
zlib_inflateEnd(&z_info.strm);
1681+
inflateEnd(&z_info.strm);
16831682
return 0;
16841683
}
16851684
} else {
@@ -1689,23 +1688,23 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
16891688
routine_name, full_name, strerror(errno));
16901689
fclose(out_file);
16911690
free(buf2);
1692-
zlib_inflateEnd(&z_info.strm);
1691+
inflateEnd(&z_info.strm);
16931692
return PACK_END;
16941693
}
16951694
if (!read_data(buf2, info.file_length, &z_info, input)) {
16961695
fprintf(stderr, "%s: Error reading file data for %s from buffer\n",
16971696
routine_name, full_name);
16981697
fclose(out_file);
16991698
free(buf2);
1700-
zlib_inflateEnd(&z_info.strm);
1699+
inflateEnd(&z_info.strm);
17011700
return 0;
17021701
}
17031702
if (fwrite(buf2, info.file_length, 1, out_file) != 1) {
17041703
fprintf(stderr, "%s: Failed to write to %s: %s\n", routine_name,
17051704
full_name, strerror(errno));
17061705
fclose(out_file);
17071706
free(buf2);
1708-
zlib_inflateEnd(&z_info.strm);
1707+
inflateEnd(&z_info.strm);
17091708
return 0;
17101709
}
17111710
free(buf2);
@@ -1715,7 +1714,7 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
17151714
}
17161715
}
17171716

1718-
zlib_inflateEnd(&z_info.strm);
1717+
inflateEnd(&z_info.strm);
17191718
return 1;
17201719
}
17211720

@@ -1750,22 +1749,4 @@ int acl_pkg_unpack(const char *in_file, const char *out_dir) {
17501749
return ret;
17511750
}
17521751

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-
17711752
#endif // USE_ZLIB

lib/pkg_editor/src/zlib.c

Lines changed: 0 additions & 150 deletions
This file was deleted.

lib/pkg_editor/src/zlib_interface.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)