mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Compare commits
	
		
			11 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 48605fb1bd | ||
|  | 731d5b2f87 | ||
|  | e842d2de5e | ||
|  | f28a343dfa | ||
|  | 7bc1530e7a | ||
|  | 2a8a458b93 | ||
|  | aba9ad1a5a | ||
|  | fc8a9e1d8b | ||
|  | fb98158e67 | ||
|  | 56fb6c2010 | ||
|  | 6b95156074 | 
							
								
								
									
										14
									
								
								example1.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								example1.c
									
									
									
									
									
								
							| @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) | ||||
|   uLong uncomp_len = src_len; | ||||
|   uint8 *pCmp, *pUncomp; | ||||
|   uint total_succeeded = 0; | ||||
|   argc, argv; | ||||
|   (void)argc, (void)argv; | ||||
|  | ||||
|   printf("miniz.c version: %s\n", MZ_VERSION); | ||||
|  | ||||
| @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) | ||||
|       return EXIT_FAILURE; | ||||
|     } | ||||
|  | ||||
|     printf("Compressed from %u to %u bytes\n", src_len, cmp_len); | ||||
|     printf("Compressed from %u to %u bytes\n", (mz_uint32)src_len, (mz_uint32)cmp_len); | ||||
|  | ||||
|     if (step) | ||||
|     { | ||||
| @@ -61,11 +61,11 @@ int main(int argc, char *argv[]) | ||||
|         pCmp[i] ^= (rand() & 0xFF); | ||||
|       } | ||||
|     } | ||||
|      | ||||
|  | ||||
|     // Decompress. | ||||
|     cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len); | ||||
|     total_succeeded += (cmp_status == Z_OK); | ||||
|      | ||||
|  | ||||
|     if (step) | ||||
|     { | ||||
|       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; | ||||
|       } | ||||
|  | ||||
|       printf("Decompressed from %u to %u bytes\n", cmp_len, uncomp_len); | ||||
|       printf("Decompressed from %u to %u bytes\n", (mz_uint32)cmp_len, (mz_uint32)uncomp_len); | ||||
|  | ||||
|       // Ensure uncompress() returned the expected data. | ||||
|       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); | ||||
|  | ||||
|     step++; | ||||
|      | ||||
|  | ||||
|     // Keep on fuzzy testing if there's a non-empty command line. | ||||
|   } while (argc >= 2);   | ||||
|   } while (argc >= 2); | ||||
|  | ||||
|   printf("Success.\n"); | ||||
|   return EXIT_SUCCESS; | ||||
|   | ||||
							
								
								
									
										88
									
								
								example1.cbp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								example1.cbp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| <?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> | ||||
| @@ -22,7 +22,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -94,7 +94,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -167,7 +167,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
| @@ -244,7 +244,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
|   | ||||
							
								
								
									
										82
									
								
								example2.c
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								example2.c
									
									
									
									
									
								
							| @@ -7,28 +7,28 @@ typedef unsigned short uint16; | ||||
| typedef unsigned int uint; | ||||
|  | ||||
| // The string to compress. | ||||
| 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" \ | ||||
|   "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" \ | ||||
|   "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." \ | ||||
|   "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."; | ||||
| 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" \ | ||||
| "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" \ | ||||
| "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." \ | ||||
| "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."; | ||||
|  | ||||
| static const char *s_pComment = "This is a comment"; | ||||
|  | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|   uint i; | ||||
|   mz_bool status; | ||||
|   size_t uncomp_size; | ||||
|   mz_zip_archive zip_archive;  | ||||
|   void *p; | ||||
|    uint i; | ||||
|    mz_bool status; | ||||
|    size_t uncomp_size; | ||||
|    mz_zip_archive zip_archive; | ||||
|    void *p; | ||||
|  | ||||
|   printf("miniz.c version: %s\n", MZ_VERSION); | ||||
|    printf("miniz.c version: %s\n", MZ_VERSION); | ||||
|  | ||||
|   argc, argv; | ||||
|    (void)argc, (void)argv; | ||||
|  | ||||
|   // Append a bunch of text files to test.zip | ||||
|   for (i = 0; i < 50; i++) | ||||
| @@ -43,29 +43,29 @@ int main(int argc, char *argv[]) | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   // Now try to open the archive. | ||||
|   memset(&zip_archive, 0, sizeof(zip_archive)); | ||||
|   status = mz_zip_reader_init_file(&zip_archive, "test.zip", 0); | ||||
|   if (!status) | ||||
|   { | ||||
|     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); | ||||
|    // Now try to open the archive. | ||||
|    memset(&zip_archive, 0, sizeof(zip_archive)); | ||||
|    status = mz_zip_reader_init_file(&zip_archive, "test.zip", 0); | ||||
|    if (!status) | ||||
|    { | ||||
|       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; | ||||
|       } | ||||
|  | ||||
|       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. | ||||
|   p = mz_zip_reader_extract_file_to_heap(&zip_archive, "0.txt", &uncomp_size, 0); | ||||
|   if (!p) | ||||
| @@ -86,10 +86,10 @@ int main(int argc, char *argv[]) | ||||
|  | ||||
|   printf("Successfully extracted file \"0.txt\", size %u\n", (uint)uncomp_size); | ||||
|  | ||||
|   // We're done. | ||||
|   free(p); | ||||
|   mz_zip_reader_end(&zip_archive); | ||||
|    // We're done. | ||||
|    free(p); | ||||
|    mz_zip_reader_end(&zip_archive); | ||||
|  | ||||
|   printf("Success.\n"); | ||||
|   return EXIT_SUCCESS; | ||||
|    printf("Success.\n"); | ||||
|    return EXIT_SUCCESS; | ||||
| } | ||||
|   | ||||
							
								
								
									
										88
									
								
								example2.cbp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								example2.cbp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| <?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> | ||||
