Avoid using fdropen in mz_zip_add_mem_to_archive_file_in_place or
if new flag MZ_ZIP_FLAG_READ_ALLOW_WRITING is set.
This improves performance, but also fdreopen is broken on Android
(some kind of race).
Zip archives are usually read from the back to the front, making it
possible to append them to other files (e.g. executables) in order to
provide some kind of embedded filesystem.
We can actually extract the start of the archive by looking at the
central directory offset, by comparing the specified and the actual file
offset.
The Zip64 format adds another challenge as the EOCD locator specifies
the offset to the EOCD starting from the beginning of the archive. Such
relative offset cannot be directly used for archives not starting at
position zero, hence the addition of another step that tries to locate
the 64bit EOCD right before the EOCD locator. The added overhead is
pretty small (and could be made smaller by reading both the presumed
EOCD and EOCD locator at once) and works pretty well for 90% of the
archives I've tested it with, if that heuristic fails the old behaviour
is preserved.
Miniz started including windows.h from version 3.0.0 and on when compiling for Windows using MSVC.
windows.h header file is known to conflict with C++ std namespace by defining its own min/max macros. It is a common practice to disable these ancient macros in windows.h by declaring NOMINMAX macro prior to including windows.h in code.
While this issue does not affect miniz directly due to the fact that it is straight-C code and it does not use min/max from C++ std namespace, it does affect other projects like miniz-cpp which wrap and amalgamate miniz and then both compile in C++ mode and use min/max from std namespace.
It is therefore proposed to prefix inclusion of windows.h in miniz_zip.c by the following lines:
#ifndef NOMINMAX
#define NOMINMAX
#endif
Summary:
Added conditional macro definition to prevent MSVC compiler warning C5105 when compiling for Windows in straight C mode
Details:
Since version 3.0.0 miniz_zip.c includes windows.h header file when compiling for Windows using MSVC. However, when compiling miniz_zip.c using MSVC17 in straight-C mode (no C++), this inclusion causes warning C5105:
winbase.h(9531,5): warning C5105: macro expansion producing 'defined' has undefined behavior
This warning is not produced when compiling in C++ mode.
In order to prevent the warning, any straight-C code that wants to include windows.h should make an additional define before including:
#ifndef __cplusplus
#define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0
#endif
#include <windows.h>
Code Quality (Avoid Integer Overflow): Ensure correct order of integer size promotion when doing additions by placing the mz_uint64 value first or explicitly casting the first value to mz_uint64.
Pragmatic approach: Treat Linux on x86_64 the same as Mac OS X and FreeBSD,
i.e. as a Unix-like 64-bit operating system with know large file support.
Fixes#257
When NDEBUG, the assert in mz_zip_array_range_check does nothing and an unused variable warning is generated at 4159f8c8c3/miniz_zip.c (L280)
This commit removes the `|| define (NDEBUG)` so when debugging is turned off, no range check is performed.
Code should check for__USE_LARGEFILE64, not _LARGEFILE64_SOURCE
_LARGEFILE64_SOURCE should be used only for setting a preference
when compiling code (either explicitly or by the compiler itself).
Then, according to its value, features.h will take care define things
like __USE_LARGEFILE64 appropriately.
As a side-effect, this patch adds support for clang. When building
with clang one has to explicitly define _LARGEFILE64_SOURCE if he
want to use the *64 api.