Skip to content

Commit

Permalink
Fix compilation with the various omission compile definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
uroni committed Mar 13, 2017
1 parent 2337db2 commit 1c6ca86
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 37 deletions.
9 changes: 8 additions & 1 deletion amalgamate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ do
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c
done


echo "int main() { return 0; }" > main.c
echo "Test compile with GCC..."
gcc -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
echo "Test compile with GCC ANSI..."
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
if command -v clang
then
echo "Test compile with clang..."
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out
fi
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
do
echo "Test compile with GCC and define $def..."
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out -D${def}
done
rm test.out
rm main.c

Expand Down
4 changes: 2 additions & 2 deletions miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ void mz_free(void *p)
MZ_FREE(p);
}

#ifndef MINIZ_NO_ZLIB_APIS

void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
{
(void)opaque, (void)items, (void)size;
Expand All @@ -180,6 +178,8 @@ const char *mz_version(void)
return MZ_VERSION;
}

#ifndef MINIZ_NO_ZLIB_APIS

int mz_deflateInit(mz_streamp pStream, int level)
{
return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
Expand Down
45 changes: 23 additions & 22 deletions miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
/*#define MINIZ_NO_ARCHIVE_APIS */

/* Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's. */
/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */
/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */

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

#include <stddef.h>

#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
#include <time.h>
#endif
Expand Down Expand Up @@ -207,22 +209,32 @@ enum
/* Method */
#define MZ_DEFLATED 8

#ifndef MINIZ_NO_ZLIB_APIS

/* Heap allocation callbacks.
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
typedef void (*mz_free_func)(void *opaque, void *address);
typedef void(*mz_free_func)(void *opaque, void *address);
typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);

/* TODO: I can't encode "1.16" here, argh */
#define MZ_VERSION "9.1.15"
#define MZ_VERNUM 0x91F0
#define MZ_VER_MAJOR 9
#define MZ_VER_MINOR 1
#define MZ_VER_REVISION 15
/* 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. */
enum
{
MZ_NO_COMPRESSION = 0,
MZ_BEST_SPEED = 1,
MZ_BEST_COMPRESSION = 9,
MZ_UBER_COMPRESSION = 10,
MZ_DEFAULT_LEVEL = 6,
MZ_DEFAULT_COMPRESSION = -1
};

#define MZ_VERSION "10.0.0"
#define MZ_VERNUM 0xA000
#define MZ_VER_MAJOR 10
#define MZ_VER_MINOR 0
#define MZ_VER_REVISION 0
#define MZ_VER_SUBREVISION 0

#ifndef MINIZ_NO_ZLIB_APIS

/* 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). */
enum
{
Expand All @@ -249,17 +261,6 @@ enum
MZ_PARAM_ERROR = -10000
};

/* 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. */
enum
{
MZ_NO_COMPRESSION = 0,
MZ_BEST_SPEED = 1,
MZ_BEST_COMPRESSION = 9,
MZ_UBER_COMPRESSION = 10,
MZ_DEFAULT_LEVEL = 6,
MZ_DEFAULT_COMPRESSION = -1
};

/* Window bits */
#define MZ_DEFAULT_WINDOW_BITS 15

Expand Down
2 changes: 0 additions & 2 deletions miniz_tdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,6 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void
return out_buf.m_size;
}

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

/* 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). */
Expand All @@ -1431,7 +1430,6 @@ mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int

return comp_flags;
}
#endif /*MINIZ_NO_ZLIB_APIS */

#ifdef _MSC_VER
#pragma warning(push)
Expand Down
3 changes: 0 additions & 3 deletions miniz_tdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,11 @@ tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, siz
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
mz_uint32 tdefl_get_adler32(tdefl_compressor *d);

/* 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. */
#ifndef MINIZ_NO_ZLIB_APIS
/* Create tdefl_compress() flags given zlib-style compression parameters. */
/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
/* window_bits may be -15 (raw deflate) or 15 (zlib) */
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
#endif /* #ifndef MINIZ_NO_ZLIB_APIS */

/* Allocate the tdefl_compressor structure in C so that */
/* non-C language bindings to tdefl_ API don't need to worry about */
Expand Down
23 changes: 16 additions & 7 deletions miniz_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
**************************************************************************/
#include "miniz_zip.h"

#ifndef MINIZ_NO_ARCHIVE_APIS

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -368,6 +370,7 @@ static MZ_TIME_T mz_zip_dos_to_time_t(int dos_time, int dos_date)
return mktime(&tm);
}

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

#ifndef MINIZ_NO_STDIO
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *pTime)
{
struct MZ_FILE_STAT_STRUCT file_stat;
Expand All @@ -401,6 +406,7 @@ static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *p

return MZ_TRUE;
}
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS*/

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

#ifndef MINIZ_NO_TIME
if (last_modified != NULL)
{
mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date);
}
else
{
#ifndef MINIZ_NO_TIME
{
MZ_TIME_T cur_time;
time(&cur_time);
mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
}
#endif /* #ifndef MINIZ_NO_TIME */
MZ_TIME_T cur_time;
time(&cur_time);
mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
}
#endif /* #ifndef MINIZ_NO_TIME */

archive_name_size = strlen(pArchive_name);
if (archive_name_size > MZ_UINT16_MAX)
Expand Down Expand Up @@ -4339,12 +4343,17 @@ mz_bool mz_zip_end(mz_zip_archive *pZip)

if (pZip->m_zip_mode == MZ_ZIP_MODE_READING)
return mz_zip_reader_end(pZip);
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
else if ((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))
return mz_zip_writer_end(pZip);
#endif

return MZ_FALSE;
}

#ifdef __cplusplus
}
#endif

#endif /*#ifndef MINIZ_NO_ARCHIVE_APIS*/

0 comments on commit 1c6ca86

Please sign in to comment.