| @@ -22,7 +22,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -94,7 +94,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -167,7 +167,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
| @@ -244,7 +244,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
|   | ||||
							
								
								
									
										55
									
								
								example3.c
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								example3.c
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ | ||||
| // 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. | ||||
| #include "miniz.c" | ||||
| #include <limits.h> | ||||
|  | ||||
| typedef unsigned char uint8; | ||||
| typedef unsigned short uint16; | ||||
| @@ -21,10 +22,11 @@ int main(int argc, char *argv[]) | ||||
|   uint infile_size; | ||||
|   int level = Z_BEST_COMPRESSION; | ||||
|   z_stream stream; | ||||
|   int n = 1; | ||||
|   int p = 1; | ||||
|   const char *pSrc_filename; | ||||
|   const char *pDst_filename; | ||||
|      | ||||
|   long file_loc; | ||||
|  | ||||
|   printf("miniz.c version: %s\n", MZ_VERSION); | ||||
|  | ||||
|   if (argc < 4) | ||||
| @@ -38,9 +40,9 @@ int main(int argc, char *argv[]) | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|  | ||||
|   while ((n < argc) && (argv[n][0] == '-')) | ||||
|   while ((p < argc) && (argv[p][0] == '-')) | ||||
|   { | ||||
|     switch (argv[n][1]) | ||||
|     switch (argv[p][1]) | ||||
|     { | ||||
|       case 'l': | ||||
|       { | ||||
| @@ -54,36 +56,36 @@ int main(int argc, char *argv[]) | ||||
|       } | ||||
|       default: | ||||
|       { | ||||
|         printf("Invalid option: %s\n", argv[n]); | ||||
|         printf("Invalid option: %s\n", argv[p]); | ||||
|         return EXIT_FAILURE; | ||||
|       } | ||||
|     } | ||||
|     n++; | ||||
|     p++; | ||||
|   } | ||||
|  | ||||
|   if ((argc - n) < 3) | ||||
|   if ((argc - p) < 3) | ||||
|   { | ||||
|     printf("Must specify mode, input filename, and output filename after options!\n"); | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|   else if ((argc - n) > 3) | ||||
|   else if ((argc - p) > 3) | ||||
|   { | ||||
|     printf("Too many filenames!\n"); | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|    | ||||
|   pMode = argv[n++]; | ||||
|  | ||||
|   pMode = argv[p++]; | ||||
|   if (!strchr("cCdD", pMode[0])) | ||||
|   { | ||||
|     printf("Invalid mode!\n"); | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|  | ||||
|   pSrc_filename = argv[n++]; | ||||
|   pDst_filename = argv[n++]; | ||||
|   pSrc_filename = argv[p++]; | ||||
|   pDst_filename = argv[p++]; | ||||
|  | ||||
|   printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename); | ||||
|        | ||||
|  | ||||
|   // Open input file. | ||||
|   pInfile = fopen(pSrc_filename, "rb"); | ||||
|   if (!pInfile) | ||||
| @@ -91,12 +93,21 @@ int main(int argc, char *argv[]) | ||||
|     printf("Failed opening input file!\n"); | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|    | ||||
|  | ||||
|   // Determine input file's size. | ||||
|   fseek(pInfile, 0, SEEK_END); | ||||
|   infile_size = ftell(pInfile); | ||||
|   file_loc = ftell(pInfile); | ||||
|   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. | ||||
|   pOutfile = fopen(pDst_filename, "wb"); | ||||
|   if (!pOutfile) | ||||
| @@ -106,7 +117,7 @@ int main(int argc, char *argv[]) | ||||
|   } | ||||
|  | ||||
|   printf("Input file size: %u\n", infile_size); | ||||
|    | ||||
|  | ||||
|   // Init the z_stream | ||||
|   memset(&stream, 0, sizeof(stream)); | ||||
|   stream.next_in = s_inbuf; | ||||
| @@ -132,16 +143,16 @@ int main(int argc, char *argv[]) | ||||
|       { | ||||
|         // Input buffer is empty, so read more bytes from input file. | ||||
|         uint n = my_min(BUF_SIZE, infile_remaining); | ||||
|                  | ||||
|  | ||||
|         if (fread(s_inbuf, 1, n, pInfile) != n) | ||||
|         { | ||||
|           printf("Failed reading from input file!\n"); | ||||
|           return EXIT_FAILURE; | ||||
|         } | ||||
|          | ||||
|  | ||||
|         stream.next_in = s_inbuf; | ||||
|         stream.avail_in = n; | ||||
|          | ||||
|  | ||||
|         infile_remaining -= n; | ||||
|         //printf("Input bytes remaining: %u\n", infile_remaining); | ||||
|       } | ||||
| @@ -235,7 +246,7 @@ int main(int argc, char *argv[]) | ||||
|     { | ||||
|       printf("inflateEnd() failed!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|     }       | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
| @@ -250,8 +261,8 @@ int main(int argc, char *argv[]) | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|  | ||||
|   printf("Total input bytes: %u\n", stream.total_in); | ||||
|   printf("Total output bytes: %u\n", stream.total_out); | ||||
|   printf("Total input bytes: %u\n", (mz_uint32)stream.total_in); | ||||
|   printf("Total output bytes: %u\n", (mz_uint32)stream.total_out); | ||||
|   printf("Success.\n"); | ||||
|   return EXIT_SUCCESS; | ||||
| } | ||||
|   | ||||
							
								
								
									
										88
									
								
								example3.cbp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								example3.cbp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| <?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> | ||||
| @@ -22,7 +22,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -94,7 +94,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -167,7 +167,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
| @@ -244,7 +244,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
|   | ||||
							
								
								
									
										19
									
								
								example4.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								example4.c
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ | ||||
| // Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c. | ||||
| #include "tinfl.c" | ||||
| #include <stdio.h> | ||||
| #include <limits.h> | ||||
|  | ||||
| typedef unsigned char uint8; | ||||
| typedef unsigned short uint16; | ||||
| @@ -22,7 +23,8 @@ int main(int argc, char *argv[]) | ||||
|   uint infile_size, outfile_size; | ||||
|   size_t in_buf_size; | ||||
|   uint8 *pCmp_data; | ||||
|            | ||||
|   long file_loc; | ||||
|  | ||||
|   if (argc != 3) | ||||
|   { | ||||
|     printf("Usage: example4 infile outfile\n"); | ||||
| @@ -38,12 +40,21 @@ int main(int argc, char *argv[]) | ||||
|     printf("Failed opening input file!\n"); | ||||
|     return EXIT_FAILURE; | ||||
|   } | ||||
|    | ||||
|  | ||||
|   // Determine input file's size. | ||||
|   fseek(pInfile, 0, SEEK_END); | ||||
|   infile_size = ftell(pInfile); | ||||
|   file_loc = ftell(pInfile); | ||||
|   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); | ||||
|   if (!pCmp_data) | ||||
|   { | ||||
| @@ -65,7 +76,7 @@ int main(int argc, char *argv[]) | ||||
|   } | ||||
|  | ||||
|   printf("Input file size: %u\n", 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); | ||||
|   if (!status) | ||||
|   | ||||
							
								
								
									
										88
									
								
								example4.cbp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								example4.cbp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| <?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> | ||||
| @@ -22,7 +22,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -94,7 +94,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Debug|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			> | ||||
| @@ -167,7 +167,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
| @@ -244,7 +244,7 @@ | ||||
| 		<Configuration | ||||
| 			Name="Release|x64" | ||||
| 			OutputDirectory="$(SolutionDir)bin" | ||||
| 			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" | ||||
| 			IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="1" | ||||
| 			WholeProgramOptimization="1" | ||||
|   | ||||
							
								
								
									
										327
									
								
								example5.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										327
									
								
								example5.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,327 @@ | ||||
| // example5.c - Demonstrates how to use miniz.c's low-level tdefl_compress() and tinfl_inflate() API's for simple file to file compression/decompression. | ||||
| // 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. | ||||
| // 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" | ||||
|  | ||||
| // 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 short uint16; | ||||
| typedef unsigned int uint; | ||||
|  | ||||
| #define my_max(a,b) (((a) > (b)) ? (a) : (b)) | ||||
| #define my_min(a,b) (((a) < (b)) ? (a) : (b)) | ||||
|  | ||||
| // IN_BUF_SIZE is the size of the file read buffer. | ||||
| // IN_BUF_SIZE must be >= 1 | ||||
| #define IN_BUF_SIZE (1024*512) | ||||
| static uint8 s_inbuf[IN_BUF_SIZE]; | ||||
|  | ||||
| // COMP_OUT_BUF_SIZE is the size of the output buffer used during compression. | ||||
| // COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE | ||||
| #define COMP_OUT_BUF_SIZE (1024*512) | ||||
|  | ||||
| // OUT_BUF_SIZE is the size of the output buffer used during decompression. | ||||
| // OUT_BUF_SIZE must be a power of 2 >= TINFL_LZ_DICT_SIZE (because the low-level decompressor not only writes, but reads from the output buffer as it decompresses) | ||||
| //#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE) | ||||
| #define OUT_BUF_SIZE (1024*512) | ||||
| 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[]) | ||||
| { | ||||
|    const char *pMode; | ||||
|    FILE *pInfile, *pOutfile; | ||||
|    uint infile_size; | ||||
|    int level = 9; | ||||
|    int p = 1; | ||||
|    const char *pSrc_filename; | ||||
|    const char *pDst_filename; | ||||
|    const void *next_in = s_inbuf; | ||||
|    size_t avail_in = 0; | ||||
|    void *next_out = s_outbuf; | ||||
|    size_t avail_out = OUT_BUF_SIZE; | ||||
|    size_t total_in = 0, total_out = 0; | ||||
|    long file_loc; | ||||
|  | ||||
|    assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE); | ||||
|  | ||||
|    printf("miniz.c example5 (demonstrates tinfl/tdefl)\n"); | ||||
|  | ||||
|    if (argc < 4) | ||||
|    { | ||||
|       printf("File to file compression/decompression using the low-level tinfl/tdefl API's.\n"); | ||||
|       printf("Usage: example5 [options] [mode:c or d] infile outfile\n"); | ||||
|       printf("\nModes:\n"); | ||||
|       printf("c - Compresses file infile to a zlib stream in file outfile\n"); | ||||
|       printf("d - Decompress zlib stream in file infile to file outfile\n"); | ||||
|       printf("\nOptions:\n"); | ||||
|       printf("-l[0-10] - Compression level, higher values are slower, 0 is none.\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    while ((p < argc) && (argv[p][0] == '-')) | ||||
|    { | ||||
|       switch (argv[p][1]) | ||||
|       { | ||||
|          case 'l': | ||||
|          { | ||||
|             level = atoi(&argv[1][2]); | ||||
|             if ((level < 0) || (level > 10)) | ||||
|             { | ||||
|                printf("Invalid level!\n"); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|             break; | ||||
|          } | ||||
|          default: | ||||
|          { | ||||
|             printf("Invalid option: %s\n", argv[p]); | ||||
|             return EXIT_FAILURE; | ||||
|          } | ||||
|       } | ||||
|       p++; | ||||
|    } | ||||
|  | ||||
|    if ((argc - p) < 3) | ||||
|    { | ||||
|       printf("Must specify mode, input filename, and output filename after options!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|    else if ((argc - p) > 3) | ||||
|    { | ||||
|       printf("Too many filenames!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    pMode = argv[p++]; | ||||
|    if (!strchr("cCdD", pMode[0])) | ||||
|    { | ||||
|       printf("Invalid mode!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    pSrc_filename = argv[p++]; | ||||
|    pDst_filename = argv[p++]; | ||||
|  | ||||
|    printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename); | ||||
|  | ||||
|    // Open input file. | ||||
|    pInfile = fopen(pSrc_filename, "rb"); | ||||
|    if (!pInfile) | ||||
|    { | ||||
|       printf("Failed opening input file!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    // Determine input file's size. | ||||
|    fseek(pInfile, 0, SEEK_END); | ||||
|    file_loc = ftell(pInfile); | ||||
|    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. | ||||
|    pOutfile = fopen(pDst_filename, "wb"); | ||||
|    if (!pOutfile) | ||||
|    { | ||||
|       printf("Failed opening output file!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    printf("Input file size: %u\n", infile_size); | ||||
|  | ||||
|    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; | ||||
|  | ||||
|       // 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. | ||||
|       status = tdefl_init(&g_deflator, NULL, NULL, comp_flags); | ||||
|       if (status != TDEFL_STATUS_OKAY) | ||||
|       { | ||||
|          printf("tdefl_init() failed!\n"); | ||||
|          return EXIT_FAILURE; | ||||
|       } | ||||
|  | ||||
|       avail_out = COMP_OUT_BUF_SIZE; | ||||
|  | ||||
|       // Compression. | ||||
|       for ( ; ; ) | ||||
|       { | ||||
|          size_t in_bytes, out_bytes; | ||||
|  | ||||
|          if (!avail_in) | ||||
|          { | ||||
|             // Input buffer is empty, so read more bytes from input file. | ||||
|             uint n = my_min(IN_BUF_SIZE, infile_remaining); | ||||
|  | ||||
|             if (fread(s_inbuf, 1, n, pInfile) != n) | ||||
|             { | ||||
|                printf("Failed reading from input file!\n"); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|  | ||||
|             next_in = s_inbuf; | ||||
|             avail_in = n; | ||||
|  | ||||
|             infile_remaining -= n; | ||||
|             //printf("Input bytes remaining: %u\n", infile_remaining); | ||||
|          } | ||||
|  | ||||
|          in_bytes = avail_in; | ||||
|          out_bytes = avail_out; | ||||
|          // 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); | ||||
|  | ||||
|          next_in = (const char *)next_in + in_bytes; | ||||
|          avail_in -= in_bytes; | ||||
|          total_in += in_bytes; | ||||
|  | ||||
|          next_out = (char *)next_out + out_bytes; | ||||
|          avail_out -= out_bytes; | ||||
|          total_out += out_bytes; | ||||
|  | ||||
|          if ((status != TDEFL_STATUS_OKAY) || (!avail_out)) | ||||
|          { | ||||
|             // Output buffer is full, or compression is done or failed, so write buffer to output file. | ||||
|             uint n = COMP_OUT_BUF_SIZE - (uint)avail_out; | ||||
|             if (fwrite(s_outbuf, 1, n, pOutfile) != n) | ||||
|             { | ||||
|                printf("Failed writing to output file!\n"); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|             next_out = s_outbuf; | ||||
|             avail_out = COMP_OUT_BUF_SIZE; | ||||
|          } | ||||
|  | ||||
|          if (status == TDEFL_STATUS_DONE) | ||||
|          { | ||||
|             // Compression completed successfully. | ||||
|             break; | ||||
|          } | ||||
|          else if (status != TDEFL_STATUS_OKAY) | ||||
|          { | ||||
|             // Compression somehow failed. | ||||
|             printf("tdefl_compress() failed with status %i!\n", status); | ||||
|             return EXIT_FAILURE; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
|    else if ((pMode[0] == 'd') || (pMode[0] == 'D')) | ||||
|    { | ||||
|       // Decompression. | ||||
|       uint infile_remaining = infile_size; | ||||
|  | ||||
|       tinfl_decompressor inflator; | ||||
|       tinfl_init(&inflator); | ||||
|  | ||||
|       for ( ; ; ) | ||||
|       { | ||||
|          size_t in_bytes, out_bytes; | ||||
|          tinfl_status status; | ||||
|          if (!avail_in) | ||||
|          { | ||||
|             // Input buffer is empty, so read more bytes from input file. | ||||
|             uint n = my_min(IN_BUF_SIZE, infile_remaining); | ||||
|  | ||||
|             if (fread(s_inbuf, 1, n, pInfile) != n) | ||||
|             { | ||||
|                printf("Failed reading from input file!\n"); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|  | ||||
|             next_in = s_inbuf; | ||||
|             avail_in = n; | ||||
|  | ||||
|             infile_remaining -= n; | ||||
|          } | ||||
|  | ||||
|          in_bytes = avail_in; | ||||
|          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); | ||||
|  | ||||
|          avail_in -= in_bytes; | ||||
|          next_in = (const mz_uint8 *)next_in + in_bytes; | ||||
|          total_in += in_bytes; | ||||
|  | ||||
|          avail_out -= out_bytes; | ||||
|          next_out = (mz_uint8 *)next_out + out_bytes; | ||||
|          total_out += out_bytes; | ||||
|  | ||||
|          if ((status <= TINFL_STATUS_DONE) || (!avail_out)) | ||||
|          { | ||||
|             // Output buffer is full, or decompression is done, so write buffer to output file. | ||||
|             uint n = OUT_BUF_SIZE - (uint)avail_out; | ||||
|             if (fwrite(s_outbuf, 1, n, pOutfile) != n) | ||||
|             { | ||||
|                printf("Failed writing to output file!\n"); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|             next_out = s_outbuf; | ||||
|             avail_out = OUT_BUF_SIZE; | ||||
|          } | ||||
|  | ||||
|          // If status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong. | ||||
|          if (status <= TINFL_STATUS_DONE) | ||||
|          { | ||||
|             if (status == TINFL_STATUS_DONE) | ||||
|             { | ||||
|                // Decompression completed successfully. | ||||
|                break; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                // Decompression failed. | ||||
|                printf("tinfl_decompress() failed with status %i!\n", status); | ||||
|                return EXIT_FAILURE; | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       printf("Invalid mode!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    fclose(pInfile); | ||||
|    if (EOF == fclose(pOutfile)) | ||||
|    { | ||||
|       printf("Failed writing to output file!\n"); | ||||
|       return EXIT_FAILURE; | ||||
|    } | ||||
|  | ||||
|    printf("Total input bytes: %u\n", (mz_uint32)total_in); | ||||
|    printf("Total output bytes: %u\n", (mz_uint32)total_out); | ||||
|    printf("Success.\n"); | ||||
|    return EXIT_SUCCESS; | ||||
| } | ||||
							
								
								
									
										88
									
								
								example5.cbp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								example5.cbp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| <?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> | ||||
							
								
								
									
										346
									
								
								example5.vcproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										346
									
								
								example5.vcproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,346 @@ | ||||
| <?xml version="1.0" encoding="Windows-1252"?> | ||||
| <VisualStudioProject | ||||
| 	ProjectType="Visual C++" | ||||
| 	Version="9.00" | ||||
| 	Name="example5" | ||||
| 	ProjectGUID="{AE293522-92D8-4B60-95C7-B4AEE10A303F}" | ||||
| 	RootNamespace="example5" | ||||
| 	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=".\example5.c" | ||||
| 				> | ||||
| 			</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> | ||||
							
								
								
									
										20
									
								
								examples.sln
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								examples.sln
									
									
									
									
									
								
							| @@ -9,6 +9,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example3", "example3.vcproj | ||||
| EndProject | ||||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example4", "example4.vcproj", "{AE293522-92D8-4B60-95C7-C3AEE10A303F}" | ||||
| EndProject | ||||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example5", "example5.vcproj", "{AE293522-92D8-4B60-95C7-B4AEE10A303F}" | ||||
| EndProject | ||||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniz_tester", "miniz_tester.vcproj", "{AE293522-92D9-1B60-95C7-B4AEE10A303F}" | ||||
| EndProject | ||||
| Global | ||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| 		Debug|Win32 = Debug|Win32 | ||||
| @@ -49,6 +53,22 @@ Global | ||||
| 		{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|Win32.Build.0 = Release|Win32 | ||||
| 		{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|x64.ActiveCfg = Release|x64 | ||||
| 		{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|x64.Build.0 = Release|x64 | ||||
| 		{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|Win32.ActiveCfg = Debug|Win32 | ||||
| 		{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|Win32.Build.0 = Debug|Win32 | ||||
| 		{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|x64.ActiveCfg = Debug|x64 | ||||
| 		{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|x64.Build.0 = Debug|x64 | ||||
| 		{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|Win32.ActiveCfg = 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.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 | ||||
| 	GlobalSection(SolutionProperties) = preSolution | ||||
| 		HideSolutionNode = FALSE | ||||
|   | ||||
							
								
								
									
										10
									
								
								examples.workspace
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples.workspace
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?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> | ||||
							
								
								
									
										325
									
								
								miniz.c
									
									
									
									
									
								
							
							
						
						
									
										325
									
								
								miniz.c
									
									
									
									
									
								
							| @@ -1,30 +1,43 @@ | ||||
| /* miniz.c v1.11 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | ||||
| /* miniz.c v1.14 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | ||||
|    See "unlicense" statement at the end of this file. | ||||
|    Rich Geldreich <richgel99@gmail.com>, last updated May 27, 2011 | ||||
|    Rich Geldreich <richgel99@gmail.com>, last updated May 20, 2012 | ||||
|    Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt | ||||
|  | ||||
|    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). | ||||
|  | ||||
|    * Change History | ||||
|      May 15, v1.09 - Initial stable release. | ||||
|      May 27, 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  | ||||
|       Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86).      | ||||
|      5/20/12 v1.14 - MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include <time.h> (thanks fermtect). | ||||
|      5/19/12 v1.13 - From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit. | ||||
|        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. | ||||
|       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/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 | ||||
|       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. | ||||
|       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 | ||||
|       drop in throughput on some files). | ||||
|      May 28, v1.11 - Added statement from unlicense.org | ||||
|      5/15/11 v1.09 - Initial stable release. | ||||
|  | ||||
|    * Deflate/Inflate implementation notes: | ||||
|    * Low-level Deflate/Inflate implementation notes: | ||||
|  | ||||
|      Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or | ||||
|      greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses | ||||
|      approximately as well as zlib. | ||||
|  | ||||
|      Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function | ||||
|      coroutine: see tinfl_decompress(). It supports decompression into a 32KB wrapping buffer or into a memory | ||||
|      coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory | ||||
|      block large enough to hold the entire file. | ||||
|  | ||||
|      The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation. | ||||
| @@ -37,7 +50,7 @@ | ||||
|         deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound | ||||
|         inflateInit/inflateInit2/inflate/inflateEnd | ||||
|         compress, compress2, compressBound, uncompress | ||||
|         CRC-32, Adler-32 | ||||
|         CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. | ||||
|         Supports raw deflate streams or standard zlib streams with adler-32 checking. | ||||
|  | ||||
|      Limitations: | ||||
| @@ -123,6 +136,10 @@ | ||||
|  | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS) | ||||
| #include <time.h> | ||||
| #endif | ||||
|  | ||||
| // Defines to completely disable specific portions of miniz.c: | ||||
| // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. | ||||
|  | ||||
| @@ -177,14 +194,11 @@ extern "C" { | ||||
|  | ||||
| // ------------------- zlib-style API Definitions. | ||||
|  | ||||
| // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. | ||||
| // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! | ||||
| typedef unsigned long mz_ulong; | ||||
|  | ||||
| // Heap allocation callbacks. | ||||
| // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. | ||||
| typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); | ||||
| typedef void (*mz_free_func)(void *opaque, void *address); | ||||
| typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); | ||||
| // mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. | ||||
| void mz_free(void *p); | ||||
|  | ||||
| #define MZ_ADLER32_INIT (1) | ||||
| // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. | ||||
| @@ -202,21 +216,27 @@ enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3 | ||||
|  | ||||
| #ifndef MINIZ_NO_ZLIB_APIS | ||||
|  | ||||
| #define MZ_VERSION          "9.1.11" | ||||
| #define MZ_VERNUM           0x91B0 | ||||
| // Heap allocation callbacks. | ||||
| // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. | ||||
| typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); | ||||
| typedef void (*mz_free_func)(void *opaque, void *address); | ||||
| typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); | ||||
|  | ||||
| #define MZ_VERSION          "9.1.14" | ||||
| #define MZ_VERNUM           0x91E0 | ||||
| #define MZ_VER_MAJOR        9 | ||||
| #define MZ_VER_MINOR        1 | ||||
| #define MZ_VER_REVISION     11 | ||||
| #define MZ_VER_REVISION     14 | ||||
| #define MZ_VER_SUBREVISION  0 | ||||
|  | ||||
| // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other stuff is for advanced use. | ||||
| // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). | ||||
| enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 }; | ||||
|  | ||||
| // Return status codes. MZ_PARAM_ERROR is non-standard. | ||||
| enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 }; | ||||
|  | ||||
| // Compression levels. | ||||
| enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_DEFAULT_COMPRESSION = -1 }; | ||||
| // Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. | ||||
| enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 }; | ||||
|  | ||||
| // Window bits | ||||
| #define MZ_DEFAULT_WINDOW_BITS 15 | ||||
| @@ -428,7 +448,11 @@ typedef int mz_bool; | ||||
| #define MZ_TRUE (1) | ||||
|  | ||||
| // Works around MSVC's spammy "warning C4127: conditional expression is constant" message. | ||||
| #define MZ_MACRO_END while (0, 0) | ||||
| #ifdef _MSC_VER | ||||
|    #define MZ_MACRO_END while (0, 0) | ||||
| #else | ||||
|    #define MZ_MACRO_END while (0) | ||||
| #endif | ||||
|  | ||||
| // ------------------- ZIP archive reading/writing | ||||
|  | ||||
| @@ -585,11 +609,13 @@ mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilena | ||||
|  | ||||
| // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. | ||||
| // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer. | ||||
| // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. | ||||
| mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); | ||||
| mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. | ||||
| // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. | ||||
| mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
| #endif | ||||
|  | ||||
| @@ -610,6 +636,7 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip); | ||||
| // Misc. high-level helper functions: | ||||
|  | ||||
| // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. | ||||
| // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. | ||||
| mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
|  | ||||
| // Reads a single file from an archive into a heap block. | ||||
| @@ -622,7 +649,11 @@ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char | ||||
|  | ||||
| // ------------------- Low-level Decompression API Definitions | ||||
|  | ||||
| // Decompression flags. | ||||
| // 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_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. | ||||
| // TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). | ||||
| // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. | ||||
| enum | ||||
| { | ||||
|   TINFL_FLAG_PARSE_ZLIB_HEADER = 1, | ||||
| @@ -638,7 +669,7 @@ enum | ||||
| // On return: | ||||
| //  Function returns a pointer to the decompressed data, or NULL on failure. | ||||
| //  *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. | ||||
| //  The caller must free() the returned block when it's no longer needed. | ||||
| //  The caller must call mz_free() on the returned block when it's no longer needed. | ||||
| void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); | ||||
|  | ||||
| // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. | ||||
| @@ -714,17 +745,21 @@ struct tinfl_decompressor_tag | ||||
| // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). | ||||
| #define TDEFL_LESS_MEMORY 0 | ||||
|  | ||||
| // Compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): | ||||
| // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): | ||||
| // TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). | ||||
| enum | ||||
| { | ||||
|   TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF | ||||
| }; | ||||
|  | ||||
| // TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. | ||||
| // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). | ||||
| // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. | ||||
| // TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). | ||||
| // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) | ||||
| // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. | ||||
| // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. | ||||
| // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. | ||||
| enum | ||||
| { | ||||
|   TDEFL_WRITE_ZLIB_HEADER             = 0x01000, | ||||
| @@ -754,11 +789,12 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void | ||||
|  | ||||
| // Compresses an image to a compressed PNG file in memory. | ||||
| // On entry: | ||||
| //  pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. | ||||
| //  pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.  | ||||
| //  The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. | ||||
| // On return: | ||||
| //  Function returns a pointer to the compressed data, or NULL on failure. | ||||
| //  *pLen_out will be set to the size of the PNG image file. | ||||
| //  The caller must free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. | ||||
| //  The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. | ||||
| void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); | ||||
|  | ||||
| // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. | ||||
| @@ -794,6 +830,7 @@ typedef enum | ||||
|   TDEFL_FINISH = 4 | ||||
| } tdefl_flush; | ||||
|  | ||||
| // tdefl's compression state structure. | ||||
| typedef struct | ||||
| { | ||||
|   tdefl_put_buf_func_ptr m_pPut_buf_func; | ||||
| @@ -822,22 +859,30 @@ typedef struct | ||||
| } tdefl_compressor; | ||||
|  | ||||
| // Initializes the compressor. | ||||
| // 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. | ||||
| // If pBut_buf_func is NULL the user should always call the tdefl_compress() API. | ||||
| // flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) | ||||
| tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
|  | ||||
| // Compresses a block of data, consuming as much of the input as possible, and writing as much compressed data as possible. | ||||
| // Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. | ||||
| tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); | ||||
| // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a valid tdefl_put_buf_func_ptr. | ||||
|  | ||||
| // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. | ||||
| // tdefl_compress_buffer() always consumes the entire input buffer. | ||||
| tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); | ||||
|  | ||||
| tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); | ||||
| mz_uint32 tdefl_get_adler32(tdefl_compressor *d); | ||||
|  | ||||
| // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros. | ||||
| #ifndef MINIZ_NO_ZLIB_APIS | ||||
| // Create tdefl_compress() flags given zlib-style compression parameters. | ||||
| // level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) | ||||
| // window_bits may be -15 (raw deflate) or 15 (zlib) | ||||
| // strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED | ||||
| mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); | ||||
| #endif // #ifndef MINIZ_NO_ZLIB_APIS | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| @@ -860,7 +905,7 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; | ||||
|  | ||||
| #ifdef MINIZ_NO_MALLOC | ||||
|   #define MZ_MALLOC(x) NULL | ||||
|   #define MZ_FREE(x) x, ((void)0) | ||||
|   #define MZ_FREE(x) (void)x, ((void)0) | ||||
|   #define MZ_REALLOC(p, x) NULL | ||||
| #else | ||||
|   #define MZ_MALLOC(x) malloc(x) | ||||
| @@ -880,12 +925,12 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; | ||||
|   #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) | ||||
| #endif | ||||
|  | ||||
| #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !defined(__forceinline) | ||||
|   #ifdef __cplusplus | ||||
|     #define __forceinline inline | ||||
|   #else | ||||
|     #define __forceinline | ||||
|   #endif | ||||
| #ifdef _MSC_VER | ||||
|   #define MZ_FORCEINLINE __forceinline | ||||
| #elif defined(__GNUC__) | ||||
|   #define MZ_FORCEINLINE __attribute__((__always_inline__)) | ||||
| #else | ||||
|   #define MZ_FORCEINLINE | ||||
| #endif | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| @@ -894,10 +939,6 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; | ||||
|  | ||||
| // ------------------- 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_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552; | ||||
| @@ -918,12 +959,23 @@ 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, | ||||
|     0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; | ||||
|   mz_uint32 crcu32 = (mz_uint32)crc; | ||||
|   if (!ptr) return MZ_CRC32_INIT; | ||||
|   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; | ||||
|   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)]; } | ||||
|   return ~crcu32; | ||||
| } | ||||
|  | ||||
| void mz_free(void *p) | ||||
| { | ||||
|   MZ_FREE(p); | ||||
| } | ||||
|  | ||||
| #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) | ||||
| { | ||||
|   return MZ_VERSION; | ||||
| @@ -1036,7 +1088,7 @@ int mz_deflateEnd(mz_streamp pStream) | ||||
|  | ||||
| mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len) | ||||
| { | ||||
|   pStream; | ||||
|   (void)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.) | ||||
|   return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5); | ||||
| } | ||||
| @@ -2153,7 +2205,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)) | ||||
|         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)); | ||||
|       memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy); | ||||
| @@ -2175,8 +2227,7 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush) | ||||
|  | ||||
| #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES | ||||
| #define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p) | ||||
| static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) | ||||
|  | ||||
| static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) | ||||
| { | ||||
|   mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; | ||||
|   mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; | ||||
| @@ -2210,7 +2261,7 @@ static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahea | ||||
|   } | ||||
| } | ||||
| #else | ||||
| static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) | ||||
| static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) | ||||
| { | ||||
|   mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; | ||||
|   mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; | ||||
| @@ -2378,7 +2429,7 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d) | ||||
| } | ||||
| #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN | ||||
|  | ||||
| static __forceinline void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit) | ||||
| static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit) | ||||
| { | ||||
|   d->m_total_lz_bytes++; | ||||
|   *d->m_pLZ_code_buf++ = lit; | ||||
| @@ -2386,7 +2437,7 @@ static __forceinline void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit | ||||
|   d->m_huff_count[0][lit]++; | ||||
| } | ||||
|  | ||||
| static __forceinline void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist) | ||||
| static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist) | ||||
| { | ||||
|   mz_uint32 s0, s1; | ||||
|  | ||||
| @@ -2402,10 +2453,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++; } | ||||
|  | ||||
|   s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[match_dist >> 8]; | ||||
|   s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; | ||||
|   d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; | ||||
|  | ||||
|   d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; | ||||
|   if (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) | ||||
| @@ -2496,7 +2547,7 @@ static mz_bool tdefl_compress_normal(tdefl_compressor *d) | ||||
|       } | ||||
|     } | ||||
|     else if (!cur_match_dist) | ||||
|       tdefl_record_literal(d, d->m_dict[cur_pos]); | ||||
|       tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]); | ||||
|     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); | ||||
| @@ -2504,7 +2555,7 @@ static mz_bool tdefl_compress_normal(tdefl_compressor *d) | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       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; | ||||
|       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; | ||||
|     } | ||||
|     // Move the lookahead forward by len_to_move bytes. | ||||
|     d->m_lookahead_pos += len_to_move; | ||||
| @@ -2686,12 +2737,13 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void | ||||
|   return out_buf.m_size; | ||||
| } | ||||
|  | ||||
| #ifndef MINIZ_NO_ZLIB_APIS | ||||
| static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32,  16, 32, 128, 256,  512, 768, 1500 }; | ||||
|  | ||||
| // level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files). | ||||
| mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy) | ||||
| { | ||||
|   mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : 6] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); | ||||
|   mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); | ||||
|   if (window_bits > 0) comp_flags |= TDEFL_WRITE_ZLIB_HEADER; | ||||
|  | ||||
|   if (!level) comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; | ||||
| @@ -2702,6 +2754,7 @@ mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int | ||||
|  | ||||
|   return comp_flags; | ||||
| } | ||||
| #endif //MINIZ_NO_ZLIB_APIS | ||||
|  | ||||
| #ifdef _MSC_VER | ||||
| #pragma warning (push) | ||||
| @@ -2745,19 +2798,43 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, | ||||
|  | ||||
| #ifndef MINIZ_NO_ARCHIVE_APIS | ||||
|  | ||||
| #ifndef MINIZ_NO_TIME | ||||
| #include <time.h> | ||||
| #endif | ||||
|  | ||||
| #ifdef MINIZ_NO_STDIO | ||||
|   #define MZ_FILE void * | ||||
| #else | ||||
|   #include <stdio.h> | ||||
|   #include <sys/stat.h> | ||||
|   #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) | ||||
|     #include <sys/utime.h> | ||||
|  | ||||
|   #if defined(_MSC_VER) | ||||
|     static FILE *mz_fopen(const char *pFilename, const char *pMode) | ||||
|     { | ||||
|       FILE* pFile = NULL; | ||||
|       fopen_s(&pFile, pFilename, pMode); | ||||
|       return pFile; | ||||
|     } | ||||
|     static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | ||||
|     { | ||||
|       FILE* pFile = NULL; | ||||
|       if (freopen_s(&pFile, pPath, pMode, pStream)) | ||||
|         return NULL; | ||||
|       return pFile; | ||||
|     } | ||||
|   #else | ||||
|     static FILE *mz_fopen(const char *pFilename, const char *pMode) | ||||
|     { | ||||
|       return fopen(pFilename, pMode); | ||||
|     } | ||||
|     static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | ||||
|     { | ||||
|       return freopen(pPath, pMode, pStream); | ||||
|     } | ||||
|   #endif // #if defined(_MSC_VER) | ||||
|  | ||||
|   #if defined(_MSC_VER) || defined(__MINGW64__) | ||||
|     #ifndef MINIZ_NO_TIME | ||||
|       #include <sys/utime.h> | ||||
|     #endif | ||||
|     #define MZ_FILE FILE | ||||
|     #define MZ_FOPEN fopen | ||||
|     #define MZ_FOPEN mz_fopen | ||||
|     #define MZ_FCLOSE fclose | ||||
|     #define MZ_FREAD fread | ||||
|     #define MZ_FWRITE fwrite | ||||
| @@ -2766,12 +2843,46 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, | ||||
|     #define MZ_FILE_STAT_STRUCT _stat | ||||
|     #define MZ_FILE_STAT _stat | ||||
|     #define MZ_FFLUSH fflush | ||||
|     #define MZ_FREOPEN freopen | ||||
|     #define MZ_FREOPEN mz_freopen | ||||
|     #define MZ_DELETE_FILE remove | ||||
|   #elif defined(__MINGW32__) | ||||
|     #ifndef MINIZ_NO_TIME | ||||
|       #include <sys/utime.h> | ||||
|     #endif | ||||
|     #define MZ_FILE FILE | ||||
|     #define MZ_FOPEN mz_fopen | ||||
|     #define MZ_FCLOSE fclose | ||||
|     #define MZ_FREAD fread | ||||
|     #define MZ_FWRITE fwrite | ||||
|     #define MZ_FTELL64 ftello64 | ||||
|     #define MZ_FSEEK64 fseeko64 | ||||
|     #define MZ_FILE_STAT_STRUCT _stat | ||||
|     #define MZ_FILE_STAT _stat | ||||
|     #define MZ_FFLUSH fflush | ||||
|     #define MZ_FREOPEN mz_freopen | ||||
|     #define MZ_DELETE_FILE remove | ||||
|   #elif defined(__TINYC__) | ||||
|     #ifndef MINIZ_NO_TIME | ||||
|       #include <sys\utime.h> | ||||
|     #endif | ||||
|     #define MZ_FILE FILE | ||||
|     #define MZ_FOPEN mz_fopen | ||||
|     #define MZ_FCLOSE fclose | ||||
|     #define MZ_FREAD fread | ||||
|     #define MZ_FWRITE fwrite | ||||
|     #define MZ_FTELL64 ftell | ||||
|     #define MZ_FSEEK64 fseek | ||||
|     #define MZ_FILE_STAT_STRUCT stat | ||||
|     #define MZ_FILE_STAT stat | ||||
|     #define MZ_FFLUSH fflush | ||||
|     #define MZ_FREOPEN mz_freopen | ||||
|     #define MZ_DELETE_FILE remove | ||||
|   #else | ||||
|     #include <utime.h> | ||||
|     #ifndef MINIZ_NO_TIME | ||||
|       #include <utime.h> | ||||
|     #endif | ||||
|     #define MZ_FILE FILE | ||||
|     #define MZ_FOPEN fopen | ||||
|     #define MZ_FOPEN mz_fopen | ||||
|     #define MZ_FCLOSE fclose | ||||
|     #define MZ_FREAD fread | ||||
|     #define MZ_FWRITE fwrite | ||||
| @@ -2780,7 +2891,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, | ||||
|     #define MZ_FILE_STAT_STRUCT stat | ||||
|     #define MZ_FILE_STAT stat | ||||
|     #define MZ_FFLUSH fflush | ||||
|     #define MZ_FREOPEN freopen | ||||
|     #define MZ_FREOPEN mz_freopen | ||||
|     #define MZ_DELETE_FILE remove | ||||
|   #endif // #ifdef _MSC_VER | ||||
| #endif // #ifdef MINIZ_NO_STDIO | ||||
| @@ -2828,7 +2939,7 @@ struct mz_zip_internal_state_tag | ||||
| #define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size | ||||
| #define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index] | ||||
|  | ||||
| static __forceinline void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray) | ||||
| static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray) | ||||
| { | ||||
|   pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p); | ||||
|   memset(pArray, 0, sizeof(mz_zip_array)); | ||||
| @@ -2843,25 +2954,25 @@ static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array * | ||||
|   return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing) | ||||
| { | ||||
|   if (new_capacity > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) return MZ_FALSE; } | ||||
|   return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing) | ||||
| { | ||||
|   if (new_size > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) return MZ_FALSE; } | ||||
|   pArray->m_size = new_size; | ||||
|   return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n) | ||||
| { | ||||
|   return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE); | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n) | ||||
| { | ||||
|   size_t orig_size = pArray->m_size; if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) return MZ_FALSE; | ||||
|   memcpy((mz_uint8*)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size); | ||||
| @@ -2880,7 +2991,18 @@ static time_t mz_zip_dos_to_time_t(int dos_time, int dos_date) | ||||
|  | ||||
| static void mz_zip_time_to_dos_time(time_t time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date) | ||||
| { | ||||
| #ifdef _MSC_VER | ||||
|   struct tm tm_struct; | ||||
|   struct tm *tm = &tm_struct; | ||||
|   errno_t err = localtime_s(tm, &time); | ||||
|   if (err) | ||||
|   { | ||||
|     *pDOS_date = 0; *pDOS_time = 0; | ||||
|     return; | ||||
|   } | ||||
| #else | ||||
|   struct tm *tm = localtime(&time); | ||||
| #endif | ||||
|   *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1)); | ||||
|   *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday); | ||||
| } | ||||
| @@ -2904,7 +3026,7 @@ static mz_bool mz_zip_set_file_times(const char *pFilename, time_t access_time, | ||||
|   struct utimbuf t; t.actime = access_time; t.modtime = modified_time; | ||||
|   return !utime(pFilename, &t); | ||||
| #else | ||||
|   pFilename, access_time, modified_time; | ||||
|   (void)pFilename, (void)access_time, (void)modified_time; | ||||
|   return MZ_TRUE; | ||||
| #endif // #ifndef MINIZ_NO_TIME | ||||
| } | ||||
| @@ -2934,7 +3056,7 @@ static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint32 flags | ||||
|   return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index) | ||||
| { | ||||
|   const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; | ||||
|   const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index)); | ||||
| @@ -2997,7 +3119,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) | ||||
| { | ||||
|   mz_uint i, n, cdir_size, num_this_disk, cdir_disk_index; | ||||
|   mz_uint cdir_size, num_this_disk, cdir_disk_index; | ||||
|   mz_uint64 cdir_ofs; | ||||
|   mz_int64 cur_file_ofs; | ||||
|   const mz_uint8 *p; | ||||
| @@ -3047,6 +3169,7 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 fl | ||||
|  | ||||
|   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. | ||||
|     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)) || | ||||
| @@ -3167,7 +3290,7 @@ mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip) | ||||
|   return pZip ? pZip->m_total_files : 0; | ||||
| } | ||||
|  | ||||
| static __forceinline const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index) | ||||
| static MZ_FORCEINLINE const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index) | ||||
| { | ||||
|   if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) | ||||
|     return NULL; | ||||
| @@ -3256,7 +3379,7 @@ mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, cha | ||||
|   return n + 1; | ||||
| } | ||||
|  | ||||
| static __forceinline mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags) | ||||
| static MZ_FORCEINLINE mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags) | ||||
| { | ||||
|   mz_uint i; | ||||
|   if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE) | ||||
| @@ -3267,7 +3390,7 @@ static __forceinline mz_bool mz_zip_reader_string_equal(const char *pA, const ch | ||||
|   return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| static __forceinline int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len) | ||||
| static MZ_FORCEINLINE int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len) | ||||
| { | ||||
|   const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; | ||||
|   mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS); | ||||
| @@ -3419,7 +3542,11 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file | ||||
|   { | ||||
|     // Temporarily allocate a read buffer. | ||||
|     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)) | ||||
| #else | ||||
|     if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) | ||||
| #endif | ||||
|       return MZ_FALSE; | ||||
|     if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) | ||||
|       return MZ_FALSE; | ||||
| @@ -3495,7 +3622,11 @@ 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); | ||||
|  | ||||
|   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)) | ||||
| #else | ||||
|   if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) | ||||
| #endif | ||||
|     return NULL; | ||||
|   if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size))) | ||||
|     return NULL; | ||||
| @@ -3575,7 +3706,11 @@ 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. | ||||
|     if (pZip->m_pState->m_pMem) | ||||
|     { | ||||
| #ifdef _MSC_VER | ||||
|       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; | ||||
|       if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size) | ||||
|         status = TINFL_STATUS_FAILED; | ||||
| @@ -3736,6 +3871,7 @@ mz_bool mz_zip_reader_end(mz_zip_archive *pZip) | ||||
|   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) | ||||
| { | ||||
|   int file_index = mz_zip_reader_locate_file(pZip, pArchive_filename, NULL, flags); | ||||
| @@ -3743,6 +3879,7 @@ mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pAr | ||||
|     return MZ_FALSE; | ||||
|   return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags); | ||||
| } | ||||
| #endif | ||||
|  | ||||
| // ------------------- .ZIP archive writing | ||||
|  | ||||
| @@ -3788,7 +3925,11 @@ 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_internal_state *pState = pZip->m_pState; | ||||
|   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))) | ||||
| #else | ||||
|   if ((!n) || ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))) | ||||
| #endif | ||||
|     return 0; | ||||
|   if (new_size > pState->m_mem_capacity) | ||||
|   { | ||||
| @@ -4041,15 +4182,20 @@ static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_fil | ||||
| mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32) | ||||
| { | ||||
|   mz_uint16 method = 0, dos_time = 0, dos_date = 0; | ||||
|   mz_uint level = level_and_flags & 0xF, ext_attributes = 0, num_alignment_padding_bytes; | ||||
|   mz_uint level, ext_attributes = 0, num_alignment_padding_bytes; | ||||
|   mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0; | ||||
|   size_t archive_name_size; | ||||
|   mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; | ||||
|   tdefl_compressor *pComp = NULL; | ||||
|   mz_bool store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)); | ||||
|   mz_bool store_data_uncompressed; | ||||
|   mz_zip_internal_state *pState; | ||||
|  | ||||
|   if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (pZip->m_total_files == 0xFFFF) || (level > 10)) | ||||
|   if ((int)level_and_flags < 0) | ||||
|     level_and_flags = MZ_DEFAULT_LEVEL; | ||||
|   level = level_and_flags & 0xF; | ||||
|   store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)); | ||||
|  | ||||
|   if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (pZip->m_total_files == 0xFFFF) || (level > MZ_UBER_COMPRESSION)) | ||||
|     return MZ_FALSE; | ||||
|  | ||||
|   pState = pZip->m_pState; | ||||
| @@ -4186,14 +4332,18 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) | ||||
| { | ||||
|   mz_uint uncomp_crc32 = MZ_CRC32_INIT, level = level_and_flags & 0xF, num_alignment_padding_bytes; | ||||
|   mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; | ||||
|   mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0; | ||||
|   mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0; | ||||
|   size_t archive_name_size; | ||||
|   mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; | ||||
|   MZ_FILE *pSrc_file = NULL; | ||||
|  | ||||
|   if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > 10)) | ||||
|   if ((int)level_and_flags < 0) | ||||
|     level_and_flags = MZ_DEFAULT_LEVEL; | ||||
|   level = level_and_flags & 0xF; | ||||
|  | ||||
|   if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) | ||||
|     return MZ_FALSE; | ||||
|   if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA) | ||||
|     return MZ_FALSE; | ||||
| @@ -4582,7 +4732,9 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const | ||||
|   mz_zip_archive zip_archive; | ||||
|   struct MZ_FILE_STAT_STRUCT file_stat; | ||||
|   MZ_CLEAR_OBJ(zip_archive); | ||||
|   if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > 9)) | ||||
|   if ((int)level_and_flags < 0) | ||||
|      level_and_flags = MZ_DEFAULT_LEVEL; | ||||
|   if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > MZ_UBER_COMPRESSION)) | ||||
|     return MZ_FALSE; | ||||
|   if (!mz_zip_writer_validate_archive_name(pArchive_name)) | ||||
|     return MZ_FALSE; | ||||
| @@ -4606,12 +4758,15 @@ 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); | ||||
|   // Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) | ||||
|   status = status && mz_zip_writer_finalize_archive(&zip_archive); | ||||
|   status = status && mz_zip_writer_end(&zip_archive); | ||||
|   if (!mz_zip_writer_finalize_archive(&zip_archive)) | ||||
|     status = MZ_FALSE; | ||||
|   if (!mz_zip_writer_end(&zip_archive)) | ||||
|     status = MZ_FALSE; | ||||
|   if ((!status) && (created_new_archive)) | ||||
|   { | ||||
|     // It's a new archive and something went wrong, so just delete it. | ||||
|     MZ_DELETE_FILE(pZip_filename); | ||||
|     int ignoredStatus = MZ_DELETE_FILE(pZip_filename); | ||||
|     (void)ignoredStatus; | ||||
|   } | ||||
|   return status; | ||||
| } | ||||
|   | ||||
							
								
								
									
										1804
									
								
								miniz_tester.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1804
									
								
								miniz_tester.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										358
									
								
								miniz_tester.vcproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										358
									
								
								miniz_tester.vcproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,358 @@ | ||||
| <?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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								timer.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,152 @@ | ||||
| // 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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								timer.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| // 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; | ||||
| }; | ||||
							
								
								
									
										24
									
								
								tinfl.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								tinfl.c
									
									
									
									
									
								
							| @@ -10,11 +10,11 @@ | ||||
|  | ||||
| #include <stdlib.h> | ||||
|  | ||||
| typedef unsigned char mz_uint8;  | ||||
| typedef signed short mz_int16;  | ||||
| typedef unsigned short mz_uint16;  | ||||
| typedef unsigned int mz_uint32;  | ||||
| typedef unsigned int mz_uint;  | ||||
| typedef unsigned char mz_uint8; | ||||
| typedef signed short mz_int16; | ||||
| typedef unsigned short mz_uint16; | ||||
| typedef unsigned int mz_uint32; | ||||
| typedef unsigned int mz_uint; | ||||
| typedef unsigned long long mz_uint64; | ||||
|  | ||||
| #if defined(_M_IX86) || defined(_M_X64) | ||||
| @@ -30,9 +30,17 @@ typedef unsigned long long mz_uint64; | ||||
| #endif | ||||
|  | ||||
| // Works around MSVC's spammy "warning C4127: conditional expression is constant" message. | ||||
| #define MZ_MACRO_END while (0, 0) | ||||
| #ifdef _MSC_VER | ||||
|   #define MZ_MACRO_END while (0, 0) | ||||
| #else | ||||
|   #define MZ_MACRO_END while (0) | ||||
| #endif | ||||
|  | ||||
| // Decompression flags. | ||||
| // 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_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. | ||||
| // TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). | ||||
| // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. | ||||
| enum | ||||
| { | ||||
|   TINFL_FLAG_PARSE_ZLIB_HEADER = 1, | ||||
| @@ -556,7 +564,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, | ||||
|  | ||||
| #endif // #ifndef TINFL_HEADER_FILE_ONLY | ||||
|  | ||||
| /*  | ||||
| /* | ||||
|   This is free and unencumbered software released into the public domain. | ||||
|  | ||||
|   Anyone is free to copy, modify, publish, use, compile, sell, or | ||||
|   | ||||
		Reference in New Issue
	
	Block a user