Skip to content

Commit 1c6ca86

Browse files
committed
Fix compilation with the various omission compile definitions
1 parent 2337db2 commit 1c6ca86

File tree

6 files changed

+49
-37
lines changed

6 files changed

+49
-37
lines changed

amalgamate.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ do
2323
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c
2424
done
2525

26-
2726
echo "int main() { return 0; }" > main.c
27+
echo "Test compile with GCC..."
2828
gcc -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
29+
echo "Test compile with GCC ANSI..."
2930
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
3031
if command -v clang
3132
then
33+
echo "Test compile with clang..."
3234
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out
3335
fi
36+
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
37+
do
38+
echo "Test compile with GCC and define $def..."
39+
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out -D${def}
40+
done
3441
rm test.out
3542
rm main.c
3643

miniz.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ void mz_free(void *p)
157157
MZ_FREE(p);
158158
}
159159

160-
#ifndef MINIZ_NO_ZLIB_APIS
161-
162160
void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
163161
{
164162
(void)opaque, (void)items, (void)size;
@@ -180,6 +178,8 @@ const char *mz_version(void)
180178
return MZ_VERSION;
181179
}
182180

181+
#ifndef MINIZ_NO_ZLIB_APIS
182+
183183
int mz_deflateInit(mz_streamp pStream, int level)
184184
{
185185
return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);

miniz.h

+23-22
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
131131
/*#define MINIZ_NO_ARCHIVE_APIS */
132132

133-
/* Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's. */
133+
/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */
134134
/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */
135135

136136
/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */
@@ -150,6 +150,8 @@
150150
#define MINIZ_NO_TIME
151151
#endif
152152

153+
#include <stddef.h>
154+
153155
#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
154156
#include <time.h>
155157
#endif
@@ -207,22 +209,32 @@ enum
207209
/* Method */
208210
#define MZ_DEFLATED 8
209211

210-
#ifndef MINIZ_NO_ZLIB_APIS
211-
212212
/* Heap allocation callbacks.
213-
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
213+
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
214214
typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
215-
typedef void (*mz_free_func)(void *opaque, void *address);
215+
typedef void(*mz_free_func)(void *opaque, void *address);
216216
typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
217217

218-
/* TODO: I can't encode "1.16" here, argh */
219-
#define MZ_VERSION "9.1.15"
220-
#define MZ_VERNUM 0x91F0
221-
#define MZ_VER_MAJOR 9
222-
#define MZ_VER_MINOR 1
223-
#define MZ_VER_REVISION 15
218+
/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
219+
enum
220+
{
221+
MZ_NO_COMPRESSION = 0,
222+
MZ_BEST_SPEED = 1,
223+
MZ_BEST_COMPRESSION = 9,
224+
MZ_UBER_COMPRESSION = 10,
225+
MZ_DEFAULT_LEVEL = 6,
226+
MZ_DEFAULT_COMPRESSION = -1
227+
};
228+
229+
#define MZ_VERSION "10.0.0"
230+
#define MZ_VERNUM 0xA000
231+
#define MZ_VER_MAJOR 10
232+
#define MZ_VER_MINOR 0
233+
#define MZ_VER_REVISION 0
224234
#define MZ_VER_SUBREVISION 0
225235

236+
#ifndef MINIZ_NO_ZLIB_APIS
237+
226238
/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). */
227239
enum
228240
{
@@ -249,17 +261,6 @@ enum
249261
MZ_PARAM_ERROR = -10000
250262
};
251263

252-
/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
253-
enum
254-
{
255-
MZ_NO_COMPRESSION = 0,
256-
MZ_BEST_SPEED = 1,
257-
MZ_BEST_COMPRESSION = 9,
258-
MZ_UBER_COMPRESSION = 10,
259-
MZ_DEFAULT_LEVEL = 6,
260-
MZ_DEFAULT_COMPRESSION = -1
261-
};
262-
263264
/* Window bits */
264265
#define MZ_DEFAULT_WINDOW_BITS 15
265266

miniz_tdef.c

