mirror of
https://github.com/eledio-devices/thirdparty-miniz.git
synced 2025-11-01 08:48:31 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26e9473e5d |
14
example1.c
14
example1.c
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
|||||||
uLong uncomp_len = src_len;
|
uLong uncomp_len = src_len;
|
||||||
uint8 *pCmp, *pUncomp;
|
uint8 *pCmp, *pUncomp;
|
||||||
uint total_succeeded = 0;
|
uint total_succeeded = 0;
|
||||||
(void)argc, (void)argv;
|
argc, argv;
|
||||||
|
|
||||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Compressed from %u to %u bytes\n", (mz_uint32)src_len, (mz_uint32)cmp_len);
|
printf("Compressed from %u to %u bytes\n", src_len, cmp_len);
|
||||||
|
|
||||||
if (step)
|
if (step)
|
||||||
{
|
{
|
||||||
@@ -61,11 +61,11 @@ int main(int argc, char *argv[])
|
|||||||
pCmp[i] ^= (rand() & 0xFF);
|
pCmp[i] ^= (rand() & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompress.
|
// Decompress.
|
||||||
cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len);
|
cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len);
|
||||||
total_succeeded += (cmp_status == Z_OK);
|
total_succeeded += (cmp_status == Z_OK);
|
||||||
|
|
||||||
if (step)
|
if (step)
|
||||||
{
|
{
|
||||||
printf("Simple fuzzy test: step %u total_succeeded: %u\n", step, total_succeeded);
|
printf("Simple fuzzy test: step %u total_succeeded: %u\n", step, total_succeeded);
|
||||||
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Decompressed from %u to %u bytes\n", (mz_uint32)cmp_len, (mz_uint32)uncomp_len);
|
printf("Decompressed from %u to %u bytes\n", cmp_len, uncomp_len);
|
||||||
|
|
||||||
// Ensure uncompress() returned the expected data.
|
// Ensure uncompress() returned the expected data.
|
||||||
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
|
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
|
||||||
@@ -96,9 +96,9 @@ int main(int argc, char *argv[])
|
|||||||
free(pUncomp);
|
free(pUncomp);
|
||||||
|
|
||||||
step++;
|
step++;
|
||||||
|
|
||||||
// Keep on fuzzy testing if there's a non-empty command line.
|
// Keep on fuzzy testing if there's a non-empty command line.
|
||||||
} while (argc >= 2);
|
} while (argc >= 2);
|
||||||
|
|
||||||
printf("Success.\n");
|
printf("Success.\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
88
example1.cbp
88
example1.cbp
@@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="example1" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Debug Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example1D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example1\Debug Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Debug x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example1_x64D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example1\Debug x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example1" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example1\Release Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O3" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example1_x64" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example1\Release x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Unit filename="example1.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
82
example2.c
82
example2.c
@@ -7,28 +7,28 @@ typedef unsigned short uint16;
|
|||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
|
||||||
// The string to compress.
|
// The string to compress.
|
||||||
static const char *s_pStr =
|
static const char *s_pStr =
|
||||||
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and" \
|
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and" \
|
||||||
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it" \
|
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it" \
|
||||||
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be" \
|
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be" \
|
||||||
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as" \
|
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as" \
|
||||||
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas." \
|
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas." \
|
||||||
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any" \
|
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any" \
|
||||||
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
||||||
|
|
||||||
static const char *s_pComment = "This is a comment";
|
static const char *s_pComment = "This is a comment";
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint i;
|
uint i;
|
||||||
mz_bool status;
|
mz_bool status;
|
||||||
size_t uncomp_size;
|
size_t uncomp_size;
|
||||||
mz_zip_archive zip_archive;
|
mz_zip_archive zip_archive;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||||
|
|
||||||
(void)argc, (void)argv;
|
argc, argv;
|
||||||
|
|
||||||
// Append a bunch of text files to test.zip
|
// Append a bunch of text files to test.zip
|
||||||
for (i = 0; i < 50; i++)
|
for (i = 0; i < 50; i++)
|
||||||
@@ -43,29 +43,29 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now try to open the archive.
|
// Now try to open the archive.
|
||||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||||
status = mz_zip_reader_init_file(&zip_archive, "test.zip", 0);
|
status = mz_zip_reader_init_file(&zip_archive, "test.zip", 0);
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
printf("mz_zip_reader_init_file() failed!\n");
|
printf("mz_zip_reader_init_file() failed!\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get and print information about each file in the archive.
|
||||||
|
for (i = 0; i < mz_zip_reader_get_num_files(&zip_archive); i++)
|
||||||
|
{
|
||||||
|
mz_zip_archive_file_stat file_stat;
|
||||||
|
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat))
|
||||||
|
{
|
||||||
|
printf("mz_zip_reader_file_stat() failed!\n");
|
||||||
|
mz_zip_reader_end(&zip_archive);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get and print information about each file in the archive.
|
|
||||||
for (i = 0; i < mz_zip_reader_get_num_files(&zip_archive); i++)
|
|
||||||
{
|
|
||||||
mz_zip_archive_file_stat file_stat;
|
|
||||||
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat))
|
|
||||||
{
|
|
||||||
printf("mz_zip_reader_file_stat() failed!\n");
|
|
||||||
mz_zip_reader_end(&zip_archive);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u\n", file_stat.m_filename, file_stat.m_comment, (uint)file_stat.m_uncomp_size, (uint)file_stat.m_comp_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u\n", file_stat.m_filename, file_stat.m_comment, (uint)file_stat.m_uncomp_size, (uint)file_stat.m_comp_size);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to extract 0.txt to the heap.
|
// Try to extract 0.txt to the heap.
|
||||||
p = mz_zip_reader_extract_file_to_heap(&zip_archive, "0.txt", &uncomp_size, 0);
|
p = mz_zip_reader_extract_file_to_heap(&zip_archive, "0.txt", &uncomp_size, 0);
|
||||||
if (!p)
|
if (!p)
|
||||||
@@ -86,10 +86,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
printf("Successfully extracted file \"0.txt\", size %u\n", (uint)uncomp_size);
|
printf("Successfully extracted file \"0.txt\", size %u\n", (uint)uncomp_size);
|
||||||
|
|
||||||
// We're done.
|
// We're done.
|
||||||
free(p);
|
free(p);
|
||||||
mz_zip_reader_end(&zip_archive);
|
mz_zip_reader_end(&zip_archive);
|
||||||
|
|
||||||
printf("Success.\n");
|
printf("Success.\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
88
example2.cbp
88
example2.cbp
@@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="example2" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Debug Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example2D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example2\Debug Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Debug x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example2_x64D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example2\Debug x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example2" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example2\Release Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O3" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example2_x64" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example2\Release x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Unit filename="example2.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
55
example3.c
55
example3.c
@@ -2,7 +2,6 @@
|
|||||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||||
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
||||||
#include "miniz.c"
|
#include "miniz.c"
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
typedef unsigned short uint16;
|
typedef unsigned short uint16;
|
||||||
@@ -22,11 +21,10 @@ int main(int argc, char *argv[])
|
|||||||
uint infile_size;
|
uint infile_size;
|
||||||
int level = Z_BEST_COMPRESSION;
|
int level = Z_BEST_COMPRESSION;
|
||||||
z_stream stream;
|
z_stream stream;
|
||||||
int p = 1;
|
int n = 1;
|
||||||
const char *pSrc_filename;
|
const char *pSrc_filename;
|
||||||
const char *pDst_filename;
|
const char *pDst_filename;
|
||||||
long file_loc;
|
|
||||||
|
|
||||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
@@ -40,9 +38,9 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((p < argc) && (argv[p][0] == '-'))
|
while ((n < argc) && (argv[n][0] == '-'))
|
||||||
{
|
{
|
||||||
switch (argv[p][1])
|
switch (argv[n][1])
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
{
|
{
|
||||||
@@ -56,36 +54,36 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
printf("Invalid option: %s\n", argv[p]);
|
printf("Invalid option: %s\n", argv[n]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((argc - p) < 3)
|
if ((argc - n) < 3)
|
||||||
{
|
{
|
||||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
else if ((argc - p) > 3)
|
else if ((argc - n) > 3)
|
||||||
{
|
{
|
||||||
printf("Too many filenames!\n");
|
printf("Too many filenames!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMode = argv[p++];
|
pMode = argv[n++];
|
||||||
if (!strchr("cCdD", pMode[0]))
|
if (!strchr("cCdD", pMode[0]))
|
||||||
{
|
{
|
||||||
printf("Invalid mode!\n");
|
printf("Invalid mode!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSrc_filename = argv[p++];
|
pSrc_filename = argv[n++];
|
||||||
pDst_filename = argv[p++];
|
pDst_filename = argv[n++];
|
||||||
|
|
||||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||||
|
|
||||||
// Open input file.
|
// Open input file.
|
||||||
pInfile = fopen(pSrc_filename, "rb");
|
pInfile = fopen(pSrc_filename, "rb");
|
||||||
if (!pInfile)
|
if (!pInfile)
|
||||||
@@ -93,21 +91,12 @@ int main(int argc, char *argv[])
|
|||||||
printf("Failed opening input file!\n");
|
printf("Failed opening input file!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine input file's size.
|
// Determine input file's size.
|
||||||
fseek(pInfile, 0, SEEK_END);
|
fseek(pInfile, 0, SEEK_END);
|
||||||
file_loc = ftell(pInfile);
|
infile_size = ftell(pInfile);
|
||||||
fseek(pInfile, 0, SEEK_SET);
|
fseek(pInfile, 0, SEEK_SET);
|
||||||
|
|
||||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
|
||||||
{
|
|
||||||
// This is not a limitation of miniz or tinfl, but this example.
|
|
||||||
printf("File is too large to be processed by this example.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
infile_size = (uint)file_loc;
|
|
||||||
|
|
||||||
// Open output file.
|
// Open output file.
|
||||||
pOutfile = fopen(pDst_filename, "wb");
|
pOutfile = fopen(pDst_filename, "wb");
|
||||||
if (!pOutfile)
|
if (!pOutfile)
|
||||||
@@ -117,7 +106,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Input file size: %u\n", infile_size);
|
printf("Input file size: %u\n", infile_size);
|
||||||
|
|
||||||
// Init the z_stream
|
// Init the z_stream
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
stream.next_in = s_inbuf;
|
stream.next_in = s_inbuf;
|
||||||
@@ -143,16 +132,16 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// Input buffer is empty, so read more bytes from input file.
|
// Input buffer is empty, so read more bytes from input file.
|
||||||
uint n = my_min(BUF_SIZE, infile_remaining);
|
uint n = my_min(BUF_SIZE, infile_remaining);
|
||||||
|
|
||||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||||
{
|
{
|
||||||
printf("Failed reading from input file!\n");
|
printf("Failed reading from input file!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.next_in = s_inbuf;
|
stream.next_in = s_inbuf;
|
||||||
stream.avail_in = n;
|
stream.avail_in = n;
|
||||||
|
|
||||||
infile_remaining -= n;
|
infile_remaining -= n;
|
||||||
//printf("Input bytes remaining: %u\n", infile_remaining);
|
//printf("Input bytes remaining: %u\n", infile_remaining);
|
||||||
}
|
}
|
||||||
@@ -246,7 +235,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
printf("inflateEnd() failed!\n");
|
printf("inflateEnd() failed!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -261,8 +250,8 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Total input bytes: %u\n", (mz_uint32)stream.total_in);
|
printf("Total input bytes: %u\n", stream.total_in);
|
||||||
printf("Total output bytes: %u\n", (mz_uint32)stream.total_out);
|
printf("Total output bytes: %u\n", stream.total_out);
|
||||||
printf("Success.\n");
|
printf("Success.\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
88
example3.cbp
88
example3.cbp
@@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="example3" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Debug Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example3D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example3\Debug Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O0" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-g" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Debug x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example3_x64D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example3\Debug x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example3" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example3\Release Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example3_x64" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example3\Release x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Unit filename="example3.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
19
example4.c
19
example4.c
@@ -2,7 +2,6 @@
|
|||||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||||
#include "tinfl.c"
|
#include "tinfl.c"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
typedef unsigned short uint16;
|
typedef unsigned short uint16;
|
||||||
@@ -23,8 +22,7 @@ int main(int argc, char *argv[])
|
|||||||
uint infile_size, outfile_size;
|
uint infile_size, outfile_size;
|
||||||
size_t in_buf_size;
|
size_t in_buf_size;
|
||||||
uint8 *pCmp_data;
|
uint8 *pCmp_data;
|
||||||
long file_loc;
|
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
{
|
{
|
||||||
printf("Usage: example4 infile outfile\n");
|
printf("Usage: example4 infile outfile\n");
|
||||||
@@ -40,21 +38,12 @@ int main(int argc, char *argv[])
|
|||||||
printf("Failed opening input file!\n");
|
printf("Failed opening input file!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine input file's size.
|
// Determine input file's size.
|
||||||
fseek(pInfile, 0, SEEK_END);
|
fseek(pInfile, 0, SEEK_END);
|
||||||
file_loc = ftell(pInfile);
|
infile_size = ftell(pInfile);
|
||||||
fseek(pInfile, 0, SEEK_SET);
|
fseek(pInfile, 0, SEEK_SET);
|
||||||
|
|
||||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
|
||||||
{
|
|
||||||
// This is not a limitation of miniz or tinfl, but this example.
|
|
||||||
printf("File is too large to be processed by this example.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
infile_size = (uint)file_loc;
|
|
||||||
|
|
||||||
pCmp_data = (uint8 *)malloc(infile_size);
|
pCmp_data = (uint8 *)malloc(infile_size);
|
||||||
if (!pCmp_data)
|
if (!pCmp_data)
|
||||||
{
|
{
|
||||||
@@ -76,7 +65,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Input file size: %u\n", infile_size);
|
printf("Input file size: %u\n", infile_size);
|
||||||
|
|
||||||
in_buf_size = infile_size;
|
in_buf_size = infile_size;
|
||||||
status = tinfl_decompress_mem_to_callback(pCmp_data, &in_buf_size, tinfl_put_buf_func, pOutfile, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
status = tinfl_decompress_mem_to_callback(pCmp_data, &in_buf_size, tinfl_put_buf_func, pOutfile, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||||
if (!status)
|
if (!status)
|
||||||
|
|||||||
88
example4.cbp
88
example4.cbp
@@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="example4" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Debug Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example4D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example4\Debug Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O0" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-g" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Debug x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example4_x64D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example4\Debug x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example4" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example4\Release Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example4_x64" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example4\Release x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Unit filename="example4.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
86
example5.c
86
example5.c
@@ -2,19 +2,8 @@
|
|||||||
// The low-level API's are the fastest, make no use of dynamic memory allocation, and are the most flexible functions exposed by miniz.c.
|
// The low-level API's are the fastest, make no use of dynamic memory allocation, and are the most flexible functions exposed by miniz.c.
|
||||||
// Public domain, April 11 2012, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
// Public domain, April 11 2012, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||||
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
||||||
|
|
||||||
// Purposely disable a whole bunch of stuff this low-level example doesn't use.
|
|
||||||
#define MINIZ_NO_STDIO
|
|
||||||
#define MINIZ_NO_ARCHIVE_APIS
|
|
||||||
#define MINIZ_NO_TIME
|
|
||||||
#define MINIZ_NO_ZLIB_APIS
|
|
||||||
#define MINIZ_NO_MALLOC
|
|
||||||
#include "miniz.c"
|
#include "miniz.c"
|
||||||
|
|
||||||
// Now include stdio.h because this test uses fopen(), etc. (but we still don't want miniz.c's stdio stuff, for testing).
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
typedef unsigned short uint16;
|
typedef unsigned short uint16;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
@@ -37,17 +26,13 @@ static uint8 s_inbuf[IN_BUF_SIZE];
|
|||||||
#define OUT_BUF_SIZE (1024*512)
|
#define OUT_BUF_SIZE (1024*512)
|
||||||
static uint8 s_outbuf[OUT_BUF_SIZE];
|
static uint8 s_outbuf[OUT_BUF_SIZE];
|
||||||
|
|
||||||
// tdefl_compressor contains all the state needed by the low-level compressor so it's a pretty big struct (~300k).
|
|
||||||
// This example makes it a global vs. putting it on the stack, of course in real-world usage you'll probably malloc() or new it.
|
|
||||||
tdefl_compressor g_deflator;
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *pMode;
|
const char *pMode;
|
||||||
FILE *pInfile, *pOutfile;
|
FILE *pInfile, *pOutfile;
|
||||||
uint infile_size;
|
uint infile_size;
|
||||||
int level = 9;
|
int level = Z_BEST_COMPRESSION;
|
||||||
int p = 1;
|
int n = 1;
|
||||||
const char *pSrc_filename;
|
const char *pSrc_filename;
|
||||||
const char *pDst_filename;
|
const char *pDst_filename;
|
||||||
const void *next_in = s_inbuf;
|
const void *next_in = s_inbuf;
|
||||||
@@ -55,11 +40,10 @@ int main(int argc, char *argv[])
|
|||||||
void *next_out = s_outbuf;
|
void *next_out = s_outbuf;
|
||||||
size_t avail_out = OUT_BUF_SIZE;
|
size_t avail_out = OUT_BUF_SIZE;
|
||||||
size_t total_in = 0, total_out = 0;
|
size_t total_in = 0, total_out = 0;
|
||||||
long file_loc;
|
|
||||||
|
|
||||||
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
||||||
|
|
||||||
printf("miniz.c example5 (demonstrates tinfl/tdefl)\n");
|
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
{
|
{
|
||||||
@@ -73,9 +57,9 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((p < argc) && (argv[p][0] == '-'))
|
while ((n < argc) && (argv[n][0] == '-'))
|
||||||
{
|
{
|
||||||
switch (argv[p][1])
|
switch (argv[n][1])
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
{
|
{
|
||||||
@@ -89,36 +73,36 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
printf("Invalid option: %s\n", argv[p]);
|
printf("Invalid option: %s\n", argv[n]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((argc - p) < 3)
|
if ((argc - n) < 3)
|
||||||
{
|
{
|
||||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
else if ((argc - p) > 3)
|
else if ((argc - n) > 3)
|
||||||
{
|
{
|
||||||
printf("Too many filenames!\n");
|
printf("Too many filenames!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMode = argv[p++];
|
pMode = argv[n++];
|
||||||
if (!strchr("cCdD", pMode[0]))
|
if (!strchr("cCdD", pMode[0]))
|
||||||
{
|
{
|
||||||
printf("Invalid mode!\n");
|
printf("Invalid mode!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSrc_filename = argv[p++];
|
pSrc_filename = argv[n++];
|
||||||
pDst_filename = argv[p++];
|
pDst_filename = argv[n++];
|
||||||
|
|
||||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||||
|
|
||||||
// Open input file.
|
// Open input file.
|
||||||
pInfile = fopen(pSrc_filename, "rb");
|
pInfile = fopen(pSrc_filename, "rb");
|
||||||
if (!pInfile)
|
if (!pInfile)
|
||||||
@@ -129,18 +113,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Determine input file's size.
|
// Determine input file's size.
|
||||||
fseek(pInfile, 0, SEEK_END);
|
fseek(pInfile, 0, SEEK_END);
|
||||||
file_loc = ftell(pInfile);
|
infile_size = ftell(pInfile);
|
||||||
fseek(pInfile, 0, SEEK_SET);
|
fseek(pInfile, 0, SEEK_SET);
|
||||||
|
|
||||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
|
||||||
{
|
|
||||||
// This is not a limitation of miniz or tinfl, but this example.
|
|
||||||
printf("File is too large to be processed by this example.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
infile_size = (uint)file_loc;
|
|
||||||
|
|
||||||
// Open output file.
|
// Open output file.
|
||||||
pOutfile = fopen(pDst_filename, "wb");
|
pOutfile = fopen(pDst_filename, "wb");
|
||||||
if (!pOutfile)
|
if (!pOutfile)
|
||||||
@@ -150,22 +125,15 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Input file size: %u\n", infile_size);
|
printf("Input file size: %u\n", infile_size);
|
||||||
|
|
||||||
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
||||||
{
|
{
|
||||||
// The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing.
|
|
||||||
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
|
|
||||||
|
|
||||||
tdefl_status status;
|
|
||||||
uint infile_remaining = infile_size;
|
uint infile_remaining = infile_size;
|
||||||
|
uint comp_flags = tdefl_create_comp_flags_from_zip_params(level, MZ_DEFAULT_WINDOW_BITS, MZ_DEFAULT_STRATEGY) | TDEFL_WRITE_ZLIB_HEADER;
|
||||||
// create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined).
|
|
||||||
mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, level)] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
|
|
||||||
if (!level)
|
|
||||||
comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
|
|
||||||
|
|
||||||
// Initialize the low-level compressor.
|
// Initialize the low-level compressor.
|
||||||
status = tdefl_init(&g_deflator, NULL, NULL, comp_flags);
|
tdefl_compressor deflator;
|
||||||
|
tdefl_status status = tdefl_init(&deflator, NULL, NULL, comp_flags);
|
||||||
if (status != TDEFL_STATUS_OKAY)
|
if (status != TDEFL_STATUS_OKAY)
|
||||||
{
|
{
|
||||||
printf("tdefl_init() failed!\n");
|
printf("tdefl_init() failed!\n");
|
||||||
@@ -173,7 +141,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
avail_out = COMP_OUT_BUF_SIZE;
|
avail_out = COMP_OUT_BUF_SIZE;
|
||||||
|
|
||||||
// Compression.
|
// Compression.
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
@@ -192,7 +160,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
next_in = s_inbuf;
|
next_in = s_inbuf;
|
||||||
avail_in = n;
|
avail_in = n;
|
||||||
|
|
||||||
infile_remaining -= n;
|
infile_remaining -= n;
|
||||||
//printf("Input bytes remaining: %u\n", infile_remaining);
|
//printf("Input bytes remaining: %u\n", infile_remaining);
|
||||||
}
|
}
|
||||||
@@ -200,8 +168,8 @@ int main(int argc, char *argv[])
|
|||||||
in_bytes = avail_in;
|
in_bytes = avail_in;
|
||||||
out_bytes = avail_out;
|
out_bytes = avail_out;
|
||||||
// Compress as much of the input as possible (or all of it) to the output buffer.
|
// Compress as much of the input as possible (or all of it) to the output buffer.
|
||||||
status = tdefl_compress(&g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
status = tdefl_compress(&deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
||||||
|
|
||||||
next_in = (const char *)next_in + in_bytes;
|
next_in = (const char *)next_in + in_bytes;
|
||||||
avail_in -= in_bytes;
|
avail_in -= in_bytes;
|
||||||
total_in += in_bytes;
|
total_in += in_bytes;
|
||||||
@@ -243,7 +211,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
tinfl_decompressor inflator;
|
tinfl_decompressor inflator;
|
||||||
tinfl_init(&inflator);
|
tinfl_init(&inflator);
|
||||||
|
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
size_t in_bytes, out_bytes;
|
size_t in_bytes, out_bytes;
|
||||||
@@ -268,7 +236,7 @@ int main(int argc, char *argv[])
|
|||||||
in_bytes = avail_in;
|
in_bytes = avail_in;
|
||||||
out_bytes = avail_out;
|
out_bytes = avail_out;
|
||||||
status = tinfl_decompress(&inflator, (const mz_uint8 *)next_in, &in_bytes, s_outbuf, (mz_uint8 *)next_out, &out_bytes, (infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
|
status = tinfl_decompress(&inflator, (const mz_uint8 *)next_in, &in_bytes, s_outbuf, (mz_uint8 *)next_out, &out_bytes, (infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||||
|
|
||||||
avail_in -= in_bytes;
|
avail_in -= in_bytes;
|
||||||
next_in = (const mz_uint8 *)next_in + in_bytes;
|
next_in = (const mz_uint8 *)next_in + in_bytes;
|
||||||
total_in += in_bytes;
|
total_in += in_bytes;
|
||||||
@@ -276,7 +244,7 @@ int main(int argc, char *argv[])
|
|||||||
avail_out -= out_bytes;
|
avail_out -= out_bytes;
|
||||||
next_out = (mz_uint8 *)next_out + out_bytes;
|
next_out = (mz_uint8 *)next_out + out_bytes;
|
||||||
total_out += out_bytes;
|
total_out += out_bytes;
|
||||||
|
|
||||||
if ((status <= TINFL_STATUS_DONE) || (!avail_out))
|
if ((status <= TINFL_STATUS_DONE) || (!avail_out))
|
||||||
{
|
{
|
||||||
// Output buffer is full, or decompression is done, so write buffer to output file.
|
// Output buffer is full, or decompression is done, so write buffer to output file.
|
||||||
@@ -320,8 +288,8 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Total input bytes: %u\n", (mz_uint32)total_in);
|
printf("Total input bytes: %u\n", total_in);
|
||||||
printf("Total output bytes: %u\n", (mz_uint32)total_out);
|
printf("Total output bytes: %u\n", total_out);
|
||||||
printf("Success.\n");
|
printf("Success.\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
88
example5.cbp
88
example5.cbp
@@ -1,88 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_project_file>
|
|
||||||
<FileVersion major="1" minor="6" />
|
|
||||||
<Project>
|
|
||||||
<Option title="example5" />
|
|
||||||
<Option pch_mode="2" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Build>
|
|
||||||
<Target title="Debug Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example5D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example5\Debug Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-O0" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-g" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Debug x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example5_x64D" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example5\Debug x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-D_DEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O0" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release Win32">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example5" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example5\Release Win32_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-m32" />
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
<Linker>
|
|
||||||
<Add option="-s" />
|
|
||||||
<Add option="-m32" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
|
||||||
<Target title="Release x64">
|
|
||||||
<Option output="$(SolutionDir)bin_mingw\example5_x64" prefix_auto="1" extension_auto="1" />
|
|
||||||
<Option working_dir="$(SolutionDir)bin_mingw" />
|
|
||||||
<Option object_output="example5\Release x64_Win32" />
|
|
||||||
<Option type="1" />
|
|
||||||
<Option compiler="gcc" />
|
|
||||||
<Compiler>
|
|
||||||
<Add option="-DWIN32" />
|
|
||||||
<Add option="-DNDEBUG" />
|
|
||||||
<Add option="-D_CONSOLE" />
|
|
||||||
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
|
|
||||||
<Add option="-Wall" />
|
|
||||||
<Add option="-O3" />
|
|
||||||
</Compiler>
|
|
||||||
</Target>
|
|
||||||
</Build>
|
|
||||||
<Unit filename="example5.c">
|
|
||||||
<Option compilerVar="CC" />
|
|
||||||
</Unit>
|
|
||||||
<Extensions>
|
|
||||||
<code_completion />
|
|
||||||
<debugger />
|
|
||||||
</Extensions>
|
|
||||||
</Project>
|
|
||||||
</CodeBlocks_project_file>
|
|
||||||
10
examples.sln
10
examples.sln
@@ -11,8 +11,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example4", "example4.vcproj
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example5", "example5.vcproj", "{AE293522-92D8-4B60-95C7-B4AEE10A303F}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example5", "example5.vcproj", "{AE293522-92D8-4B60-95C7-B4AEE10A303F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniz_tester", "miniz_tester.vcproj", "{AE293522-92D9-1B60-95C7-B4AEE10A303F}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Win32 = Debug|Win32
|
Debug|Win32 = Debug|Win32
|
||||||
@@ -61,14 +59,6 @@ Global
|
|||||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|Win32.Build.0 = Release|Win32
|
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|Win32.Build.0 = Release|Win32
|
||||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.ActiveCfg = Release|x64
|
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.ActiveCfg = Release|x64
|
||||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.Build.0 = Release|x64
|
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.Build.0 = Release|x64
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{AE293522-92D9-1B60-95C7-B4AEE10A303F}.Release|x64.Build.0 = Release|x64
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
||||||
<CodeBlocks_workspace_file>
|
|
||||||
<Workspace title="Workspace">
|
|
||||||
<Project filename="example1.cbp" />
|
|
||||||
<Project filename="example2.cbp" active="1" />
|
|
||||||
<Project filename="example3.cbp" />
|
|
||||||
<Project filename="example4.cbp" />
|
|
||||||
<Project filename="example5.cbp" />
|
|
||||||
</Workspace>
|
|
||||||
</CodeBlocks_workspace_file>
|
|
||||||
97
miniz.c
97
miniz.c
@@ -1,28 +1,18 @@
|
|||||||
/* miniz.c v1.13 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
/* miniz.c v1.12 - 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 April 12, 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/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.
|
|
||||||
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
|
|
||||||
"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. 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.
|
|
||||||
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.)
|
|
||||||
Fix ftell() usage in examples so they exit with an error on files which are too large (a limitation of the examples, not miniz itself).
|
|
||||||
4/12/12 v1.12 - More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's.
|
4/12/12 v1.12 - More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's.
|
||||||
level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson <bruced@valvesoftware.com> for the feedback/bug report.
|
level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson <bruced@valvesoftware.com> for the feedback/bug report.
|
||||||
5/28/11 v1.11 - Added statement from unlicense.org
|
5/28/11 v1.11 - Added statement from unlicense.org
|
||||||
5/27/11 v1.10 - Substantial compressor optimizations:
|
5/27/11 v1.10 - Substantial compressor optimizations:
|
||||||
Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a
|
Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a
|
||||||
Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86).
|
Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86).
|
||||||
Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types.
|
Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types.
|
||||||
Refactored the compression code for better readability and maintainability.
|
Refactored the compression code for better readability and maintainability.
|
||||||
Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large
|
Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large
|
||||||
@@ -189,7 +179,7 @@ extern "C" {
|
|||||||
|
|
||||||
// ------------------- zlib-style API Definitions.
|
// ------------------- zlib-style API Definitions.
|
||||||
|
|
||||||
// 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.
|
||||||
typedef unsigned long mz_ulong;
|
typedef unsigned long mz_ulong;
|
||||||
|
|
||||||
// Heap allocation callbacks.
|
// Heap allocation callbacks.
|
||||||
@@ -214,11 +204,11 @@ 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"
|
#define MZ_VERSION "9.1.12"
|
||||||
#define MZ_VERNUM 0x91D0
|
#define MZ_VERNUM 0x91C0
|
||||||
#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 12
|
||||||
#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).
|
||||||
@@ -440,11 +430,7 @@ typedef int mz_bool;
|
|||||||
#define MZ_TRUE (1)
|
#define MZ_TRUE (1)
|
||||||
|
|
||||||
// Works around MSVC's spammy "warning C4127: conditional expression is constant" message.
|
// Works around MSVC's spammy "warning C4127: conditional expression is constant" message.
|
||||||
#ifdef _MSC_VER
|
#define MZ_MACRO_END while (0, 0)
|
||||||
#define MZ_MACRO_END while (0, 0)
|
|
||||||
#else
|
|
||||||
#define MZ_MACRO_END while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ------------------- ZIP archive reading/writing
|
// ------------------- ZIP archive reading/writing
|
||||||
|
|
||||||
@@ -849,7 +835,7 @@ typedef struct
|
|||||||
mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
|
mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
|
||||||
} tdefl_compressor;
|
} tdefl_compressor;
|
||||||
|
|
||||||
// Initializes the compressor.
|
// Initializes the compressor.
|
||||||
// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
|
// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
|
||||||
// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression.
|
// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression.
|
||||||
// If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
|
// If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
|
||||||
@@ -866,14 +852,11 @@ tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, siz
|
|||||||
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
|
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
|
||||||
mz_uint32 tdefl_get_adler32(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.
|
// 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)
|
// 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)
|
// 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
|
// 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);
|
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
|
||||||
#endif // #ifndef MINIZ_NO_ZLIB_APIS
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@@ -896,7 +879,7 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1];
|
|||||||
|
|
||||||
#ifdef MINIZ_NO_MALLOC
|
#ifdef MINIZ_NO_MALLOC
|
||||||
#define MZ_MALLOC(x) NULL
|
#define MZ_MALLOC(x) NULL
|
||||||
#define MZ_FREE(x) (void)x, ((void)0)
|
#define MZ_FREE(x) x, ((void)0)
|
||||||
#define MZ_REALLOC(p, x) NULL
|
#define MZ_REALLOC(p, x) NULL
|
||||||
#else
|
#else
|
||||||
#define MZ_MALLOC(x) malloc(x)
|
#define MZ_MALLOC(x) malloc(x)
|
||||||
@@ -930,6 +913,10 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1];
|
|||||||
|
|
||||||
// ------------------- zlib-style API's
|
// ------------------- zlib-style API's
|
||||||
|
|
||||||
|
static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque; return MZ_MALLOC(items * size); }
|
||||||
|
static void def_free_func(void *opaque, void *address) { (void)opaque, MZ_FREE(address); }
|
||||||
|
static void *def_realloc_func(void *opaque, void *address, size_t items, size_t size) { (void)opaque; return MZ_REALLOC(address, items * size); }
|
||||||
|
|
||||||
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||||
{
|
{
|
||||||
mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552;
|
mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552;
|
||||||
@@ -950,18 +937,12 @@ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
|||||||
{
|
{
|
||||||
static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
|
static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
|
||||||
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
|
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
|
||||||
mz_uint32 crcu32 = (mz_uint32)crc;
|
|
||||||
if (!ptr) return MZ_CRC32_INIT;
|
if (!ptr) return MZ_CRC32_INIT;
|
||||||
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)]; }
|
crc = ~crc; while (buf_len--) { mz_uint8 b = *ptr++; crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b & 0xF)]; crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b >> 4)]; } return ~crc;
|
||||||
return ~crcu32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#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_free_func(void *opaque, void *address) { (void)opaque, (void)address; MZ_FREE(address); }
|
|
||||||
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); }
|
|
||||||
|
|
||||||
const char *mz_version(void)
|
const char *mz_version(void)
|
||||||
{
|
{
|
||||||
return MZ_VERSION;
|
return MZ_VERSION;
|
||||||
@@ -1074,7 +1055,7 @@ int mz_deflateEnd(mz_streamp pStream)
|
|||||||
|
|
||||||
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
|
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
|
||||||
{
|
{
|
||||||
(void)pStream;
|
pStream;
|
||||||
// This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.)
|
// This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.)
|
||||||
return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
|
return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
|
||||||
}
|
}
|
||||||
@@ -2191,7 +2172,7 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush)
|
|||||||
if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
|
if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
|
||||||
return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
|
return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
|
||||||
}
|
}
|
||||||
else if (pOutput_buf_start == d->m_output_buf)
|
else if (pOutput_buf_start == d->m_output_buf)
|
||||||
{
|
{
|
||||||
int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
|
int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
|
||||||
memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
|
memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
|
||||||
@@ -2440,10 +2421,10 @@ static __forceinline void tdefl_record_match(tdefl_compressor *d, mz_uint match_
|
|||||||
|
|
||||||
*d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
|
*d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
|
||||||
|
|
||||||
s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127];
|
s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[match_dist >> 8];
|
||||||
d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
|
d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
|
||||||
|
|
||||||
if (match_len >= TDEFL_MIN_MATCH_LEN) d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
|
d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mz_bool tdefl_compress_normal(tdefl_compressor *d)
|
static mz_bool tdefl_compress_normal(tdefl_compressor *d)
|
||||||
@@ -2534,7 +2515,7 @@ static mz_bool tdefl_compress_normal(tdefl_compressor *d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!cur_match_dist)
|
else if (!cur_match_dist)
|
||||||
tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]);
|
tdefl_record_literal(d, d->m_dict[cur_pos]);
|
||||||
else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
|
else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
|
||||||
{
|
{
|
||||||
tdefl_record_match(d, cur_match_len, cur_match_dist);
|
tdefl_record_match(d, cur_match_len, cur_match_dist);
|
||||||
@@ -2542,7 +2523,7 @@ static mz_bool tdefl_compress_normal(tdefl_compressor *d)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
|
d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
|
||||||
}
|
}
|
||||||
// Move the lookahead forward by len_to_move bytes.
|
// Move the lookahead forward by len_to_move bytes.
|
||||||
d->m_lookahead_pos += len_to_move;
|
d->m_lookahead_pos += len_to_move;
|
||||||
@@ -2724,7 +2705,6 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void
|
|||||||
return out_buf.m_size;
|
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 };
|
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).
|
// 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).
|
||||||
@@ -2741,7 +2721,6 @@ mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int
|
|||||||
|
|
||||||
return comp_flags;
|
return comp_flags;
|
||||||
}
|
}
|
||||||
#endif //MINIZ_NO_ZLIB_APIS
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (push)
|
#pragma warning (push)
|
||||||
@@ -3037,7 +3016,7 @@ static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *p
|
|||||||
|
|
||||||
static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 flags)
|
static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 flags)
|
||||||
{
|
{
|
||||||
mz_uint cdir_size, num_this_disk, cdir_disk_index;
|
mz_uint i, n, cdir_size, num_this_disk, cdir_disk_index;
|
||||||
mz_uint64 cdir_ofs;
|
mz_uint64 cdir_ofs;
|
||||||
mz_int64 cur_file_ofs;
|
mz_int64 cur_file_ofs;
|
||||||
const mz_uint8 *p;
|
const mz_uint8 *p;
|
||||||
@@ -3087,7 +3066,6 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 fl
|
|||||||
|
|
||||||
if (pZip->m_total_files)
|
if (pZip->m_total_files)
|
||||||
{
|
{
|
||||||
mz_uint i, n;
|
|
||||||
// Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and another to hold the sorted indices.
|
// Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and another to hold the sorted indices.
|
||||||
if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) ||
|
if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) ||
|
||||||
(!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)) ||
|
(!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)) ||
|
||||||
@@ -3460,11 +3438,7 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file
|
|||||||
{
|
{
|
||||||
// Temporarily allocate a read buffer.
|
// Temporarily allocate a read buffer.
|
||||||
read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
|
read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
|
||||||
#ifdef _MSC_VER
|
|
||||||
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
|
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
|
||||||
#else
|
|
||||||
if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
|
|
||||||
#endif
|
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
|
if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
@@ -3540,11 +3514,7 @@ void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, si
|
|||||||
uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
|
uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
|
||||||
|
|
||||||
alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
|
alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
|
||||||
#ifdef _MSC_VER
|
|
||||||
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
|
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
|
||||||
#else
|
|
||||||
if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
|
|
||||||
#endif
|
|
||||||
return NULL;
|
return NULL;
|
||||||
if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size)))
|
if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -3624,11 +3594,7 @@ mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_ind
|
|||||||
// The file is stored or the caller has requested the compressed data.
|
// The file is stored or the caller has requested the compressed data.
|
||||||
if (pZip->m_pState->m_pMem)
|
if (pZip->m_pState->m_pMem)
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
|
||||||
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF))
|
if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF))
|
||||||
#else
|
|
||||||
if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF))
|
|
||||||
#endif
|
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
|
if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
|
||||||
status = TINFL_STATUS_FAILED;
|
status = TINFL_STATUS_FAILED;
|
||||||
@@ -3789,7 +3755,6 @@ mz_bool mz_zip_reader_end(mz_zip_archive *pZip)
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MINIZ_NO_STDIO
|
|
||||||
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
|
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
|
||||||
{
|
{
|
||||||
int file_index = mz_zip_reader_locate_file(pZip, pArchive_filename, NULL, flags);
|
int file_index = mz_zip_reader_locate_file(pZip, pArchive_filename, NULL, flags);
|
||||||
@@ -3797,7 +3762,6 @@ mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pAr
|
|||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags);
|
return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// ------------------- .ZIP archive writing
|
// ------------------- .ZIP archive writing
|
||||||
|
|
||||||
@@ -3843,11 +3807,7 @@ static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const vo
|
|||||||
mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
|
mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
|
||||||
mz_zip_internal_state *pState = pZip->m_pState;
|
mz_zip_internal_state *pState = pZip->m_pState;
|
||||||
mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
|
mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
|
||||||
#ifdef _MSC_VER
|
|
||||||
if ((!n) || ((0, sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)))
|
if ((!n) || ((0, sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)))
|
||||||
#else
|
|
||||||
if ((!n) || ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)))
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
if (new_size > pState->m_mem_capacity)
|
if (new_size > pState->m_mem_capacity)
|
||||||
{
|
{
|
||||||
@@ -4256,7 +4216,7 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
|
|||||||
size_t archive_name_size;
|
size_t archive_name_size;
|
||||||
mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
|
mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
|
||||||
MZ_FILE *pSrc_file = NULL;
|
MZ_FILE *pSrc_file = NULL;
|
||||||
|
|
||||||
if ((int)level_and_flags < 0)
|
if ((int)level_and_flags < 0)
|
||||||
level_and_flags = MZ_DEFAULT_LEVEL;
|
level_and_flags = MZ_DEFAULT_LEVEL;
|
||||||
level = level_and_flags & 0xF;
|
level = level_and_flags & 0xF;
|
||||||
@@ -4676,15 +4636,12 @@ 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.)
|
||||||
if (!mz_zip_writer_finalize_archive(&zip_archive))
|
status = status && mz_zip_writer_finalize_archive(&zip_archive);
|
||||||
status = MZ_FALSE;
|
status = status && mz_zip_writer_end(&zip_archive);
|
||||||
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.
|
||||||
int ignoredStatus = MZ_DELETE_FILE(pZip_filename);
|
MZ_DELETE_FILE(pZip_filename);
|
||||||
(void)ignoredStatus;
|
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
1804
miniz_tester.cpp
1804
miniz_tester.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,358 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
|
||||||
<VisualStudioProject
|
|
||||||
ProjectType="Visual C++"
|
|
||||||
Version="9.00"
|
|
||||||
Name="miniz_tester"
|
|
||||||
ProjectGUID="{AE293522-92D9-1B60-95C7-B4AEE10A303F}"
|
|
||||||
RootNamespace="miniz_tester"
|
|
||||||
Keyword="Win32Proj"
|
|
||||||
TargetFrameworkVersion="196613"
|
|
||||||
>
|
|
||||||
<Platforms>
|
|
||||||
<Platform
|
|
||||||
Name="Win32"
|
|
||||||
/>
|
|
||||||
<Platform
|
|
||||||
Name="x64"
|
|
||||||
/>
|
|
||||||
</Platforms>
|
|
||||||
<ToolFiles>
|
|
||||||
</ToolFiles>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
OutputDirectory="$(SolutionDir)bin"
|
|
||||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
CharacterSet="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
|
||||||
MinimalRebuild="true"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="1"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="4"
|
|
||||||
DebugInformationFormat="4"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
OutputFile="$(OutDir)\$(ProjectName)D.exe"
|
|
||||||
LinkIncremental="2"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="1"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|x64"
|
|
||||||
OutputDirectory="$(SolutionDir)bin"
|
|
||||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
CharacterSet="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
TargetEnvironment="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
|
||||||
MinimalRebuild="true"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="1"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="4"
|
|
||||||
DebugInformationFormat="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
OutputFile="$(OutDir)\$(ProjectName)_x64D.exe"
|
|
||||||
LinkIncremental="2"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="1"
|
|
||||||
TargetMachine="17"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|Win32"
|
|
||||||
OutputDirectory="$(SolutionDir)bin"
|
|
||||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
CharacterSet="1"
|
|
||||||
WholeProgramOptimization="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="3"
|
|
||||||
InlineFunctionExpansion="2"
|
|
||||||
EnableIntrinsicFunctions="true"
|
|
||||||
FavorSizeOrSpeed="1"
|
|
||||||
OmitFramePointers="true"
|
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
|
||||||
RuntimeLibrary="0"
|
|
||||||
EnableFunctionLevelLinking="true"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="4"
|
|
||||||
DebugInformationFormat="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
LinkIncremental="1"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="1"
|
|
||||||
OptimizeReferences="2"
|
|
||||||
EnableCOMDATFolding="2"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|x64"
|
|
||||||
OutputDirectory="$(SolutionDir)bin"
|
|
||||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
CharacterSet="1"
|
|
||||||
WholeProgramOptimization="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
TargetEnvironment="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="3"
|
|
||||||
InlineFunctionExpansion="2"
|
|
||||||
EnableIntrinsicFunctions="true"
|
|
||||||
FavorSizeOrSpeed="1"
|
|
||||||
OmitFramePointers="true"
|
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
|
||||||
RuntimeLibrary="0"
|
|
||||||
EnableFunctionLevelLinking="true"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="4"
|
|
||||||
DebugInformationFormat="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
OutputFile="$(OutDir)\$(ProjectName)_x64.exe"
|
|
||||||
LinkIncremental="1"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="1"
|
|
||||||
OptimizeReferences="2"
|
|
||||||
EnableCOMDATFolding="2"
|
|
||||||
TargetMachine="17"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<References>
|
|
||||||
</References>
|
|
||||||
<Files>
|
|
||||||
<Filter
|
|
||||||
Name="Source Files"
|
|
||||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
||||||
UniqueIdentifier="{4FD737F1-C7A5-4376-A066-2A32D752A31F}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\miniz.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\miniz_tester.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\timer.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\timer.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Resource Files"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
|
||||||
UniqueIdentifier="{17DA6AB6-F800-4c08-8B7A-83BB121AAC02}"
|
|
||||||
>
|
|
||||||
</Filter>
|
|
||||||
</Files>
|
|
||||||
<Globals>
|
|
||||||
</Globals>
|
|
||||||
</VisualStudioProject>
|
|
||||||
152
timer.cpp
152
timer.cpp
@@ -1,152 +0,0 @@
|
|||||||
// File: timer.cpp - Simple high-precision timer class. Supports Win32, X360, and POSIX/Linux
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "timer.h"
|
|
||||||
|
|
||||||
#if defined(WIN32)
|
|
||||||
#include <windows.h>
|
|
||||||
#elif defined(_XBOX)
|
|
||||||
#include <xtl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned long long timer::g_init_ticks;
|
|
||||||
unsigned long long timer::g_freq;
|
|
||||||
double timer::g_inv_freq;
|
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
|
||||||
inline void query_counter(timer_ticks *pTicks)
|
|
||||||
{
|
|
||||||
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks));
|
|
||||||
}
|
|
||||||
inline void query_counter_frequency(timer_ticks *pTicks)
|
|
||||||
{
|
|
||||||
QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks));
|
|
||||||
}
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#include <sys/timex.h>
|
|
||||||
inline void query_counter(timer_ticks *pTicks)
|
|
||||||
{
|
|
||||||
struct timeval cur_time;
|
|
||||||
gettimeofday(&cur_time, NULL);
|
|
||||||
*pTicks = static_cast<unsigned long long>(cur_time.tv_sec)*1000000ULL + static_cast<unsigned long long>(cur_time.tv_usec);
|
|
||||||
}
|
|
||||||
inline void query_counter_frequency(timer_ticks *pTicks)
|
|
||||||
{
|
|
||||||
*pTicks = 1000000;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
timer::timer() :
|
|
||||||
m_start_time(0),
|
|
||||||
m_stop_time(0),
|
|
||||||
m_started(false),
|
|
||||||
m_stopped(false)
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
timer::timer(timer_ticks start_ticks)
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
init();
|
|
||||||
|
|
||||||
m_start_time = start_ticks;
|
|
||||||
|
|
||||||
m_started = true;
|
|
||||||
m_stopped = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer::start(timer_ticks start_ticks)
|
|
||||||
{
|
|
||||||
m_start_time = start_ticks;
|
|
||||||
|
|
||||||
m_started = true;
|
|
||||||
m_stopped = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer::start()
|
|
||||||
{
|
|
||||||
query_counter(&m_start_time);
|
|
||||||
|
|
||||||
m_started = true;
|
|
||||||
m_stopped = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer::stop()
|
|
||||||
{
|
|
||||||
assert(m_started);
|
|
||||||
|
|
||||||
query_counter(&m_stop_time);
|
|
||||||
|
|
||||||
m_stopped = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
double timer::get_elapsed_secs() const
|
|
||||||
{
|
|
||||||
assert(m_started);
|
|
||||||
if (!m_started)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
timer_ticks stop_time = m_stop_time;
|
|
||||||
if (!m_stopped)
|
|
||||||
query_counter(&stop_time);
|
|
||||||
|
|
||||||
timer_ticks delta = stop_time - m_start_time;
|
|
||||||
return delta * g_inv_freq;
|
|
||||||
}
|
|
||||||
|
|
||||||
timer_ticks timer::get_elapsed_us() const
|
|
||||||
{
|
|
||||||
assert(m_started);
|
|
||||||
if (!m_started)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
timer_ticks stop_time = m_stop_time;
|
|
||||||
if (!m_stopped)
|
|
||||||
query_counter(&stop_time);
|
|
||||||
|
|
||||||
timer_ticks delta = stop_time - m_start_time;
|
|
||||||
return (delta * 1000000ULL + (g_freq >> 1U)) / g_freq;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer::init()
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
{
|
|
||||||
query_counter_frequency(&g_freq);
|
|
||||||
g_inv_freq = 1.0f / g_freq;
|
|
||||||
|
|
||||||
query_counter(&g_init_ticks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timer_ticks timer::get_init_ticks()
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
init();
|
|
||||||
|
|
||||||
return g_init_ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
timer_ticks timer::get_ticks()
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
init();
|
|
||||||
|
|
||||||
timer_ticks ticks;
|
|
||||||
query_counter(&ticks);
|
|
||||||
return ticks - g_init_ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
double timer::ticks_to_secs(timer_ticks ticks)
|
|
||||||
{
|
|
||||||
if (!g_inv_freq)
|
|
||||||
init();
|
|
||||||
|
|
||||||
return ticks * g_inv_freq;
|
|
||||||
}
|
|
||||||
|
|
||||||
40
timer.h
40
timer.h
@@ -1,40 +0,0 @@
|
|||||||
// File: timer.h
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
typedef unsigned long long timer_ticks;
|
|
||||||
|
|
||||||
class timer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
timer();
|
|
||||||
timer(timer_ticks start_ticks);
|
|
||||||
|
|
||||||
void start();
|
|
||||||
void start(timer_ticks start_ticks);
|
|
||||||
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
double get_elapsed_secs() const;
|
|
||||||
inline double get_elapsed_ms() const { return get_elapsed_secs() * 1000.0f; }
|
|
||||||
timer_ticks get_elapsed_us() const;
|
|
||||||
|
|
||||||
static void init();
|
|
||||||
static inline timer_ticks get_ticks_per_sec() { return g_freq; }
|
|
||||||
static timer_ticks get_init_ticks();
|
|
||||||
static timer_ticks get_ticks();
|
|
||||||
static double ticks_to_secs(timer_ticks ticks);
|
|
||||||
static inline double ticks_to_ms(timer_ticks ticks) { return ticks_to_secs(ticks) * 1000.0f; }
|
|
||||||
static inline double get_secs() { return ticks_to_secs(get_ticks()); }
|
|
||||||
static inline double get_ms() { return ticks_to_ms(get_ticks()); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static timer_ticks g_init_ticks;
|
|
||||||
static timer_ticks g_freq;
|
|
||||||
static double g_inv_freq;
|
|
||||||
|
|
||||||
timer_ticks m_start_time;
|
|
||||||
timer_ticks m_stop_time;
|
|
||||||
|
|
||||||
bool m_started : 1;
|
|
||||||
bool m_stopped : 1;
|
|
||||||
};
|
|
||||||
18
tinfl.c
18
tinfl.c
@@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef unsigned char mz_uint8;
|
typedef unsigned char mz_uint8;
|
||||||
typedef signed short mz_int16;
|
typedef signed short mz_int16;
|
||||||
typedef unsigned short mz_uint16;
|
typedef unsigned short mz_uint16;
|
||||||
typedef unsigned int mz_uint32;
|
typedef unsigned int mz_uint32;
|
||||||
typedef unsigned int mz_uint;
|
typedef unsigned int mz_uint;
|
||||||
typedef unsigned long long mz_uint64;
|
typedef unsigned long long mz_uint64;
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_X64)
|
#if defined(_M_IX86) || defined(_M_X64)
|
||||||
@@ -30,11 +30,7 @@ typedef unsigned long long mz_uint64;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Works around MSVC's spammy "warning C4127: conditional expression is constant" message.
|
// Works around MSVC's spammy "warning C4127: conditional expression is constant" message.
|
||||||
#ifdef _MSC_VER
|
#define MZ_MACRO_END while (0, 0)
|
||||||
#define MZ_MACRO_END while (0, 0)
|
|
||||||
#else
|
|
||||||
#define MZ_MACRO_END while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Decompression flags used by tinfl_decompress().
|
// Decompression flags used by tinfl_decompress().
|
||||||
// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
|
// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
|
||||||
@@ -564,7 +560,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
|
|||||||
|
|
||||||
#endif // #ifndef TINFL_HEADER_FILE_ONLY
|
#endif // #ifndef TINFL_HEADER_FILE_ONLY
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is free and unencumbered software released into the public domain.
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
|||||||
Reference in New Issue
Block a user