Skip to content

Commit 9b89689

Browse files
committed
Add MINIZ_NO_DEFLATE_APIS and MINIZ_NO_INFLATE_APIS
1 parent 08f2c2d commit 9b89689

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

amalgamate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ then
1818
echo "Test compile with clang..."
1919
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out
2020
fi
21-
for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC
21+
for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_DEFLATE_APIS MINIZ_NO_INFLATE_APIS MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC
2222
do
2323
echo "Test compile with GCC and define $def..."
2424
gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out -D${def}

miniz.c

+8
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ const char *mz_version(void)
186186

187187
#ifndef MINIZ_NO_ZLIB_APIS
188188

189+
#ifndef MINIZ_NO_DEFLATE_APIS
190+
189191
int mz_deflateInit(mz_streamp pStream, int level)
190192
{
191193
return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
@@ -353,6 +355,10 @@ mz_ulong mz_compressBound(mz_ulong source_len)
353355
return mz_deflateBound(NULL, source_len);
354356
}
355357

358+
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
359+
360+
#ifndef MINIZ_NO_INFLATE_APIS
361+
356362
typedef struct
357363
{
358364
tinfl_decompressor m_decomp;
@@ -588,6 +594,8 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
588594
return mz_uncompress2(pDest, pDest_len, pSource, &source_len);
589595
}
590596

597+
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
598+
591599
const char *mz_error(int err)
592600
{
593601
static struct

miniz.h

+29-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
#include "miniz_export.h"
116116

117117
/* Defines to completely disable specific portions of miniz.c:
118-
If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */
118+
If all macros here are defined the only functionality remaining will be CRC-32 and adler-32. */
119119

120120
/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
121121
/*#define MINIZ_NO_STDIO */
@@ -125,6 +125,12 @@
125125
/* The current downside is the times written to your archives will be from 1979. */
126126
/*#define MINIZ_NO_TIME */
127127

128+
/* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */
129+
/*#define MINIZ_NO_DEFLATE_APIS */
130+
131+
/* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */
132+
/*#define MINIZ_NO_INFLATE_APIS */
133+
128134
/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
129135
/*#define MINIZ_NO_ARCHIVE_APIS */
130136

@@ -143,6 +149,14 @@
143149
functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
144150
/*#define MINIZ_NO_MALLOC */
145151

152+
#ifdef MINIZ_NO_INFLATE_APIS
153+
#define MINIZ_NO_ARCHIVE_APIS
154+
#endif
155+
156+
#ifdef MINIZ_NO_DEFLATE_APIS
157+
#define MINIZ_NO_ARCHIVE_WRITING_APIS
158+
#endif
159+
146160
#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
147161
/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */
148162
#define MINIZ_NO_TIME
@@ -304,6 +318,8 @@ typedef mz_stream *mz_streamp;
304318
/* Returns the version string of miniz.c. */
305319
MINIZ_EXPORT const char *mz_version(void);
306320

321+
#ifndef MINIZ_NO_DEFLATE_APIS
322+
307323
/* mz_deflateInit() initializes a compressor with default options: */
308324
/* Parameters: */
309325
/* pStream must point to an initialized mz_stream struct. */
@@ -356,6 +372,10 @@ MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const u
356372
/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */
357373
MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len);
358374

375+
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
376+
377+
#ifndef MINIZ_NO_INFLATE_APIS
378+
359379
/* Initializes a decompressor. */
360380
MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream);
361381

@@ -389,6 +409,7 @@ MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
389409
/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
390410
MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
391411
MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len);
412+
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
392413

393414
/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
394415
MINIZ_EXPORT const char *mz_error(int err);
@@ -439,6 +460,8 @@ typedef void *const voidpc;
439460
#define free_func mz_free_func
440461
#define internal_state mz_internal_state
441462
#define z_stream mz_stream
463+
464+
#ifndef MINIZ_NO_DEFLATE_APIS
442465
#define deflateInit mz_deflateInit
443466
#define deflateInit2 mz_deflateInit2
444467
#define deflateReset mz_deflateReset
@@ -448,13 +471,18 @@ typedef void *const voidpc;
448471
#define compress mz_compress
449472
#define compress2 mz_compress2
450473
#define compressBound mz_compressBound
474+
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
475+
476+
#ifndef MINIZ_NO_INFLATE_APIS
451477
#define inflateInit mz_inflateInit
452478
#define inflateInit2 mz_inflateInit2
453479
#define inflateReset mz_inflateReset
454480
#define inflate mz_inflate
455481
#define inflateEnd mz_inflateEnd
456482
#define uncompress mz_uncompress
457483
#define uncompress2 mz_uncompress2
484+
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
485+
458486
#define crc32 mz_crc32
459487
#define adler32 mz_adler32
460488
#define MAX_WBITS 15

miniz_tdef.c

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "miniz.h"
2828

29+
#ifndef MINIZ_NO_DEFLATE_APIS
30+
2931
#ifdef __cplusplus
3032
extern "C" {
3133
#endif
@@ -1575,3 +1577,5 @@ void tdefl_compressor_free(tdefl_compressor *pComp)
15751577
#ifdef __cplusplus
15761578
}
15771579
#endif
1580+
1581+
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/

miniz_tdef.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22
#include "miniz_common.h"
33

4+
#ifndef MINIZ_NO_DEFLATE_APIS
5+
46
#ifdef __cplusplus
57
extern "C" {
68
#endif
@@ -188,3 +190,5 @@ MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor *pComp);
188190
#ifdef __cplusplus
189191
}
190192
#endif
193+
194+
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/

miniz_tinfl.c

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "miniz.h"
2828

29+
#ifndef MINIZ_NO_INFLATE_APIS
30+
2931
#ifdef __cplusplus
3032
extern "C" {
3133
#endif
@@ -738,3 +740,5 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
738740
#ifdef __cplusplus
739741
}
740742
#endif
743+
744+
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/

miniz_tinfl.h

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "miniz_common.h"
33
/* ------------------- Low-level Decompression API Definitions */
44

5+
#ifndef MINIZ_NO_INFLATE_APIS
6+
57
#ifdef __cplusplus
68
extern "C" {
79
#endif
@@ -142,3 +144,5 @@ struct tinfl_decompressor_tag
142144
#ifdef __cplusplus
143145
}
144146
#endif
147+
148+
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/

0 commit comments

Comments
 (0)