From cf884a6a170dd9b93ae7b8871fb7db697a18a1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 11 Nov 2024 10:17:43 +0100 Subject: [PATCH] refactor _unzOpen_stream --- compat/unzip.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/compat/unzip.c b/compat/unzip.c index aa025bb5..7728a157 100644 --- a/compat/unzip.c +++ b/compat/unzip.c @@ -20,6 +20,8 @@ #include "unzip.h" +unzFile _unzOpen_stream(const void *path, void *stream); + /***************************************************************************/ typedef struct mz_unzip_compat_s { @@ -41,7 +43,6 @@ unzFile unzOpen64(const void *path) { } unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def) { - unzFile unz = NULL; void *stream = NULL; if (pzlib_filefunc_def) { @@ -57,28 +58,10 @@ unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def) { } } - if (!stream) { - stream = mz_stream_os_create(); - if (!stream) - return NULL; - } - - if (mz_stream_open(stream, path, MZ_OPEN_MODE_READ) != MZ_OK) { - mz_stream_delete(&stream); - return NULL; - } - - unz = unzOpen_MZ(stream); - if (!unz) { - mz_stream_close(stream); - mz_stream_delete(&stream); - return NULL; - } - return unz; + return _unzOpen_stream(path, stream); } unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def) { - unzFile unz = NULL; void *stream = NULL; if (pzlib_filefunc_def) { @@ -94,6 +77,12 @@ unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def) { } } + return _unzOpen_stream(path, stream); +} + +unzFile _unzOpen_stream(const void *path, void *stream) { + unzFile unz = NULL; + if (!stream) { stream = mz_stream_os_create(); if (!stream)