-2
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,6 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void
14081408
return out_buf.m_size;
14091409
}
14101410

1411-
#ifndef MINIZ_NO_ZLIB_APIS
14121411
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
14131412

14141413
/* level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files). */
@@ -1431,7 +1430,6 @@ mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int
14311430

14321431
return comp_flags;
14331432
}
1434-
#endif /*MINIZ_NO_ZLIB_APIS */
14351433

14361434
#ifdef _MSC_VER
14371435
#pragma warning(push)

miniz_tdef.h

-3
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,11 @@ tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, siz
173173
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
174174
mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
175175

176-
/* Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros. */
177-
#ifndef MINIZ_NO_ZLIB_APIS
178176
/* Create tdefl_compress() flags given zlib-style compression parameters. */
179177
/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
180178
/* window_bits may be -15 (raw deflate) or 15 (zlib) */
181179
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
182180
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
183-
#endif /* #ifndef MINIZ_NO_ZLIB_APIS */
184181

185182
/* Allocate the tdefl_compressor structure in C so that */
186183
/* non-C language bindings to tdefl_ API don't need to worry about */

miniz_zip.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
**************************************************************************/
2727
#include "miniz_zip.h"
2828

29+
#ifndef MINIZ_NO_ARCHIVE_APIS
30+
2931
#ifdef __cplusplus
3032
extern "C" {
3133
#endif
@@ -368,6 +370,7 @@ static MZ_TIME_T mz_zip_dos_to_time_t(int dos_time, int dos_date)
368370
return mktime(&tm);
369371
}
370372

373+
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
371374
static void mz_zip_time_t_to_dos_time(MZ_TIME_T time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
372375
{
373376
#ifdef _MSC_VER
@@ -387,8 +390,10 @@ static void mz_zip_time_t_to_dos_time(MZ_TIME_T time, mz_uint16 *pDOS_time, mz_u
387390
*pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
388391
*pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
389392
}
393+
#endif /* MINIZ_NO_ARCHIVE_WRITING_APIS */
390394

391395
#ifndef MINIZ_NO_STDIO
396+
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
392397
static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *pTime)
393398
{
394399
struct MZ_FILE_STAT_STRUCT file_stat;
@@ -401,6 +406,7 @@ static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *p
401406

402407
return MZ_TRUE;
403408
}
409+
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS*/
404410

405411
static mz_bool mz_zip_set_file_times(const char *pFilename, MZ_TIME_T access_time, MZ_TIME_T modified_time)
406412
{
@@ -2865,20 +2871,18 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
28652871
if (!mz_zip_writer_validate_archive_name(pArchive_name))
28662872
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
28672873

2874+
#ifndef MINIZ_NO_TIME
28682875
if (last_modified != NULL)
28692876
{
28702877
mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date);
28712878
}
28722879
else
28732880
{
2874-
#ifndef MINIZ_NO_TIME
2875-
{
2876-
MZ_TIME_T cur_time;
2877-
time(&cur_time);
2878-
mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
2879-
}
2880-
#endif /* #ifndef MINIZ_NO_TIME */
2881+
MZ_TIME_T cur_time;
2882+
time(&cur_time);
2883+
mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
28812884
}
2885+
#endif /* #ifndef MINIZ_NO_TIME */
28822886

28832887
archive_name_size = strlen(pArchive_name);
28842888
if (archive_name_size > MZ_UINT16_MAX)
@@ -4339,12 +4343,17 @@ mz_bool mz_zip_end(mz_zip_archive *pZip)
43394343

43404344
if (pZip->m_zip_mode == MZ_ZIP_MODE_READING)
43414345
return mz_zip_reader_end(pZip);
4346+
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
43424347
else if ((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))
43434348
return mz_zip_writer_end(pZip);
4349+
#endif
43444350

43454351
return MZ_FALSE;
43464352
}
43474353

43484354
#ifdef __cplusplus
43494355
}
43504356
#endif
4357+
4358+
#endif /*#ifndef MINIZ_NO_ARCHIVE_APIS*/
4359+

0 commit comments

Comments
 (0)