mirror of
https://github.com/eledio-devices/thirdparty-miniz.git
synced 2025-11-01 00:38:28 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48605fb1bd | ||
|
|
731d5b2f87 | ||
|
|
e842d2de5e | ||
|
|
f28a343dfa | ||
|
|
7bc1530e7a | ||
|
|
2a8a458b93 | ||
|
|
aba9ad1a5a | ||
|
|
fc8a9e1d8b |
180
miniz.c
180
miniz.c
@@ -1,18 +1,19 @@
|
|||||||
/* miniz.c v1.13 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
/* miniz.c v1.14 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
||||||
See "unlicense" statement at the end of this file.
|
See "unlicense" statement at the end of this file.
|
||||||
Rich Geldreich <richgel99@gmail.com>, last updated May 19, 2012
|
Rich Geldreich <richgel99@gmail.com>, last updated May 20, 2012
|
||||||
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
||||||
|
|
||||||
Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
|
Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
|
||||||
MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
|
MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
|
||||||
|
|
||||||
* Change History
|
* Change History
|
||||||
|
5/20/12 v1.14 - MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include <time.h> (thanks fermtect).
|
||||||
5/19/12 v1.13 - From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit.
|
5/19/12 v1.13 - From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit.
|
||||||
Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files.
|
Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files.
|
||||||
Eliminated a bunch of warnings when compiling with GCC 32-bit/64.
|
Eliminated a bunch of warnings when compiling with GCC 32-bit/64.
|
||||||
Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly
|
Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly
|
||||||
"Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning).
|
"Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning).
|
||||||
Created 32-bit and 64-bit Codeblocks projects/workspace.
|
Created 32-bit and 64-bit Codeblocks projects/workspace. Built and tested Linux executables. The codeblocks workspace is compatible with Linux+Win32/x64.
|
||||||
Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test.
|
Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test.
|
||||||
Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives.
|
Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives.
|
||||||
Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.)
|
Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.)
|
||||||
@@ -135,6 +136,10 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Defines to completely disable specific portions of miniz.c:
|
// Defines to completely disable specific portions of miniz.c:
|
||||||
// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
|
// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
|
||||||
|
|
||||||
@@ -192,11 +197,8 @@ extern "C" {
|
|||||||
// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
|
// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
|
||||||
typedef unsigned long mz_ulong;
|
typedef unsigned long mz_ulong;
|
||||||
|
|
||||||
// Heap allocation callbacks.
|
// mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
|
||||||
// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
|
void mz_free(void *p);
|
||||||
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_realloc_func)(void *opaque, void *address, size_t items, size_t size);
|
|
||||||
|
|
||||||
#define MZ_ADLER32_INIT (1)
|
#define MZ_ADLER32_INIT (1)
|
||||||
// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
|
// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
|
||||||
@@ -214,11 +216,17 @@ enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3
|
|||||||
|
|
||||||
#ifndef MINIZ_NO_ZLIB_APIS
|
#ifndef MINIZ_NO_ZLIB_APIS
|
||||||
|
|
||||||
#define MZ_VERSION "9.1.13"
|
// Heap allocation callbacks.
|
||||||
#define MZ_VERNUM 0x91D0
|
// 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_realloc_func)(void *opaque, void *address, size_t items, size_t size);
|
||||||
|
|
||||||
|
#define MZ_VERSION "9.1.14"
|
||||||
|
#define MZ_VERNUM 0x91E0
|
||||||
#define MZ_VER_MAJOR 9
|
#define MZ_VER_MAJOR 9
|
||||||
#define MZ_VER_MINOR 1
|
#define MZ_VER_MINOR 1
|
||||||
#define MZ_VER_REVISION 13
|
#define MZ_VER_REVISION 14
|
||||||
#define MZ_VER_SUBREVISION 0
|
#define MZ_VER_SUBREVISION 0
|
||||||
|
|
||||||
// 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).
|
// 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).
|
||||||
@@ -661,7 +669,7 @@ enum
|
|||||||
// On return:
|
// On return:
|
||||||
// Function returns a pointer to the decompressed data, or NULL on failure.
|
// Function returns a pointer to the decompressed data, or NULL on failure.
|
||||||
// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
|
// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
|
||||||
// The caller must free() the returned block when it's no longer needed.
|
// The caller must call mz_free() on the returned block when it's no longer needed.
|
||||||
void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
||||||
|
|
||||||
// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
|
// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
|
||||||
@@ -781,11 +789,12 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void
|
|||||||
|
|
||||||
// Compresses an image to a compressed PNG file in memory.
|
// Compresses an image to a compressed PNG file in memory.
|
||||||
// On entry:
|
// On entry:
|
||||||
// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
|
// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
|
||||||
|
// The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
|
||||||
// On return:
|
// On return:
|
||||||
// Function returns a pointer to the compressed data, or NULL on failure.
|
// Function returns a pointer to the compressed data, or NULL on failure.
|
||||||
// *pLen_out will be set to the size of the PNG image file.
|
// *pLen_out will be set to the size of the PNG image file.
|
||||||
// The caller must free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
|
// The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
|
||||||
void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
|
void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
|
||||||
|
|
||||||
// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
|
// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
|
||||||
@@ -916,12 +925,12 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1];
|
|||||||
#define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
|
#define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !defined(__forceinline)
|
#ifdef _MSC_VER
|
||||||
#ifdef __cplusplus
|
#define MZ_FORCEINLINE __forceinline
|
||||||
#define __forceinline inline
|
#elif defined(__GNUC__)
|
||||||
#else
|
#define MZ_FORCEINLINE __attribute__((__always_inline__))
|
||||||
#define __forceinline
|
#else
|
||||||
#endif
|
#define MZ_FORCEINLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -956,6 +965,11 @@ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
|||||||
return ~crcu32;
|
return ~crcu32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mz_free(void *p)
|
||||||
|
{
|
||||||
|
MZ_FREE(p);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MINIZ_NO_ZLIB_APIS
|
#ifndef MINIZ_NO_ZLIB_APIS
|
||||||
|
|
||||||
static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque, (void)items, (void)size; return MZ_MALLOC(items * size); }
|
static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque, (void)items, (void)size; return MZ_MALLOC(items * size); }
|
||||||
@@ -2213,8 +2227,7 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush)
|
|||||||
|
|
||||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
|
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
|
||||||
#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
|
#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
|
||||||
static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
|
static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
|
||||||
|
|
||||||
{
|
{
|
||||||
mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
|
mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
|
||||||
mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
|
mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
|
||||||
@@ -2248,7 +2261,7 @@ static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
|
static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
|
||||||
{
|
{
|
||||||
mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
|
mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
|
||||||
mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
|
mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
|
||||||
@@ -2416,7 +2429,7 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
|||||||
}
|
}
|
||||||
#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
||||||
|
|
||||||
static __forceinline void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit)
|
static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit)
|
||||||
{
|
{
|
||||||
d->m_total_lz_bytes++;
|
d->m_total_lz_bytes++;
|
||||||
*d->m_pLZ_code_buf++ = lit;
|
*d->m_pLZ_code_buf++ = lit;
|
||||||
@@ -2424,7 +2437,7 @@ static __forceinline void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit
|
|||||||
d->m_huff_count[0][lit]++;
|
d->m_huff_count[0][lit]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
|
static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
|
||||||
{
|
{
|
||||||
mz_uint32 s0, s1;
|
mz_uint32 s0, s1;
|
||||||
|
|
||||||
@@ -2785,19 +2798,43 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h,
|
|||||||
|
|
||||||
#ifndef MINIZ_NO_ARCHIVE_APIS
|
#ifndef MINIZ_NO_ARCHIVE_APIS
|
||||||
|
|
||||||
#ifndef MINIZ_NO_TIME
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MINIZ_NO_STDIO
|
#ifdef MINIZ_NO_STDIO
|
||||||
#define MZ_FILE void *
|
#define MZ_FILE void *
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
|
|
||||||
#include <sys/utime.h>
|
#if defined(_MSC_VER)
|
||||||
|
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
||||||
|
{
|
||||||
|
FILE* pFile = NULL;
|
||||||
|
fopen_s(&pFile, pFilename, pMode);
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
|
{
|
||||||
|
FILE* pFile = NULL;
|
||||||
|
if (freopen_s(&pFile, pPath, pMode, pStream))
|
||||||
|
return NULL;
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
||||||
|
{
|
||||||
|
return fopen(pFilename, pMode);
|
||||||
|
}
|
||||||
|
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
|
{
|
||||||
|
return freopen(pPath, pMode, pStream);
|
||||||
|
}
|
||||||
|
#endif // #if defined(_MSC_VER)
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW64__)
|
||||||
|
#ifndef MINIZ_NO_TIME
|
||||||
|
#include <sys/utime.h>
|
||||||
|
#endif
|
||||||
#define MZ_FILE FILE
|
#define MZ_FILE FILE
|
||||||
#define MZ_FOPEN fopen
|
#define MZ_FOPEN mz_fopen
|
||||||
#define MZ_FCLOSE fclose
|
#define MZ_FCLOSE fclose
|
||||||
#define MZ_FREAD fread
|
#define MZ_FREAD fread
|
||||||
#define MZ_FWRITE fwrite
|
#define MZ_FWRITE fwrite
|
||||||
@@ -2806,12 +2843,46 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h,
|
|||||||
#define MZ_FILE_STAT_STRUCT _stat
|
#define MZ_FILE_STAT_STRUCT _stat
|
||||||
#define MZ_FILE_STAT _stat
|
#define MZ_FILE_STAT _stat
|
||||||
#define MZ_FFLUSH fflush
|
#define MZ_FFLUSH fflush
|
||||||
#define MZ_FREOPEN freopen
|
#define MZ_FREOPEN mz_freopen
|
||||||
|
#define MZ_DELETE_FILE remove
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
#ifndef MINIZ_NO_TIME
|
||||||
|
#include <sys/utime.h>
|
||||||
|
#endif
|
||||||
|
#define MZ_FILE FILE
|
||||||
|
#define MZ_FOPEN mz_fopen
|
||||||
|
#define MZ_FCLOSE fclose
|
||||||
|
#define MZ_FREAD fread
|
||||||
|
#define MZ_FWRITE fwrite
|
||||||
|
#define MZ_FTELL64 ftello64
|
||||||
|
#define MZ_FSEEK64 fseeko64
|
||||||
|
#define MZ_FILE_STAT_STRUCT _stat
|
||||||
|
#define MZ_FILE_STAT _stat
|
||||||
|
#define MZ_FFLUSH fflush
|
||||||
|
#define MZ_FREOPEN mz_freopen
|
||||||
|
#define MZ_DELETE_FILE remove
|
||||||
|
#elif defined(__TINYC__)
|
||||||
|
#ifndef MINIZ_NO_TIME
|
||||||
|
#include <sys\utime.h>
|
||||||
|
#endif
|
||||||
|
#define MZ_FILE FILE
|
||||||
|
#define MZ_FOPEN mz_fopen
|
||||||
|
#define MZ_FCLOSE fclose
|
||||||
|
#define MZ_FREAD fread
|
||||||
|
#define MZ_FWRITE fwrite
|
||||||
|
#define MZ_FTELL64 ftell
|
||||||
|
#define MZ_FSEEK64 fseek
|
||||||
|
#define MZ_FILE_STAT_STRUCT stat
|
||||||
|
#define MZ_FILE_STAT stat
|
||||||
|
#define MZ_FFLUSH fflush
|
||||||
|
#define MZ_FREOPEN mz_freopen
|
||||||
#define MZ_DELETE_FILE remove
|
#define MZ_DELETE_FILE remove
|
||||||
#else
|
#else
|
||||||
#include <utime.h>
|
#ifndef MINIZ_NO_TIME
|
||||||
|
#include <utime.h>
|
||||||
|
#endif
|
||||||
#define MZ_FILE FILE
|
#define MZ_FILE FILE
|
||||||
#define MZ_FOPEN fopen
|
#define MZ_FOPEN mz_fopen
|
||||||
#define MZ_FCLOSE fclose
|
#define MZ_FCLOSE fclose
|
||||||
#define MZ_FREAD fread
|
#define MZ_FREAD fread
|
||||||
#define MZ_FWRITE fwrite
|
#define MZ_FWRITE fwrite
|
||||||
@@ -2820,7 +2891,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h,
|
|||||||
#define MZ_FILE_STAT_STRUCT stat
|
#define MZ_FILE_STAT_STRUCT stat
|
||||||
#define MZ_FILE_STAT stat
|
#define MZ_FILE_STAT stat
|
||||||
#define MZ_FFLUSH fflush
|
#define MZ_FFLUSH fflush
|
||||||
#define MZ_FREOPEN freopen
|
#define MZ_FREOPEN mz_freopen
|
||||||
#define MZ_DELETE_FILE remove
|
#define MZ_DELETE_FILE remove
|
||||||
#endif // #ifdef _MSC_VER
|
#endif // #ifdef _MSC_VER
|
||||||
#endif // #ifdef MINIZ_NO_STDIO
|
#endif // #ifdef MINIZ_NO_STDIO
|
||||||
@@ -2868,7 +2939,7 @@ struct mz_zip_internal_state_tag
|
|||||||
#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
|
#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
|
||||||
#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
|
#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
|
||||||
|
|
||||||
static __forceinline void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray)
|
static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray)
|
||||||
{
|
{
|
||||||
pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p);
|
pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p);
|
||||||
memset(pArray, 0, sizeof(mz_zip_array));
|
memset(pArray, 0, sizeof(mz_zip_array));
|
||||||
@@ -2883,25 +2954,25 @@ static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array *
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing)
|
static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing)
|
||||||
{
|
{
|
||||||
if (new_capacity > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) return MZ_FALSE; }
|
if (new_capacity > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) return MZ_FALSE; }
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing)
|
static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing)
|
||||||
{
|
{
|
||||||
if (new_size > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) return MZ_FALSE; }
|
if (new_size > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) return MZ_FALSE; }
|
||||||
pArray->m_size = new_size;
|
pArray->m_size = new_size;
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n)
|
static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n)
|
||||||
{
|
{
|
||||||
return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE);
|
return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n)
|
static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n)
|
||||||
{
|
{
|
||||||
size_t orig_size = pArray->m_size; if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) return MZ_FALSE;
|
size_t orig_size = pArray->m_size; if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) return MZ_FALSE;
|
||||||
memcpy((mz_uint8*)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
|
memcpy((mz_uint8*)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
|
||||||
@@ -2920,7 +2991,18 @@ static time_t mz_zip_dos_to_time_t(int dos_time, int dos_date)
|
|||||||
|
|
||||||
static void mz_zip_time_to_dos_time(time_t time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
|
static void mz_zip_time_to_dos_time(time_t time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
|
||||||
{
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
struct tm tm_struct;
|
||||||
|
struct tm *tm = &tm_struct;
|
||||||
|
errno_t err = localtime_s(tm, &time);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
*pDOS_date = 0; *pDOS_time = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
struct tm *tm = localtime(&time);
|
struct tm *tm = localtime(&time);
|
||||||
|
#endif
|
||||||
*pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
|
*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);
|
*pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
|
||||||
}
|
}
|
||||||
@@ -2944,7 +3026,7 @@ static mz_bool mz_zip_set_file_times(const char *pFilename, time_t access_time,
|
|||||||
struct utimbuf t; t.actime = access_time; t.modtime = modified_time;
|
struct utimbuf t; t.actime = access_time; t.modtime = modified_time;
|
||||||
return !utime(pFilename, &t);
|
return !utime(pFilename, &t);
|
||||||
#else
|
#else
|
||||||
pFilename, access_time, modified_time;
|
(void)pFilename, (void)access_time, (void)modified_time;
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
#endif // #ifndef MINIZ_NO_TIME
|
#endif // #ifndef MINIZ_NO_TIME
|
||||||
}
|
}
|
||||||
@@ -2974,7 +3056,7 @@ static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint32 flags
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index)
|
static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index)
|
||||||
{
|
{
|
||||||
const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
|
const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
|
||||||
const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index));
|
const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index));
|
||||||
@@ -3208,7 +3290,7 @@ mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip)
|
|||||||
return pZip ? pZip->m_total_files : 0;
|
return pZip ? pZip->m_total_files : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
|
static MZ_FORCEINLINE const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
|
||||||
{
|
{
|
||||||
if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
|
if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -3297,7 +3379,7 @@ mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, cha
|
|||||||
return n + 1;
|
return n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags)
|
static MZ_FORCEINLINE mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags)
|
||||||
{
|
{
|
||||||
mz_uint i;
|
mz_uint i;
|
||||||
if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
|
if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
|
||||||
@@ -3308,7 +3390,7 @@ static __forceinline mz_bool mz_zip_reader_string_equal(const char *pA, const ch
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len)
|
static MZ_FORCEINLINE int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len)
|
||||||
{
|
{
|
||||||
const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
|
const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
|
||||||
mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS);
|
mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS);
|
||||||
@@ -4676,8 +4758,10 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const
|
|||||||
}
|
}
|
||||||
status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
|
status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
|
||||||
// Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.)
|
// Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.)
|
||||||
status = status && mz_zip_writer_finalize_archive(&zip_archive);
|
if (!mz_zip_writer_finalize_archive(&zip_archive))
|
||||||
status = status && mz_zip_writer_end(&zip_archive);
|
status = MZ_FALSE;
|
||||||
|
if (!mz_zip_writer_end(&zip_archive))
|
||||||
|
status = MZ_FALSE;
|
||||||
if ((!status) && (created_new_archive))
|
if ((!status) && (created_new_archive))
|
||||||
{
|
{
|
||||||
// It's a new archive and something went wrong, so just delete it.
|
// It's a new archive and something went wrong, so just delete it.
|
||||||
|
|||||||
Reference in New Issue
Block a user