Skip to content

Commit 2512bdb

Browse files
committed
fix: check zip_source_t
Signed-off-by: imkiva <[email protected]>
1 parent 91e1e82 commit 2512bdb

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ if (HAVE_ZIP_H)
8585
int main(int argc, char *argv[]) { zip_flags_t flag = 0; }" HAVE_ZIP_FLAGS_T)
8686
check_c_source_compiles("#include <zip.h>
8787
int main(int argc, char *argv[]) { unsigned int flag = ZIP_FL_ENC_GUESS; }" HAVE_ZIP_FL_ENC_GUESS)
88+
check_c_source_compiles("#include <zip.h>
89+
int main(int argc, char *argv[]) { zip_source_t *src; }" HAVE_ZIP_SOURCE_T)
8890

8991
# check libz if libzip is required
9092
if (NOT EXISTS "/system/framework/framework-res.apk")

cmake/cmake-config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifdef HAVE_CONFIG_H
44

55
#cmakedefine01 HAVE_ZIP_FLAGS_T
6+
#cmakedefine01 HAVE_ZIP_SOURCE_T
67
#cmakedefine01 HAVE_ZIP_FL_ENC_GUESS
78
#cmakedefine01 HAVE_ZIP_H
89
#cmakedefine01 KIVM_THREADED
@@ -21,6 +22,9 @@
2122

2223
#if HAVE_ZIP_H
2324
#define KIVM_JAR_CLASS_LOADING
25+
#if HAVE_ZIP_SOURCE_T
26+
#define KIVM_ZIP_OPEN_SOURCE
27+
#endif
2428
#endif
2529

2630
#if KIVM_ARCH_x86_64 || KIVM_ARCH_x86

include/shared/zip/libzippp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242

4343
//defined in libzip
4444
struct zip;
45+
46+
#ifdef KIVM_ZIP_OPEN_SOURCE
4547
struct zip_source;
48+
#endif
4649

4750
#define DIRECTORY_SEPARATOR '/'
4851
#define IS_DIRECTORY(str) ((str).length()>0 && (str)[(str).length()-1]==DIRECTORY_SEPARATOR)
@@ -131,7 +134,9 @@ namespace libzippp {
131134
*/
132135
explicit ZipArchive(const kivm::String &zipPath);
133136

137+
#ifdef KIVM_ZIP_OPEN_SOURCE
134138
explicit ZipArchive(const kivm::String &bufferName, void *buffer, size_t bufferSize);
139+
#endif
135140

136141
~ZipArchive(); //commit all the changes if open
137142

@@ -267,9 +272,12 @@ namespace libzippp {
267272
private:
268273
std::string path;
269274
zip *zipHandle;
275+
276+
#ifdef KIVM_ZIP_OPEN_SOURCE
270277
zip_source *zipSource;
271278
void *zipBuffer;
272279
size_t zipBufferSize;
280+
#endif
273281
OpenMode mode;
274282

275283
//generic method to create ZipEntry

src/shared/zip/libzippp.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ int ZipEntry::readContent(std::ofstream &ofOutput, ZipArchive::State state, libz
8080
ZipArchive::ZipArchive(const kivm::String &zipPath)
8181
: path(kivm::strings::toStdString(zipPath)),
8282
zipHandle(nullptr),
83-
mode(NOT_OPEN),
84-
zipBuffer(nullptr),
85-
zipBufferSize(0),
86-
zipSource(nullptr) {
83+
#ifdef KIVM_ZIP_OPEN_SOURCE
84+
zipBuffer(nullptr),
85+
zipBufferSize(0),
86+
zipSource(nullptr),
87+
#endif
88+
mode(NOT_OPEN) {
8789
}
8890

91+
#ifdef KIVM_ZIP_OPEN_SOURCE
8992
ZipArchive::ZipArchive(const kivm::String &bufferName, void *buffer, size_t bufferSize)
9093
: path(kivm::strings::toStdString(bufferName)),
9194
zipHandle(nullptr),
@@ -94,6 +97,7 @@ ZipArchive::ZipArchive(const kivm::String &bufferName, void *buffer, size_t buff
9497
zipBufferSize(bufferSize),
9598
zipSource(nullptr) {
9699
}
100+
#endif
97101

98102
ZipArchive::~ZipArchive() {
99103
close(); /* discard ??? */
@@ -113,6 +117,7 @@ bool ZipArchive::open(OpenMode om, bool checkConsistency) {
113117

114118
int errorFlag = 0;
115119

120+
#ifdef KIVM_ZIP_OPEN_SOURCE
116121
if (zipBuffer == nullptr) {
117122
zipHandle = zip_open(path.c_str(), zipFlag, &errorFlag);
118123

@@ -133,6 +138,9 @@ bool ZipArchive::open(OpenMode om, bool checkConsistency) {
133138
}
134139
}
135140
}
141+
#else
142+
zipHandle = zip_open(path.c_str(), zipFlag, &errorFlag);
143+
#endif
136144

137145
//error during opening of the file
138146
if (errorFlag != ZIP_ER_OK) {
@@ -153,10 +161,12 @@ int ZipArchive::close() {
153161
int result = zip_close(zipHandle);
154162
zipHandle = nullptr;
155163

164+
#ifdef KIVM_ZIP_OPEN_SOURCE
156165
if (zipBuffer != nullptr && zipSource != nullptr) {
157166
zip_source_free(zipSource);
158167
zipSource = nullptr;
159168
}
169+
#endif
160170
mode = NOT_OPEN;
161171

162172
if (result != 0) { return result; }

0 commit comments

Comments
 (0)