160 #ifndef MINIZ_HEADER_INCLUDED
161 #define MINIZ_HEADER_INCLUDED
194 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
196 #define MINIZ_NO_TIME
199 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
203 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
205 #define MINIZ_X86_OR_X64_CPU 1
208 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
210 #define MINIZ_LITTLE_ENDIAN 1
213 #if MINIZ_X86_OR_X64_CPU
215 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
218 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
220 #define MINIZ_HAS_64BIT_REGISTERS 1
224 #define ftello64 ftello
225 #define fseeko64 fseeko
226 #define fopen64 fopen
227 #define freopen64 freopen
242 #define MZ_ADLER32_INIT (1)
246 #define MZ_CRC32_INIT (0)
254 #define MZ_DEFLATED 8
256 #ifndef MINIZ_NO_ZLIB_APIS
260 typedef void *(*mz_alloc_func)(
void *opaque,
size_t items,
size_t size);
262 typedef void *(*mz_realloc_func)(
void *opaque,
void *address,
size_t items,
size_t size);
264 #define MZ_VERSION "9.1.15"
265 #define MZ_VERNUM 0x91F0
266 #define MZ_VER_MAJOR 9
267 #define MZ_VER_MINOR 1
268 #define MZ_VER_REVISION 15
269 #define MZ_VER_SUBREVISION 0
281 #define MZ_DEFAULT_WINDOW_BITS 15
283 struct mz_internal_state;
400 #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
413 #define Z_NO_FLUSH MZ_NO_FLUSH
414 #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
415 #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
416 #define Z_FULL_FLUSH MZ_FULL_FLUSH
417 #define Z_FINISH MZ_FINISH
418 #define Z_BLOCK MZ_BLOCK
420 #define Z_STREAM_END MZ_STREAM_END
421 #define Z_NEED_DICT MZ_NEED_DICT
422 #define Z_ERRNO MZ_ERRNO
423 #define Z_STREAM_ERROR MZ_STREAM_ERROR
424 #define Z_DATA_ERROR MZ_DATA_ERROR
425 #define Z_MEM_ERROR MZ_MEM_ERROR
426 #define Z_BUF_ERROR MZ_BUF_ERROR
427 #define Z_VERSION_ERROR MZ_VERSION_ERROR
428 #define Z_PARAM_ERROR MZ_PARAM_ERROR
429 #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
430 #define Z_BEST_SPEED MZ_BEST_SPEED
431 #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
432 #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
433 #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
434 #define Z_FILTERED MZ_FILTERED
435 #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
437 #define Z_FIXED MZ_FIXED
438 #define Z_DEFLATED MZ_DEFLATED
439 #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
440 #define alloc_func mz_alloc_func
441 #define free_func mz_free_func
442 #define internal_state mz_internal_state
443 #define z_stream mz_stream
444 #define deflateInit mz_deflateInit
445 #define deflateInit2 mz_deflateInit2
446 #define deflateReset mz_deflateReset
447 #define deflate mz_deflate
448 #define deflateEnd mz_deflateEnd
449 #define deflateBound mz_deflateBound
450 #define compress mz_compress
451 #define compress2 mz_compress2
452 #define compressBound mz_compressBound
453 #define inflateInit mz_inflateInit
454 #define inflateInit2 mz_inflateInit2
455 #define inflate mz_inflate
456 #define inflateEnd mz_inflateEnd
457 #define uncompress mz_uncompress
458 #define crc32 mz_crc32
459 #define adler32 mz_adler32
461 #define MAX_MEM_LEVEL 9
462 #define zError mz_error
463 #define ZLIB_VERSION MZ_VERSION
464 #define ZLIB_VERNUM MZ_VERNUM
465 #define ZLIB_VER_MAJOR MZ_VER_MAJOR
466 #define ZLIB_VER_MINOR MZ_VER_MINOR
467 #define ZLIB_VER_REVISION MZ_VER_REVISION
468 #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
469 #define zlibVersion mz_version
470 #define zlib_version mz_version()
471 #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
473 #endif // MINIZ_NO_ZLIB_APIS
491 #define MZ_MACRO_END while (0, 0)
493 #define MZ_MACRO_END while (0)
498 #ifndef MINIZ_NO_ARCHIVE_APIS
515 #ifndef MINIZ_NO_TIME
580 #ifndef MINIZ_NO_STDIO
619 #ifndef MINIZ_NO_STDIO
631 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
637 #ifndef MINIZ_NO_STDIO
655 #ifndef MINIZ_NO_STDIO
685 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
687 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
716 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
727 #define TINFL_LZ_DICT_SIZE 32768
741 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
742 #define tinfl_get_adler32(r) (r)->m_check_adler32
761 #if MINIZ_HAS_64BIT_REGISTERS
762 #define TINFL_USE_64BIT_BITBUF 1
765 #if TINFL_USE_64BIT_BITBUF
767 #define TINFL_BITBUF_SIZE (64)
770 #define TINFL_BITBUF_SIZE (32)
775 mz_uint32 m_state,
m_num_bits,
m_zhdr0,
m_zhdr1,
m_z_adler32,
m_final,
m_type,
m_check_adler32,
m_dist,
m_counter,
m_num_extra,
m_table_sizes[
TINFL_MAX_HUFF_TABLES];
785 #define TDEFL_LESS_MEMORY 0
828 size_t tdefl_compress_mem_to_mem(
void *pOut_buf,
size_t out_buf_len,
const void *pSrc_buf,
size_t src_buf_len,
int flags);
852 #if TDEFL_LESS_MEMORY
886 mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index,
m_wants_to_finish;
922 #ifndef MINIZ_NO_ZLIB_APIS
928 #endif // #ifndef MINIZ_NO_ZLIB_APIS
934 #endif // MINIZ_HEADER_INCLUDED
938 #ifndef MINIZ_HEADER_FILE_ONLY
947 #define MZ_ASSERT(x) assert(x)
949 #ifdef MINIZ_NO_MALLOC
950 #define MZ_MALLOC(x) NULL
951 #define MZ_FREE(x) (void)x, ((void)0)
952 #define MZ_REALLOC(p, x) NULL
954 #define MZ_MALLOC(x) malloc(x)
955 #define MZ_FREE(x) free(x)
956 #define MZ_REALLOC(p, x) realloc(p, x)
959 #define MZ_MAX(a,b) (((a)>(b))?(a):(b))
960 #define MZ_MIN(a,b) (((a)<(b))?(a):(b))
961 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
963 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
964 #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
965 #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
967 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
968 #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))
972 #define MZ_FORCEINLINE __forceinline
973 #elif defined(__GNUC__)
974 #define MZ_FORCEINLINE inline __attribute__((__always_inline__))
976 #define MZ_FORCEINLINE inline
990 for (i = 0; i + 7 < block_len; i += 8, ptr += 8) {
991 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
992 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
994 for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
995 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
997 return (s2 << 16) + s1;
1003 static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
1004 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
1007 crcu32 = ~crcu32;
while (buf_len--) {
mz_uint8 b = *ptr++; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; }
1016 #ifndef MINIZ_NO_ZLIB_APIS
1018 static void *
def_alloc_func(
void *opaque,
size_t items,
size_t size) { (void)opaque, (
void)items, (void)size;
return MZ_MALLOC(items * size); }
1020 static void *
def_realloc_func(
void *opaque,
void *address,
size_t items,
size_t size) { (void)opaque, (
void)address, (void)items, (
void)size;
return MZ_REALLOC(address, items * size); }
1053 pStream->
state = (
struct mz_internal_state *)pComp;
1074 size_t in_bytes, out_bytes;
1075 mz_ulong orig_total_in, orig_total_out;
1076 int mz_status =
MZ_OK;
1099 if (defl_status < 0)
1113 if ((flush) || (pStream->
total_in != orig_total_in) || (pStream->
total_out != orig_total_out))
1136 return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
1143 memset(&stream, 0,
sizeof(stream));
1146 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
return MZ_PARAM_ERROR;
1154 if (status !=
MZ_OK)
return status;
1203 pStream->
state = (
struct mz_internal_state *)pDecomp;
1225 size_t in_bytes, out_bytes, orig_avail_in;
1242 if ((flush ==
MZ_FINISH) && (first_call))
1328 memset(&stream, 0,
sizeof(stream));
1331 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
return MZ_PARAM_ERROR;
1339 if (status !=
MZ_OK)
1355 static struct {
int m_err;
const char *m_pDesc; } s_error_descs[] =
1357 {
MZ_OK,
"" }, {
MZ_STREAM_END,
"stream end" }, {
MZ_NEED_DICT,
"need dictionary" }, {
MZ_ERRNO,
"file error" }, {
MZ_STREAM_ERROR,
"stream error" },
1360 mz_uint i;
for (i = 0; i <
sizeof(s_error_descs) /
sizeof(s_error_descs[0]); ++i)
if (s_error_descs[i].m_err == err)
return s_error_descs[i].m_pDesc;
1364 #endif //MINIZ_NO_ZLIB_APIS
1368 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
1369 #define TINFL_MEMSET(p, c, l) memset(p, c, l)
1371 #define TINFL_CR_BEGIN switch(r->m_state) { case 0:
1372 #define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
1373 #define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
1374 #define TINFL_CR_FINISH }
1378 #define TINFL_GET_BYTE(state_index, c) do { \
1379 if (pIn_buf_cur >= pIn_buf_end) { \
1381 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
1382 TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
1383 if (pIn_buf_cur < pIn_buf_end) { \
1384 c = *pIn_buf_cur++; \
1392 } else c = *pIn_buf_cur++; } MZ_MACRO_END
1394 #define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n))
1395 #define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
1396 #define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
1402 #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
1404 temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
1406 code_len = temp >> 9; \
1407 if ((code_len) && (num_bits >= code_len)) \
1409 } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
1410 code_len = TINFL_FAST_LOOKUP_BITS; \
1412 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
1413 } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
1414 } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
1415 } while (num_bits < 15);
1421 #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
1422 int temp; mz_uint code_len, c; \
1423 if (num_bits < 15) { \
1424 if ((pIn_buf_end - pIn_buf_cur) < 2) { \
1425 TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
1427 bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
1430 if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
1431 code_len = temp >> 9, temp &= 511; \
1433 code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
1434 } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
1438 static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
1439 static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
1440 static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
1441 static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
1442 static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
1443 static const int s_min_table_sizes[3] = { 257, 1, 4 };
1446 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *
const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1447 mz_uint8 *pOut_buf_cur = pOut_buf_next, *
const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1451 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0;
return TINFL_STATUS_BAD_PARAM; }
1473 while ((counter) && (num_bits))
1483 while (pIn_buf_cur >= pIn_buf_end)
1494 n =
MZ_MIN(
MZ_MIN((
size_t)(pOut_buf_end - pOut_buf_cur), (
size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1495 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (
mz_uint)n;
1508 for ( i = 0; i <= 143; ++i) {
1511 for ( ; i <= 255; ++i) {
1514 for ( ; i <= 279; ++i) {
1517 for ( ; i <= 287; ++i) {
1532 used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1533 for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1534 if ((65536 != total) && (used_syms > 1))
1540 mz_uint rev_code = 0, l, cur_code, code_size = pTable->
m_code_size[sym_index];
if (!code_size)
continue;
1541 cur_code = next_code[code_size]++;
for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1547 tree_cur -= ((rev_code >>= 1) & 1);
1548 if (!pTable->
m_tree[-tree_cur - 1]) { pTable->
m_tree[-tree_cur - 1] = (
mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
else tree_cur = pTable->
m_tree[-tree_cur - 1];
1550 tree_cur -= ((rev_code >>= 1) & 1); pTable->
m_tree[-tree_cur - 1] = (
mz_int16)sym_index;
1557 if ((dist == 16) && (!counter))
1561 num_extra =
"\02\03\07"[dist - 16];
TINFL_GET_BITS(18, s, num_extra); s +=
"\03\03\013"[dist - 16];
1576 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
1582 *pOut_buf_cur++ = (
mz_uint8)counter;
1587 #if TINFL_USE_64BIT_BITBUF
1593 code_len = sym2 >> 9;
1598 counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
1602 #if !TINFL_USE_64BIT_BITBUF
1606 code_len = sym2 >> 9;
1611 bit_buf >>= code_len; num_bits -= code_len;
1613 pOut_buf_cur[0] = (
mz_uint8)counter;
1624 if ((counter &= 511) == 256)
break;
1626 num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
1627 if (num_extra) {
mz_uint extra_bits;
TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
1630 num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
1631 if (num_extra) {
mz_uint extra_bits;
TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
1633 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
1639 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
1641 if ((
MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
1646 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
1650 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1651 else if ((counter >= 9) && (counter <= dist))
1653 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
1659 }
while ((pSrc += 8) < pSrc_end);
1660 if ((counter &= 7) < 3)
1664 pOut_buf_cur[0] = pSrc[0];
1666 pOut_buf_cur[1] = pSrc[1];
1667 pOut_buf_cur += counter;
1675 pOut_buf_cur[0] = pSrc[0];
1676 pOut_buf_cur[1] = pSrc[1];
1677 pOut_buf_cur[2] = pSrc[2];
1678 pOut_buf_cur += 3; pSrc += 3;
1679 }
while ((
int)(counter -= 3) > 2);
1680 if ((
int)counter > 0)
1682 pOut_buf_cur[0] = pSrc[0];
1683 if ((
int)counter > 1)
1684 pOut_buf_cur[1] = pSrc[1];
1685 pOut_buf_cur += counter;
1699 *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
1702 const mz_uint8 *ptr = pOut_buf_next;
size_t buf_len = *pOut_buf_size;
1706 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
1708 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
1709 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
1711 for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
1712 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
1727 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
1734 src_buf_ofs += src_buf_size;
1735 *pOut_len += dst_buf_size;
1737 new_out_buf_capacity = out_buf_capacity * 2;
if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
1738 pNew_buf =
MZ_REALLOC(pBuf, new_out_buf_capacity);
1743 pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
1765 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size =
TINFL_LZ_DICT_SIZE - dict_ofs;
1768 in_buf_ofs += in_buf_size;
1769 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (
int)dst_buf_size, pPut_buf_user)))
1779 *pIn_buf_size = in_buf_ofs;
1787 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
1788 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
1789 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
1790 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
1791 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
1792 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
1793 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
1794 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
1797 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
1798 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1799 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1800 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
1803 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
1804 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
1805 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
1806 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
1807 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
1808 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
1809 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1810 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1811 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1812 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1813 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1814 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
1817 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
1818 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1819 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1820 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1821 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1822 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1823 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1827 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
1828 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
1829 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
1832 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
1833 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
1834 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
1841 for (i = 0; i < num_syms; i++) {
mz_uint freq = pSyms0[i].
m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
1842 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
1843 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
1845 const mz_uint32* pHist = &hist[pass << 8];
1846 mz_uint offsets[256], cur_ofs = 0;
1847 for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
1848 for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
1849 {
tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
1857 int root, leaf, next, avbl, used, dpth;
1858 if (n==0)
return;
else if (n==1) { A[0].
m_key = 1;
return; }
1859 A[0].
m_key += A[1].
m_key; root = 0; leaf = 2;
1860 for (next=1; next < n-1; next++)
1863 if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].
m_key = (
mz_uint16)(A[next].m_key + A[root].m_key); A[root++].
m_key = (
mz_uint16)next; }
else A[next].
m_key = (
mz_uint16)(A[next].m_key + A[leaf++].m_key);
1865 A[n-2].
m_key = 0;
for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
1866 avbl = 1; used = dpth = 0; root = n-2; next = n-1;
1869 while (root>=0 && (
int)A[root].
m_key==dpth) { used++; root--; }
1870 while (avbl>used) { A[next--].
m_key = (
mz_uint16)(dpth); avbl--; }
1871 avbl = 2*used; dpth++; used = 0;
1879 int i;
mz_uint32 total = 0;
if (code_list_len <= 1)
return;
1881 for (i = max_code_size; i > 0; i--) total += (((
mz_uint32)pNum_codes[i]) << (max_code_size - i));
1882 while (total != (1UL << max_code_size))
1884 pNum_codes[max_code_size]--;
1885 for (i = max_code_size - 1; i > 0; i--)
if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2;
break; }
1895 for (i = 0; i < table_len; i++) num_codes[d->
m_huff_code_sizes[table_num][i]]++;
1900 int num_used_syms = 0;
1906 for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
1911 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
1915 next_code[1] = 0;
for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
1917 for (i = 0; i < table_len; i++)
1920 code = next_code[code_size]++;
for (l = code_size; l > 0; l--,
code >>= 1) rev_code = (rev_code << 1) | (
code & 1);
1925 #define TDEFL_PUT_BITS(b, l) do { \
1926 mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
1927 d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
1928 while (d->m_bits_in >= 8) { \
1929 if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
1930 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
1931 d->m_bit_buffer >>= 8; \
1932 d->m_bits_in -= 8; \
1936 #define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
1937 if (rle_repeat_count < 3) { \
1938 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
1939 while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
1941 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
1942 } rle_repeat_count = 0; } }
1944 #define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
1945 if (rle_z_count < 3) { \
1946 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
1947 } else if (rle_z_count <= 10) { \
1948 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
1950 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
1951 } rle_z_count = 0; } }
1953 static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
1957 int num_lit_codes, num_dist_codes, num_bit_lengths;
mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
1965 for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--)
if (d->
m_huff_code_sizes[0][num_lit_codes - 1])
break;
1966 for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--)
if (d->
m_huff_code_sizes[1][num_dist_codes - 1])
break;
1970 total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0;
1973 for (i = 0; i < total_code_sizes_to_pack; i++)
1975 mz_uint8 code_size = code_sizes_to_pack[i];
1984 if (code_size != prev_code_size)
1989 else if (++rle_repeat_count == 6)
1994 prev_code_size = code_size;
2009 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
2022 for (i = 0; i <= 143; ++i) *p++ = 8;
2023 for ( ; i <= 255; ++i) *p++ = 9;
2024 for ( ; i <= 279; ++i) *p++ = 7;
2025 for ( ; i <= 287; ++i) *p++ = 8;
2035 static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
2037 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
2047 #define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
2050 for (pLZ_codes = d->
m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
2053 flags = *pLZ_codes++ | 0x100;
2057 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
2058 mz_uint match_len = pLZ_codes[0], match_dist = *(
const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
2069 sym = (match_dist < 512) ? s0 : s1;
2070 num_extra_bits = (match_dist < 512) ? n0 : n1;
2074 TDEFL_PUT_BITS_FAST(match_dist &
mz_bitmasks[num_extra_bits], num_extra_bits);
2082 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
2089 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
2103 pOutput_buf += (bits_in >> 3);
2104 bit_buffer >>= (bits_in & ~7);
2108 #undef TDEFL_PUT_BITS_FAST
2133 for (pLZ_codes = d->
m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
2136 flags = *pLZ_codes++ | 0x100;
2140 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
2146 if (match_dist < 512)
2170 #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
2183 mz_uint saved_bit_buf, saved_bits_in;
2228 else if (!comp_block_succeeded)
2267 if ((n -= bytes_to_copy) != 0)
2282 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2283 #define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
2289 mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->
m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
2295 if (--num_probes_left == 0)
return;
2296 #define TDEFL_PROBE \
2297 next_probe_pos = d->m_next[probe_pos]; \
2298 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
2299 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
2300 if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
2306 q = (
const mz_uint16*)(d->
m_dict + probe_pos);
if (TDEFL_READ_UNALIGNED_WORD(q) != s01)
continue; p = s; probe_len = 32;
2307 do { }
while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
2308 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
2315 *pMatch_dist = dist;
if ((*pMatch_len = match_len =
MZ_MIN(max_match_len, probe_len)) == max_match_len)
break;
2316 c01 = TDEFL_READ_UNALIGNED_WORD(&d->
m_dict[pos + match_len - 1]);
2332 if (--num_probes_left == 0)
return;
2333 #define TDEFL_PROBE \
2334 next_probe_pos = d->m_next[probe_pos]; \
2335 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
2336 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
2337 if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break;
2340 if (!dist)
break; p = s; q = d->
m_dict + probe_pos;
for (probe_len = 0; probe_len < max_match_len; probe_len++)
if (*p++ != *q++)
break;
2341 if (probe_len > match_len)
2343 *pMatch_dist = dist;
if ((*pMatch_len = match_len = probe_len) == max_match_len)
return;
2344 c0 = d->
m_dict[pos + match_len]; c1 = d->
m_dict[pos + match_len - 1];
2348 #endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2350 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
2360 const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
2364 lookahead_size += num_bytes_to_process;
2366 while (num_bytes_to_process)
2374 num_bytes_to_process -= n;
2378 if ((!d->
m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE))
break;
2380 while (lookahead_size >= 4)
2382 mz_uint cur_match_dist, cur_match_len = 1;
2394 do { }
while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
2395 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
2403 *pLZ_code_buf++ = (
mz_uint8)first_trigram;
2404 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
2410 cur_match_len =
MZ_MIN(cur_match_len, lookahead_size);
2419 *pLZ_flags = (
mz_uint8)((*pLZ_flags >> 1) | 0x80);
2423 d->
m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++;
2430 *pLZ_code_buf++ = (
mz_uint8)first_trigram;
2431 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
2435 if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
2437 total_lz_bytes += cur_match_len;
2438 lookahead_pos += cur_match_len;
2441 MZ_ASSERT(lookahead_size >= cur_match_len);
2442 lookahead_size -= cur_match_len;
2455 while (lookahead_size)
2460 *pLZ_code_buf++ = lit;
2461 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
2462 if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
2487 #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
2526 mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
2533 const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process;
2534 src_buf_left -= num_bytes_to_process;
2536 while (pSrc != pSrc_end)
2573 cur_match_len = 0;
while (cur_match_len < d->m_lookahead_size) {
if (d->
m_dict[cur_pos + cur_match_len] != c)
break; cur_match_len++; }
2583 cur_match_dist = cur_match_len = 0;
2590 if (cur_match_len >= 128)
2606 else if (!cur_match_dist)
2611 len_to_move = cur_match_len;
2662 if (pIn_buf_size) *pIn_buf_size = 0;
2663 if (pOut_buf_size) *pOut_buf_size = 0;
2674 (d->
m_wants_to_finish && (flush !=
TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf) )
2676 if (pIn_buf_size) *pIn_buf_size = 0;
2677 if (pOut_buf_size) *pOut_buf_size = 0;
2685 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
2690 if (!tdefl_compress_fast(d))
2694 #endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
2723 d->
m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
2754 MZ_FREE(pComp);
return succeeded;
2767 size_t new_size = p->
m_size + len;
2771 do { new_capacity =
MZ_MAX(128U, new_capacity << 1U); }
while (new_size > new_capacity);
2782 if (!pOut_len)
return MZ_FALSE;
else *pOut_len = 0;
2791 if (!pOut_buf)
return 0;
2797 #ifndef MINIZ_NO_ZLIB_APIS
2798 static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2814 #endif //MINIZ_NO_ZLIB_APIS
2817 #pragma warning (push)
2818 #pragma warning (disable:4204) // nonstandard extension used : non-constant aggregate initializer (also supported by GNU C and C99, so no big deal)
2827 static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2829 if (!pComp)
return NULL;
2838 *pLen_out = out_buf.
m_size-41;
2840 static const mz_uint8 chans[] = {0x00, 0x00, 0x04, 0x02, 0x06};
2841 mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
2842 0,0,(
mz_uint8)(w>>8),(
mz_uint8)w,0,0,(
mz_uint8)(h>>8),(
mz_uint8)h,8,chans[num_chans],0,0,0,0,0,0,0,
2845 memcpy(out_buf.
m_pBuf, pnghdr, 41);
2860 #pragma warning (pop)
2865 #ifndef MINIZ_NO_ARCHIVE_APIS
2867 #ifdef MINIZ_NO_STDIO
2868 #define MZ_FILE void *
2871 #include <sys/stat.h>
2873 #if defined(_MSC_VER) || defined(__MINGW64__)
2874 static FILE *mz_fopen(
const char *pFilename,
const char *pMode)
2877 fopen_s(&pFile, pFilename, pMode);
2880 static FILE *mz_freopen(
const char *pPath,
const char *pMode, FILE *pStream)
2883 if (freopen_s(&pFile, pPath, pMode, pStream))
2887 #ifndef MINIZ_NO_TIME
2888 #include <sys/utime.h>
2890 #define MZ_FILE FILE
2891 #define MZ_FOPEN mz_fopen
2892 #define MZ_FCLOSE fclose
2893 #define MZ_FREAD fread
2894 #define MZ_FWRITE fwrite
2895 #define MZ_FTELL64 _ftelli64
2896 #define MZ_FSEEK64 _fseeki64
2897 #define MZ_FILE_STAT_STRUCT _stat
2898 #define MZ_FILE_STAT _stat
2899 #define MZ_FFLUSH fflush
2900 #define MZ_FREOPEN mz_freopen
2901 #define MZ_DELETE_FILE remove
2902 #elif defined(__MINGW32__)
2903 #ifndef MINIZ_NO_TIME
2904 #include <sys/utime.h>
2906 #define MZ_FILE FILE
2907 #define MZ_FOPEN(f, m) fopen(f, m)
2908 #define MZ_FCLOSE fclose
2909 #define MZ_FREAD fread
2910 #define MZ_FWRITE fwrite
2911 #define MZ_FTELL64 ftello64
2912 #define MZ_FSEEK64 fseeko64
2913 #define MZ_FILE_STAT_STRUCT _stat
2914 #define MZ_FILE_STAT _stat
2915 #define MZ_FFLUSH fflush
2916 #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
2917 #define MZ_DELETE_FILE remove
2918 #elif defined(__TINYC__)
2919 #ifndef MINIZ_NO_TIME
2920 #include <sys/utime.h>
2922 #define MZ_FILE FILE
2923 #define MZ_FOPEN(f, m) fopen(f, m)
2924 #define MZ_FCLOSE fclose
2925 #define MZ_FREAD fread
2926 #define MZ_FWRITE fwrite
2927 #define MZ_FTELL64 ftell
2928 #define MZ_FSEEK64 fseek
2929 #define MZ_FILE_STAT_STRUCT stat
2930 #define MZ_FILE_STAT stat
2931 #define MZ_FFLUSH fflush
2932 #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
2933 #define MZ_DELETE_FILE remove
2934 #elif defined(__GNUC__) && _LARGEFILE64_SOURCE
2935 #ifndef MINIZ_NO_TIME
2938 #define MZ_FILE FILE
2939 #define MZ_FOPEN(f, m) fopen64(f, m)
2940 #define MZ_FCLOSE fclose
2941 #define MZ_FREAD fread
2942 #define MZ_FWRITE fwrite
2943 #define MZ_FTELL64 ftello64
2944 #define MZ_FSEEK64 fseeko64
2945 #define MZ_FILE_STAT_STRUCT stat64
2946 #define MZ_FILE_STAT stat64
2947 #define MZ_FFLUSH fflush
2948 #define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
2949 #define MZ_DELETE_FILE remove
2951 #ifndef MINIZ_NO_TIME
2954 #define MZ_FILE FILE
2955 #define MZ_FOPEN(f, m) fopen(f, m)
2956 #define MZ_FCLOSE fclose
2957 #define MZ_FREAD fread
2958 #define MZ_FWRITE fwrite
2959 #define MZ_FTELL64 ftello
2960 #define MZ_FSEEK64 fseeko
2961 #define MZ_FILE_STAT_STRUCT stat
2962 #define MZ_FILE_STAT stat
2963 #define MZ_FFLUSH fflush
2964 #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
2965 #define MZ_DELETE_FILE remove
2966 #endif // #ifdef _MSC_VER
2967 #endif // #ifdef MINIZ_NO_STDIO
2969 #define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))
3009 #define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
3010 #define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
3021 if (growing) { new_capacity =
MZ_MAX(1, pArray->
m_capacity);
while (new_capacity < min_new_capacity) new_capacity *= 2; }
3036 pArray->
m_size = new_size;
3055 #ifndef MINIZ_NO_TIME
3059 memset(&tm, 0,
sizeof(tm)); tm.tm_isdst = -1;
3060 tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900; tm.tm_mon = ((dos_date >> 5) & 15) - 1; tm.tm_mday = dos_date & 31;
3061 tm.tm_hour = (dos_time >> 11) & 31; tm.tm_min = (dos_time >> 5) & 63; tm.tm_sec = (dos_time << 1) & 62;
3068 struct tm tm_struct;
3069 struct tm *tm = &tm_struct;
3070 errno_t err = localtime_s(tm, &time);
3073 *pDOS_date = 0; *pDOS_time = 0;
3077 struct tm *tm = localtime(&time);
3079 *pDOS_time = (
mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
3080 *pDOS_date = (
mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
3084 #ifndef MINIZ_NO_STDIO
3087 #ifdef MINIZ_NO_TIME
3088 (void)pFilename; *pDOS_date = *pDOS_time = 0;
3095 #endif // #ifdef MINIZ_NO_TIME
3099 #ifndef MINIZ_NO_TIME
3102 struct utimbuf t; t.actime = access_time; t.modtime = modified_time;
3103 return !utime(pFilename, &t);
3105 #endif // #ifndef MINIZ_NO_TIME
3106 #endif // #ifndef MINIZ_NO_STDIO
3139 pE = pL +
MZ_MIN(l_len, r_len);
3146 return (pL == pE) ? (l_len < r_len) : (l < r);
3149 #define MZ_SWAP_UINT32(a, b) do { mz_uint32 t = a; a = b; b = t; } MZ_MACRO_END
3159 int start = (size - 2) >> 1, end;
3162 int child, root = start;
3165 if ((child = (root << 1) + 1) >= size)
3167 child += (((child + 1) < size) && (
mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1])));
3178 int child, root = 0;
3182 if ((child = (root << 1) + 1) >= end)
3184 child += (((child + 1) < end) &&
mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1]));
3195 mz_uint cdir_size, num_this_disk, cdir_disk_index;
3211 for (i = n - 4; i >= 0; --i)
3221 cur_file_ofs =
MZ_MAX(cur_file_ofs - (
sizeof(buf_u32) - 3), 0);
3232 if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
3253 if (sort_central_dir)
3266 mz_uint total_header_size, comp_size, decomp_size, disk_index;
3270 if (sort_central_dir)
3274 if (((!
MZ_READ_LE32(p +
MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size) || (decomp_size == 0xFFFFFFFF) || (comp_size == 0xFFFFFFFF))
3277 if ((disk_index != num_this_disk) && (disk_index != 1))
3283 n -= total_header_size; p += total_header_size;
3287 if (sort_central_dir)
3295 if ((!pZip) || (!pZip->
m_pRead))
3337 #ifndef MINIZ_NO_STDIO
3375 #endif // #ifndef MINIZ_NO_STDIO
3396 return (m_bit_flag & 1);
3401 mz_uint filename_len, external_attr;
3418 if ((external_attr & 0x10) != 0)
3428 if ((!p) || (!pStat))
3438 #ifndef MINIZ_NO_TIME
3463 if (!p) {
if (filename_buf_size) pFilename[0] =
'\0';
return 0; }
3465 if (filename_buf_size)
3467 n =
MZ_MIN(n, filename_buf_size - 1);
3469 pFilename[n] =
'\0';
3478 return 0 == memcmp(pA, pB, len);
3479 for (i = 0; i < len; ++i)
3491 pE = pL +
MZ_MIN(l_len, r_len);
3498 return (pL == pE) ? (int)(l_len - r_len) : (l - r);
3509 int l = 0, h = size - 1;
3512 int m = (l + h) >> 1, file_index = pIndices[m], comp =
mz_zip_reader_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len);
3525 mz_uint file_index;
size_t name_len, comment_len;
3530 name_len = strlen(pName);
if (name_len > 0xFFFF)
return -1;
3531 comment_len = pComment ? strlen(pComment) : 0;
if (comment_len > 0xFFFF)
return -1;
3532 for (file_index = 0; file_index < pZip->
m_total_files; file_index++)
3537 if (filename_len < name_len)
3542 const char *pFile_comment = pFilename + filename_len + file_extra_len;
3548 int ofs = filename_len - 1;
3551 if ((pFilename[ofs] ==
'/') || (pFilename[ofs] ==
'\\') || (pFilename[ofs] ==
':'))
3553 }
while (--ofs >= 0);
3555 pFilename += ofs; filename_len -= ofs;
3566 mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
3572 if ((buf_size) && (!pBuf))
3597 if (buf_size < needed_size)
3614 if (pZip->
m_pRead(pZip->
m_pIO_opaque, cur_file_ofs, pBuf, (
size_t)needed_size) != needed_size)
3626 read_buf_size = read_buf_avail = file_stat.
m_comp_size;
3629 else if (pUser_read_buf)
3632 if (!user_read_buf_size)
3634 pRead_buf = (
mz_uint8 *)pUser_read_buf;
3635 read_buf_size = user_read_buf_size;
3644 if (((0,
sizeof(
size_t) ==
sizeof(
mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
3646 if (((
sizeof(
size_t) ==
sizeof(
mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
3657 size_t in_buf_size, out_buf_size = (size_t)(file_stat.
m_uncomp_size - out_buf_ofs);
3660 read_buf_avail =
MZ_MIN(read_buf_size, comp_remaining);
3661 if (pZip->
m_pRead(pZip->
m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
3666 cur_file_ofs += read_buf_avail;
3667 comp_remaining -= read_buf_avail;
3670 in_buf_size = (size_t)read_buf_avail;
3672 read_buf_avail -= in_buf_size;
3673 read_buf_ofs += in_buf_size;
3674 out_buf_ofs += out_buf_size;
3710 mz_uint64 comp_size, uncomp_size, alloc_size;
3724 if (((0,
sizeof(
size_t) ==
sizeof(
mz_uint32))) && (alloc_size > 0x7FFFFFFF))
3726 if (((
sizeof(
size_t) ==
sizeof(
mz_uint32))) && (alloc_size > 0x7FFFFFFF))
3738 if (pSize) *pSize = (size_t)alloc_size;
3747 if (pSize) *pSize = 0;
3756 mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
3758 void *pRead_buf =
NULL;
void *pWrite_buf =
NULL;
3796 read_buf_size = read_buf_avail = file_stat.
m_comp_size;
3829 while (comp_remaining)
3831 read_buf_avail =
MZ_MIN(read_buf_size, comp_remaining);
3832 if (pZip->
m_pRead(pZip->
m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
3841 if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
3846 cur_file_ofs += read_buf_avail;
3847 out_buf_ofs += read_buf_avail;
3848 comp_remaining -= read_buf_avail;
3867 read_buf_avail =
MZ_MIN(read_buf_size, comp_remaining);
3868 if (pZip->
m_pRead(pZip->
m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
3873 cur_file_ofs += read_buf_avail;
3874 comp_remaining -= read_buf_avail;
3878 in_buf_size = (size_t)read_buf_avail;
3880 read_buf_avail -= in_buf_size;
3881 read_buf_ofs += in_buf_size;
3885 if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
3891 if ((out_buf_ofs += out_buf_size) > file_stat.
m_uncomp_size)
3924 #ifndef MINIZ_NO_STDIO
3937 pFile =
MZ_FOPEN(pDst_filename,
"wb");
3943 #ifndef MINIZ_NO_TIME
3949 #endif // #ifndef MINIZ_NO_STDIO
3961 #ifndef MINIZ_NO_STDIO
3967 #endif // #ifndef MINIZ_NO_STDIO
3976 #ifndef MINIZ_NO_STDIO
3988 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3992 #define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v))
3993 #define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v))
4031 if ((!n) || ((
sizeof(
size_t) ==
sizeof(
mz_uint32)) && (new_size > 0x7FFFFFFF)))
4036 size_t new_capacity =
MZ_MAX(64, pState->
m_mem_capacity);
while (new_capacity < new_size) new_capacity *= 2;
4052 if (0 != (initial_allocation_size =
MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning)))
4064 #ifndef MINIZ_NO_STDIO
4087 if (size_to_reserve_at_beginning)
4092 size_t n = (size_t)
MZ_MIN(
sizeof(buf), size_to_reserve_at_beginning);
4098 cur_ofs += n; size_to_reserve_at_beginning -= n;
4099 }
while (size_to_reserve_at_beginning);
4103 #endif // #ifndef MINIZ_NO_STDIO
4118 #ifdef MINIZ_NO_STDIO
4133 #endif // #ifdef MINIZ_NO_STDIO
4177 static mz_bool mz_zip_writer_create_local_dir_header(
mz_zip_archive *pZip,
mz_uint8 *pDst,
mz_uint16 filename_size,
mz_uint16 extra_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date)
4195 static mz_bool mz_zip_writer_create_central_dir_header(
mz_zip_archive *pZip,
mz_uint8 *pDst,
mz_uint16 filename_size,
mz_uint16 extra_size,
mz_uint16 comment_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date,
mz_uint64 local_header_ofs,
mz_uint32 ext_attributes)
4216 static mz_bool mz_zip_writer_add_to_central_dir(
mz_zip_archive *pZip,
const char *pFilename,
mz_uint16 filename_size,
const void *pExtra,
mz_uint16 extra_size,
const void *pComment,
mz_uint16 comment_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date,
mz_uint64 local_header_ofs,
mz_uint32 ext_attributes)
4227 if (!
mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes))
4247 if (*pArchive_name ==
'/')
4249 while (*pArchive_name)
4251 if ((*pArchive_name ==
'\\') || (*pArchive_name ==
':'))
4270 memset(buf, 0,
MZ_MIN(
sizeof(buf), n));
4276 cur_file_ofs += s; n -= s;
4283 mz_uint16 method = 0, dos_time = 0, dos_date = 0;
4284 mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
4285 mz_uint64 local_dir_header_ofs, cur_archive_file_ofs, comp_size = 0;
4286 size_t archive_name_size;
4289 mz_bool store_data_uncompressed;
4292 if ((
int)level_and_flags < 0)
4294 level = level_and_flags & 0xF;
4300 local_dir_header_ofs = cur_archive_file_ofs = pZip->
m_archive_size;
4306 if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF))
4311 #ifndef MINIZ_NO_TIME
4313 time_t cur_time; time(&cur_time);
4316 #endif // #ifndef MINIZ_NO_TIME
4318 archive_name_size = strlen(pArchive_name);
4319 if (archive_name_size > 0xFFFF)
4328 if ((archive_name_size) && (pArchive_name[archive_name_size - 1] ==
'/'))
4331 ext_attributes |= 0x10;
4333 if ((buf_size) || (uncomp_size))
4341 if ((!store_data_uncompressed) && (buf_size))
4352 local_dir_header_ofs += num_alignment_padding_bytes;
4354 cur_archive_file_ofs += num_alignment_padding_bytes +
sizeof(local_dir_header);
4357 if (pZip->
m_pWrite(pZip->
m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
4362 cur_archive_file_ofs += archive_name_size;
4367 uncomp_size = buf_size;
4368 if (uncomp_size <= 3)
4371 store_data_uncompressed =
MZ_TRUE;
4375 if (store_data_uncompressed)
4383 cur_archive_file_ofs += buf_size;
4384 comp_size = buf_size;
4414 if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF))
4417 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (
mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date))
4420 if (pZip->
m_pWrite(pZip->
m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
4423 if (!
mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (
mz_uint16)archive_name_size,
NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes))
4432 #ifndef MINIZ_NO_STDIO
4436 mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
4437 mz_uint64 local_dir_header_ofs, cur_archive_file_ofs, uncomp_size = 0, comp_size = 0;
4438 size_t archive_name_size;
4442 if ((
int)level_and_flags < 0)
4444 level = level_and_flags & 0xF;
4449 local_dir_header_ofs = cur_archive_file_ofs = pZip->
m_archive_size;
4456 archive_name_size = strlen(pArchive_name);
4457 if (archive_name_size > 0xFFFF)
4469 pSrc_file =
MZ_FOPEN(pSrc_filename,
"rb");
4476 if (uncomp_size > 0xFFFFFFFF)
4482 if (uncomp_size <= 3)
4490 local_dir_header_ofs += num_alignment_padding_bytes;
4492 cur_archive_file_ofs += num_alignment_padding_bytes +
sizeof(local_dir_header);
4495 if (pZip->
m_pWrite(pZip->
m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
4500 cur_archive_file_ofs += archive_name_size;
4504 mz_uint64 uncomp_remaining = uncomp_size;
4514 while (uncomp_remaining)
4524 uncomp_remaining -= n;
4525 cur_archive_file_ofs += n;
4527 comp_size = uncomp_size;
4558 if (
MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size)
4562 uncomp_remaining -= in_buf_size;
4595 if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF))
4598 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (
mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date))
4601 if (pZip->
m_pWrite(pZip->
m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
4604 if (!
mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (
mz_uint16)archive_name_size,
NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes))
4612 #endif // #ifndef MINIZ_NO_STDIO
4616 mz_uint n, bit_flags, num_alignment_padding_bytes;
4617 mz_uint64 comp_bytes_remaining, local_dir_header_ofs;
4618 mz_uint64 cur_src_file_ofs, cur_dst_file_ofs;
4621 size_t orig_central_dir_size;
4623 void *pBuf;
const mz_uint8 *pSrc_central_header;
4648 cur_dst_file_ofs += num_alignment_padding_bytes;
4649 local_dir_header_ofs = cur_dst_file_ofs;
4662 while (comp_bytes_remaining)
4670 cur_src_file_ofs += n;
4677 cur_dst_file_ofs += n;
4679 comp_bytes_remaining -= n;
4700 cur_dst_file_ofs += n;
4705 if (cur_dst_file_ofs > 0xFFFFFFFF)
4740 mz_uint64 central_dir_ofs, central_dir_size;
4752 central_dir_ofs = 0;
4753 central_dir_size = 0;
4775 #ifndef MINIZ_NO_STDIO
4778 #endif // #ifndef MINIZ_NO_STDIO
4788 if ((!pZip) || (!pZip->
m_pState) || (!pBuf) || (!pSize))
4815 #ifndef MINIZ_NO_STDIO
4821 #endif // #ifndef MINIZ_NO_STDIO
4834 #ifndef MINIZ_NO_STDIO
4841 if ((
int)level_and_flags < 0)
4843 if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) >
MZ_UBER_COMPRESSION))
4852 created_new_archive =
MZ_TRUE;
4865 status =
mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
4871 if ((!status) && (created_new_archive))
4875 (void)ignoredStatus;
4889 if ((!pZip_filename) || (!pArchive_name))
4903 #endif // #ifndef MINIZ_NO_STDIO
4905 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
4907 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
4913 #endif // MINIZ_HEADER_FILE_ONLY