From 2fa13ca8a3cf196345001c9fe17bf42ee32c00f9 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 6 Dec 2024 21:30:38 +0100 Subject: [PATCH] Replace defines with function wrappers etc. as much as possible --- miniz.h | 116 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 22 deletions(-) diff --git a/miniz.h b/miniz.h index 61fb6db..46bf701 100644 --- a/miniz.h +++ b/miniz.h @@ -479,44 +479,116 @@ extern "C" #define Z_FIXED MZ_FIXED #define Z_DEFLATED MZ_DEFLATED #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS -#define alloc_func mz_alloc_func -#define free_func mz_free_func + /* See mz_alloc_func */ + typedef void *(*alloc_func)(void *opaque, size_t items, size_t size); + /* See mz_free_func */ + typedef void (*free_func)(void *opaque, void *address); + #define internal_state mz_internal_state #define z_stream mz_stream #ifndef MINIZ_NO_DEFLATE_APIS -#define deflateInit mz_deflateInit -#define deflateInit2 mz_deflateInit2 -#define deflateReset mz_deflateReset -#define deflate mz_deflate -#define deflateEnd mz_deflateEnd -#define deflateBound mz_deflateBound -#define compress mz_compress -#define compress2 mz_compress2 -#define compressBound mz_compressBound + /* Compatiblity with zlib API. See called functions for documentation */ + static int deflateInit(mz_streamp pStream, int level) + { + return mz_deflateInit(pStream, level); + } + static int deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy) + { + return mz_deflateInit2(pStream, level, method, window_bits, mem_level, strategy); + } + static int deflateReset(mz_streamp pStream) + { + return mz_deflateReset(pStream); + } + static int deflate(mz_streamp pStream, int flush) + { + return mz_deflate(pStream, flush); + } + static int deflateEnd(mz_streamp pStream) + { + return mz_deflateEnd(pStream); + } + static mz_ulong deflateBound(mz_streamp pStream, mz_ulong source_len) + { + return mz_deflateBound(pStream, source_len); + } + static int compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) + { + return mz_compress(pDest, pDest_len, pSource, source_len); + } + static int compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level) + { + return mz_compress2(pDest, pDest_len, pSource, source_len, level); + } + static mz_ulong compressBound(mz_ulong source_len) + { + return mz_compressBound(source_len); + } #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ #ifndef MINIZ_NO_INFLATE_APIS -#define inflateInit mz_inflateInit -#define inflateInit2 mz_inflateInit2 -#define inflateReset mz_inflateReset -#define inflate mz_inflate -#define inflateEnd mz_inflateEnd -#define uncompress mz_uncompress -#define uncompress2 mz_uncompress2 + /* Compatiblity with zlib API. See called functions for documentation */ + static int inflateInit(mz_streamp pStream) + { + return mz_inflateInit(pStream); + } + + static int inflateInit2(mz_streamp pStream, int window_bits) + { + return mz_inflateInit2(pStream, window_bits); + } + + static int inflateReset(mz_streamp pStream) + { + return mz_inflateReset(pStream); + } + + static int inflate(mz_streamp pStream, int flush) + { + return mz_inflate(pStream, flush); + } + + static int inflateEnd(mz_streamp pStream) + { + return mz_inflateEnd(pStream); + } + + static int uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len) + { + return mz_uncompress(pDest, pDest_len, pSource, source_len); + } + + static int uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong* pSource_len) + { + return mz_uncompress2(pDest, pDest_len, pSource, pSource_len); + } #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ -#define crc32 mz_crc32 -#define adler32 mz_adler32 + static mz_ulong crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len) + { + return mz_crc32(crc, ptr, buf_len); + } + + static mz_ulong adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) + { + return mz_adler32(adler, ptr, buf_len); + } + #define MAX_WBITS 15 #define MAX_MEM_LEVEL 9 -#define zError mz_error + + static const char* zError(int err) + { + return mz_error(err); + } #define ZLIB_VERSION MZ_VERSION #define ZLIB_VERNUM MZ_VERNUM #define ZLIB_VER_MAJOR MZ_VER_MAJOR #define ZLIB_VER_MINOR MZ_VER_MINOR #define ZLIB_VER_REVISION MZ_VER_REVISION #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION + #define zlibVersion mz_version #define zlib_version mz_version() #endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */ @@ -530,4 +602,4 @@ extern "C" #include "miniz_common.h" #include "miniz_tdef.h" #include "miniz_tinfl.h" -#include "miniz_zip.h" +#include "miniz_zip.h" \ No newline at end of file