diff --git a/project/jni/zzip/Android.mk b/project/jni/zzip/Android.mk new file mode 100644 index 000000000..332d00492 --- /dev/null +++ b/project/jni/zzip/Android.mk @@ -0,0 +1,24 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := zzip + +APP_SUBDIRS := $(patsubst $(LOCAL_PATH)/%, %, $(shell find $(LOCAL_PATH)/zzip -type d)) + +LOCAL_CFLAGS := -O3 $(foreach D, $(APP_SUBDIRS), -I$(LOCAL_PATH)/$(D)) \ + -I$(LOCAL_PATH)/include -I$(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include + + +LOCAL_CPP_EXTENSION := .cpp + +LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp)))) +LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c)))) + +LOCAL_SHARED_LIBRARIES := sdl-$(SDL_VERSION) + +LOCAL_STATIC_LIBRARIES := + +LOCAL_LDLIBS := -llog -lz + +include $(BUILD_SHARED_LIBRARY) diff --git a/project/jni/zzip/COPYING.LIB b/project/jni/zzip/COPYING.LIB new file mode 100644 index 000000000..eb685a5ec --- /dev/null +++ b/project/jni/zzip/COPYING.LIB @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/project/jni/zzip/ChangeLog b/project/jni/zzip/ChangeLog new file mode 100644 index 000000000..61ec34b35 --- /dev/null +++ b/project/jni/zzip/ChangeLog @@ -0,0 +1,1497 @@ +2010-03-29 guidod + + * Makefile.am: change osc to new home:guidod:zziplib-13 + * configure.ac: update to autoconf 2.61 which does some things differently + * m4/ax_pax_tar.m4: bug report http://trac.macports.org/ticket/24227 + showed a problem on MacOsX where some "pax" tools where advertising + an "-O" option in their "--help" page but it did not work. Therefore + rewriting the macro to actually test some "-w -O" to create a tarfile. + +2010-03-26 guidod + + * zzip/dir.c: and zzip/file.c - adding comments to the compat32 + functions such that they appear near their off_t variants. + Also added the ifdef-EOVERFLOW check that is needed on Win32. + +2010-03-25 guidod + + * Makefile.mk: add "-I m4" and re-autoconf with newest autotools. + * zzip/zzip32.h: introducing compat32 functions that take "long" + arguments where the others use "off_t". Basically, there are + two calls per each off_t-function on all systems where + previously that had been only done for those 64on32 systems. + This scheme maximized binary compatibility - if an application + can not be compiled with _LARGEFILE_SOURCE then they can use + the compat32 variants to be always sure to do the right thing. + +2010-02-15 guidod + + * zzip/Makefile.am: newest "install" does not like to install fetch.h + three times ("...not overwite... it just installed") + * Makefile.am: allow to build locally with "osc" (opensuse buildservice) + +2010-02-14 guidod + + * zzip/Makefile.am: use install-*-hook instead of install-*-local + * docs/Makefile.am: PYTHONDONTWRITEBYTECODE=1 to ensure running + python with a read-only source code repository (dynamic workspaces) + NOTE: python -B was introduced with Python 2.6 (so use environment) + * zzip/plugin.c: missing "void" + again thanks to Peter Breitenlohner (tex-live tug org) + * test/Makefile.am: build-zips outside of source tree + * m4/ax_prefix_config_h.m4: reduce error to warning as suggested + * m4/ax_check_aligned_access_required.m4: merging with derived + macro zziplib-aligned-access.m4 by Peter Breitenlohner + + +2009-09-24 guidod + * zziplib.spec: prepare 0.13.59 + * configure.ac: add --with-defines to allow compile-definitions + for easy,harden,allow_modulo_entries (also for documentation) + * zzip/zip.c: add ZZIP_EASY to disable the ZZIP_CORRECT_ROOTSEEK + feature + * zzip/zip.c (__zzip_parse_root_directory): add parenthesis to fix + ZZIP_ALLOW_MODULO_ENTRIES (as reported by Tulipánt Gergely) + * zzip/fetch.h: add MSVC defines for x86/x64 that allows direct access + +2009-08-23 guidod + + * Makefile.mk: remove some old stuff related to the compilefarm + * zziplib.spec: prepare 0.13.58 + * add ports/symbian-S60/zziplib-symbian.zip (thanks to Rangel Reale) + * switch from CVS to SVN (!!!!) and update some docs/*.htm files + * zzip/mmapped.c (zzip_disk_mmap): compile error on win32-mingw [1771707] + +2009-08-16 guidod + + * configure.ac: reorder ax_gcc_flags as the extra options were + disabled (do not know why) and add -Wstrict-aliasing to the set. + Then fix issues in source files (mostly signed-comparision warnings) + * zzip/file.c (zzip_file_open): ZZIP_CASELESS will include a + mapping of "\" into "/" to get away with windows-orientied + programs. The backslash however is only active for those + windows' binaries. Fixes an issue with non-msvc win32-builds. + +2009-08-04 guidod + + * m4/ac_sys_largefile_sensitive.m4: update, fixes ticket:2825391 + * zzip/mmapped.h: zzip/memdisk.h: replace buflen argument + from "int" to "size_t" type for init from some mem area. + +2009-08-03 guidod + + * zziplib.spec: prepare 0.13.57 + * bins/zziptest.c: redefine to win32-Sleep() when seen WINDOWS_H + which allows it to compile also with a gcc/mingw/msvcrt target + * bins/Makefile.am: ZZIP_LDFLAGS are not needed for *.exe targets + in fact they make for problems in crosscompiling without libtool + * zzip/fseeko.c: typo "fseeko" -> "fseek" made for a compile error + on systems that do not have fseeko like windows msvcrt + (reported by Josh Heidenreich) + +2009-07-03 guidod + + * zzip/mmapped.c: insert zzip_disk_buffer and + * zzip/memdisk.c: zzip_mem_disk_buffer where both functions + will actually wrap an external buffer (e.g. mmapped from + another resource such as shared memory). + * zzip/mmapped.c and zzip/mmapped.h: uncovered a bug for the + MATCH_NOCASE handling and WRAPPED_BUFFER handling that is + now handled by explicit ->flags values. The actual flag + values are now exported to the header instead of just using + a simple "1". + * ideas for zzip_disk_buffer / zzip_mem_disk_buffer sprang from + a proposal by JP Dai [Goldleaf] who offerd very similar code. + +2009-06-27 guidod + + * zziplib.spec: 0.13.56 - and make build.opensuse.org happy by + removing the %if/%endif sections. (it seems one buildserver + script understands it while the other don't - and effectivly + all variants fail if it is left in. Hopefully no other platforms + have problems with the additional buildrequires that are put here) + * zzip/mmapped.c (zzip_disk_new): malloc(sizof()) was errornously + using a pointer instead of ZZIP_DISK. Not part of libzzip but + of the extra library libzzipmmapped that is in-memory-only. + (problem reported and solution shown by JP Dai [Goldleaf]) + * configure.ac: disable search for python2.2 (gentoo bug 275247+174189) + +2009-06-22 guidod + * zziplib.spec: 0.13.55 and integrate patches for build.opensuse.org + * zzip/zip.c (__zzip_parse_root_directory): rework parse_directory + to allow for ZZIP_ALLOW_MODULO_ENTRIES version as required for + some cases where more than 65535 entries are packed into a + non-ZIP64 archive. The modulo_entries variant is disabled by + default but the know for the problem space was put into code to + check for two more error conditions and report them in debug mode. + (problem space was described carefully by Tulipánt Gergely and + the provided patch was a good foundation for the ifdef code) + * configure.ac: use $can_build_shared from linker-config to allow + build on platforms that do not support a shared library concept + or where it is disabled (the commandline switch overrides it?) + (should fix the SF bug ID 2796485 reported by Giovanni Bechis) + * zzip/file.c: errornous usage of currentfp before setting it to + the new fp value in zzip_seek(). In the good case it would seek + on the wrong file and in the bad case it goes off on sigbus/NPE. + The problem occurs only if two+ zips are accessed simultanously. + (problem reported and patch kindly provided by Evgeniy Muhin) + * docs/Makefile.am: fixup for newer xmlto may be to generate + a subdirectory "man3" inside of our output directory "man3" + and gard against usage of man3/man3 for the tarball unpacking. + (problem reported by Liu Qi [debian package maintainer]) + * zzip/__hints.h: add else-part for ZZIP_GNUC_PACKED + (makes for problems with MSVC as reported by Denny Kunker) + +2009-05-24 guidod + * zzip/fetch.c - remove SET/GET fetch definitions that already + exist in zzip/fetch.h where they have been corrected lately. + * docs/Makefile.am - change from install-sf via shell.sf.net to + upload-sourceforge via web.sf.net - and alias to "www" shorthand + * docs/referentials.htm - fix typo. + * 0.13.54 + +2009-05-23 guidod + * SDL/Makefile.am - remove dependency on zzip-config (and sdl-config) + which do not exist any since quite a time - instead use pkg-config + > Thanks to Michael Sterret for bringing it up + * SDL/SDL_rwops_zzcat.c: the SDL_rwops example was fixed, as the + nmemb/size of the sdl-read call were swapped over. The testsdl + self check (based on zzcatsdl) works OK. + * SDL/Makefile.am - the targe installation paths for the example + was fixed to include/SDL_rwops_zzip - additionally there is now + an SDL_rwops_zzip.pc pkgconfig script that will refer to the new + location (it had been previously installed in include/SDL, ouch). + * Note that the old zzip-sdl pkgconfig-files are gone now. Given that the + example was not quite working, it is improbable that anyone had + been using them in real code, so there's nothing breaking here. + * create a new package SDL_rwops-devel in zziplib.spec that will catch + the example code, SDL_rwops_zzip includes and SDL_rwops_zzip pkgconfig + * append "make check" and "make test-sdl" to zziplib.spec for minimal + pre-installation check. + * Makefile.am: fix zzip-postinstall + * zziplib.spec: specifiy %version for the Provides:-clauses + * configure.ac: do not let autoconfigured LDFLAGS/LIBS bleed into zziplib.pc + * zip.c: ensure that the zzip64_trailer entries is being used and that the + parse_root_directory function honours the full 64bit in the "entries" counter + (rejecting the patch from Tulipánt Gergely which would allow to get away with + non-standard zip archives that do use a normal zzip_trailer with a 16bit entries + counter that happens to store only the modulo value of the real entries in the + archive - zippers should fail beyond 65535 entries or switch to the ZIP64 format). + * docs/referentials.htm - include reference to http://www.ogre3d.org/ + * zzip/fseeko.c: check some more return values from fseeko/fread calls. + * 0.13.53 + +2009-05-22 guidod + * docs/Makefile.am: break a dual target into two lines as + suggested by ticket:2405440 + * m4/ax_cflags_no_writable_strings.m4 update with sed-call + suggested by ticket:2155649 + * m4/ax_check_aligned_access_required.m4 update for the cross_compiling + case with libpcap-list of host_cpu targets thare require aligned access + suggested by ticket:2479788 + * introduce ax_pax_tar.m4 to use *.tar format for manpages.tar (instead of .ar) + * 0.13.52 + +2009-05-21 guidod + + * docs/Makefile.am: make install-docs install-man3 rules so that + a failing "ar x" (on OpenBSD/vax) will not kill the whole + configure / make / make install cycle. However it simply + means that there will be no manpages on such platforms. + May be OpenBSD/vax has a "gar" (gnu ar) installed somewhere? + * closes Patches item #2716806, was opened at 2009-03-27 13:01 + * 0.13.51 + +2009-05-21 guidod + * zzip/fetch.h: ensure that either direct-bswap or direc-deref is only used + on platforms that do not require aligned memory access. The + latest report from Sylvain Beucler has shown an error a MIPS + platform (named http://www.freedink.org/ running on PSP). + * zzip/fetch.h: replace _zzip_attribute(const) with defines from zzip/__hints.h + * zzip/__hints.h: introduced ZZIP_GNUC_PACKED for __attribute__((packed)) + * zzip/format.h: replace _zzip_attribute(packed) with defines from zzip/__hints.h + * zzip/conf.h: remove _zzip_attribute - not needed anymore. + +2008-12-27 guidod + * ax_create_pkgconfig_info needs a definition for datarootdir (introduced + in latest autoconf/automake making for an error in ogre3d configuration + as reported by Ignaz Forster) + * release 0.13.50 + +2008-12-24 guidod + * add the dir-zzip-* to the cvs repo (as used on some webs) + * move "make rpm" to *.am (instead of *.mk) + * amd64 should be in libdir=$prefix/lib64 (in the spec file) + +2008-11-24 guidod + * BuildRequires: python (for %package doc) + + +2008-03-22 guidod + + * zzip/fetch.h: honor ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED for the Linux bswap + optimization. See also 443880@bugs.debian "SIGBUS on Sparc". + +2008-03-03 guidod + + * TODO: update to recent problems. Need to check my mail stack next time. + +2008-03-02 guidod + + * zzip/info.c: reverted. + * also: note that the Makefiles have been update to the newest autotools. + The project itself has been imported to an Eclipse based CDT project. + +2007-03-19 + * enforce indent by automatic indentic-check + +2007-03-17 + * http://www.securitylab.ru/forum/read.php?FID=21&TID=40858&MID=326187 + zziplib vulnerability due to usage of strcpy + * add indent-check for enforcing some source code style. + +2007-02-01 + * remake manpages.ar / htmpages.ar - redistribute zziplib-manpages.ar + instead while the rebuild mechanics become a lot simpler + * unless --maintainer-mode, make mans / install-mans part of the default + +2007-01-31 + * applying patches from Mike Frysinger + * consider making the manpage install target part of the default + `make install` rather than a sep install-man3 target ? (from Mike) + * Michael Sterret reports, that the SDL/* example requires zzip-config + instead of the pkgconfig stuff - actually, the whole part should be + give a makeover as newer SDL does install its own sdl.pc which makes + the current local generation of zzip-sdl-config.pc a real mess. + +2006-09-27 + * adding docs/zip-php.htm integrating Chris Branch's mail into the docs + * appending docs/changes.htm rule from ./ChangeLog + +2006-09-26 + * adding docs/notes.htm - to register some old dicussions for later + reference. Let's see how that fills up. + +2006-09-21 + * last doc/*.py updates + * last doc/mksite.* updates + * last doc/body.htm updates - including new zzipmmapped.html docu + * "make install-sf" will copy the doctree directly to sourceforge + +2006-09-18 + * docs/makedocs.py docs/zzipdoc/*.py creates new docs/zziplib-man3.tar.gz + plus zziplib.html zzipmmapped.html zzipfseeko.html + * that will be the only to be used in the future but it is not complete + +2006-08-18 + * updating msvc8 project files + * adding zlib.dll to cvs + * zzip/memdisk.c:183 overrides for off64_t will not work with off32_t !!! + * headers for mktime should return time_t - do we have the header ??? + +2006-08-17 + * A report by Tuilipant Gergely had shown an "unaligned access" + error on an alpha machine. So, I have added macro to test for + the condition of aligned access but the alpha platoform seems + to be okay. Further reports are required. + * Mark README.SDL to be explicitly outdated (it's 16. Dec. 2002) + +2008-08-14 + * Yvan Phelizot reports a problem in zzip/mmapped.c + * Malcom MacLeod had spurious problems inside a C++ project, + so let's update all heraders with explicit 'extern "C"' linkage. + +2006-08-08 + * rephrase build system, automated tests, some doc parts + +2006-04-28 + * bsd/mac needs sys/types.h for size_t + +2005-12-11 + * there have been reports about multithreading problems + * one source of problems: access to the dir->cache members. + fixed by using an explicit semaphore variable, otherwise + just allocate/deallocate the buffer / filehandle + * second source of problems: the zip file is opened _and_ read + with only one filehandle for multiple threads that + share the same "dir" handle. Look for "->currentfp". + * that is not fixed away - while access to the cache variables + can continue in the case of a "locked" state that is not + possible for open/reads. In the "locked" case the thread + must be blocked but that is a system-specific call. + * there are two ways to fix it - (a) push down the sysfile to + each zzip_file by "dup(2)"licating the sysfile handle. + However zzip looses a feature that was helping a lot on + system with a low number of sysfile hands (e.g. dos and + some embedded operating systems that I did work with). + and (b) provide an indirect ->lock() call that can be + filled by the caller application upon zzip invokation, + perhaps add it to the io-plugin structure. Well (c) is + it possible to support both styles? Dynamically? + +2005-12-10 + * testing on sourceforge compilefarm - including "make check" + * there was an error on bsd'ish systems (implicit 64on32) + which was caused by archaic CORRECT_ROOTSEEK code + being still present. Remove it? + +2005-12-09 + * testing with Microsoft Visual Studio 2005 (msvc8) Express Edition + * fixing some compilation problems related to zip64 support in win32 + +2005-12-08 + * cut acinclude.m4 into seperated aclocal macros in m4/ subdirectory + +2005-10-14 + * testing on sourceforge compilefarm, cleaning away any compiler warnings + i386-debian2.2 i386-freebsd4.8 + amd64-fedora3 alpha-debian3.0 + sparc-solaris8 powerpc-macos10.2 + * note, the build system has some quirks but not yet renovated to the + newest autoconf/automake stuff anyway - TBD before final release + +2005-10-13 + * MSVC7 knows the following __declspec attributes: + align(#), allocate("seg"), deprecated, dllexport, dllimport, + naked{for asm}, noinline, noreturn, nothrow, novtable, + property{MngC++}, selectany{common}, thread{tls}, uuid("name") + * introduce zzip__new__ for a restrict'ed return item + * introduce zzip_byte_t to help silence down compiler warnings + about signedness mismatch in assigning data buffer variables. + Especially the zlib data_in happens to be of unsigned char type. + * note that zzip/format.h does now use zzip_byte_t for layout definition + +2005-02-17 + * adding that _GNU_SOURCE on __linux__ to get the strndup prototype + * cleaning a few warning messages on different platforms as well + as a bug for 64bit platforms + * updating docs/mksite.sh and adding docs/mksite.pl and going to + let VERSION be pasted directly instead of a makefile snippet + * adding docs/memdisk.htm documentation to the series which is + currently quite shallow. + * note: no tests for actual zip64 support are made, neither for a + large central directory (more than 64K files) nor for large + files (more than 2GB). This is all theoretic but I am quite + confident that it will work. + +2005-02-16 + * change zzip/zip disk_trailer implementation + * we do not anymore pass a copy of the file block around + * we do use a local helper structure now with off_t fields + * the parse_root_directory is now using off_t for all computatations + * make check succeeds - beware, this is a new implementation + * RANT: glibc bastards make for additinal warning messages, the fseeko + prototype is not exported by default, but as soon as we add some + define to make it available, some other prototypes are disabled, + including one of the most widespread: strndup(). The documentation + even says we have to say GNU to get prototype - if you have ever heard + of unix to diverge into something not quite but be alike, here it is, + what compiles on most platforms gives a warning on linux even that it + works fine afterwards because the libc does export all we need and + autoconf does find it - it is just not prototyped and that's all. + +2005-02-15 + * adding zzip/memdisk.* as cache variant for libzzipfseeko + * add macro support for zip64 extensions + * extend trailer routines with zip64 detection (and return 0) + * add memdisk bins + +2005-01-04 + * remember TODO multithreading tests and hardening the code. + http://www.idefense.com/application/poi/display?id=153&type=vulnerabilities + +2004-12-27 + * updating to latest autoconf/automake/libtool stuff in Suse92 + * required a rewrite of ax_enable_builddir.m4 in ac-archive + * adding two macros to silence down bogus depracation warnings + from the latest gcc 3.3.5 + +2004-11-27 + * harveyandsu:yahoo:com reported an api mismatch for SDL rwops + usage and the implementation in the SDL_rwops_zzip example. + * + +2004-05-11 + * documenting zzip-cryptoid handling + * update mksite.sh + +2004-05-09 + * documenting zzipmmapped and zzipfseeko parser libraries + +2004-05-08 + * remove bogus zzip_file_open_ext_io from zzip.h + * change to use mksite.sh for documentation builds + +2004-03-08 + * add link in docs/history.htm to the new appnote.txt whitepaper + on zip file format specification. + +2004-02-19 + * a test run on solaris did show that fetch.* needs to be linked + to the new lib*.la stuff - to convert endianess-dependent + values from zip to main memory + * there seems to be an automake problem with hpux10 that I can not + yet define on what grounds it is - to get away with it I am + not defining automake 1.7 as the version to be used, plus + autoconf 2.57 - these are pretty new. + +2004-01-24 + * zzip/fseeko.c and bins/zzip.c had some issued with non-C99 compilers + which do not like variable declarations in the middle of a block + +2004-01-16 + * zzip_rewind again - the deflateReset does not reset the + input buffer variables (oops) so we have to do it + explicitly. Here we adopt to set crestlen to full + csize and the current z-buffer fillstate avail_in + to null to trigger a new read() on next zzip_read. + * the zlib headers do not tell whether next_in/avail_in + is used in deflateReset as is done in deflateInit. + A question to zlib@gzip.org brought no answer (as + is always the case) and after some thinking I did + decide to reset avail_in *after* the zReset call. + * based on this decision, I have made up a patch and I was + sending it over to zlib@gzip.org. Same consequence + again, the message is bluntly ignored (while there is + traffic on zlib devel mailinglist). There seems to be + a major problem about it, either a technical problem + (mail-adress disfunctional) or a social problem (no + one cares or perhaps some minor racism). + +2003-12-29 + * added libzzipfseeko.la with another simplified interface + * rename the other one to libzzipmmapped.la + * fix bugs for decompression on the latter as well + it seems the one has to use inflateInit2 (..., -MAX_WBITS) + * added bins/unzzipshow for an example binary + * added "--help" and "--version" to all bins examples + +2003-12-24 + * added libzzipmmap.la with a simplified interface to zip archives + * added bins unzzipdir and unzzipcat to show usage of libzzipmmap.la + * introduce zzip/types.h to allow easier inclusion to zzip/mmapped.* + +2003-12-22 + * add AC_C_BIGENDIAN and + * move out ZZIP_GET to zzip/fetch.h where we also specify access + wrappers to items in the zzip/format.h structures, portably. + * add byteswap.h ac_check and put a new file autoconf.h to carry + compiletime overrides for the autoconf definitions. + * start changing over to use zzip/fetch.h definitions everywhere + thereby replacing original ZZIP_GET16/32 usages completely. + This is localized to zzip/zip.c + * rename struct zzip_root_dirent to struct zzip_disk_entry but + retain a compatibility declaration. + * introduce zzip_version_t and zzip_dostime_t along with an optional + ZZIP_NEED_PACKED def that helps with weird compiler struct packing + * struct zzip_file_trailer did not use the char[x] variant, it does now + * place even more zzip/fetch.h declarations + * place even more defs into zzip/format.h + * noting CVS area on webpages + +2003-12-21 + * Nigel Stewart hints on some MSVC 6 issues, thanks. + +2003-12-20 + * implant *Reset instead of Deinit/Init in zzip_rewind - the latter + is supposed to make for a memory leak (see problem report). + +2003-12-10 + * add zzip_rewind fix by glenn = Glenn Maynard (www.stepmania.com) + * fix dirsep_casecmp buglet noted by glenn + * glenn did ask for zzip_fstat, and here it is. + * but glenn's file_dup is not as easy and skipped here. + * otherwise, glenn noted that zziplib is not fully ready for multithreading, + the reason seems to be mostly in the reshared 32k buffer where the + access is not synchronized completely :-( ... effectivly, in MT + all ZZIP_FILE*s need to have a dedicated ZZIP_DIR*buffer. + * update make-doc.py with newest version + +2003-08-18 + * changing license to dual MPL / LGPL + * bumping version code 12.83 = 13.23 which are actually the very + same inside the code + * remove a few compatibility headers at install time. + * add install-exec-hook to add ln -s aliases for sharedlibs + they are being tried again in .spec but that does not + matter as long as it is "|| true" + * adapt all source to carry the MPL alternative license + instead of the old cruft. + * remove staticlinking.txt - it should be covered by copying.htm now + * remove "compats" disthook as well as the complete subdirectory + i.e. rm -r "zziplib/" at top directory (actually, I store it + in a distant place for now.) + * remove _htmpages.ar and _manpages.are from dist tarball + * add toplevel COPYING.LIB + * adapt README and TODO + * remove ac_output(zziplib and bins/zzip-config) + * remove bins/zzip-config.in + * adapt m4 macro and call zzip-config to be archaic + * remove maintainer-mode for "test.zip" + * turn zzip_plugin_io_t into a union reference, the old struct is + still of the same name but a member in there called "fd" + the typedef is no a "union _zzip_plugin_io" instead. + * the member "use_mmap" is renamed to "sys" - we add a #define + in plugin.h to let some software compile with all versions + * in zzip/zip.c, try now with making maplen and pagesize of type + zzip_ssize_t - as it was newly introduce it might help and + perhaps be a little conservative in execution. Before that, + we did use size_t and it was provoking warnings like + comparing/computing signed+unsigned pairs of values. + * add "type" and "write" members to zzip_plugin_io, keep it + backward compatible as much as possible. + * add _zzip_write to zzip/conf.h + * remove ZZIP_WRAPWRAP code in plugin.c + * remove --with-wrapwrap + * introduce a #define _zzip_plugin_io_handlers and + typedefs zzip_plugin_io_handlers and zzip_plugin_io_handlers_t + * oops toplevel PHONY does not work, an automake restriction + * oops, "cat body.htm" should be "cat $(srcdir)/body.htm" + * adding manpages.ar again, just to be sure + +2003-08-14 + * remove _not_implemend macro definitions for shallow-write api + from header zzip.h + * introduce symbol _ZZIP_WRITE_SOURCE that all files should + carry that want to have the declarations of the + shallow-write api + * use that symbol for zzip/write.c and bins/zzip.c + * adding docs/64on32.htm + +2003-08-14 + * for the shallow-write api to compile on win32, we need to + test for direct.h which only exists on win'sh system + or so we assume + * add bins/unzzip + * add bins/zzip + * ooops, zzip_strerror_of should check dir != 0 + +2003-08-13 + * complete zip-write API - no actual implementation so far + * tested shallow-write implementation on solaris+linux+win32 + * and now, call it zzip-12 always + +2003-08-12 + * `make docs` does not always work, so we add `make docu` now + * update make-doc.py + * fix call for make-doc.py + * fix zzip_get16 bad refer that gets detected by make-doc.py + + +2003-08-07 + * implement zzip/write to a degree that it forwards calls to real + files and directories in the system. No zip archives here, + but the accession API has been setup so that applications + can start to pick it up even for versions of zziplib that + have been compiled without zip archive support. + +2003-08-07 + * add doc lines in zzip/zzip.h + * add write-defines including flag-marker ZZIP_NO_CREAT + * add file write.c with empty definitions for write-support + * add the make-doc.py script in its last version - and make its output + the default master files for both html and docbook + * remove all other doc-maker scripts but make-doc.pl and make-doc.py + plus the make-dbk.pl of course + * twist configure.ac to set PYTHON instead of PHP + +2003-08-03 + * make compatibility-headers to issue a warning upon include + +2003-07-31 + * fix a segfault with corrupted central directory - just some checks + for field boundaries + * add a hack to support the fixup-rootdir thing with some simple(r) code + that abuses a few fields in the trailer-structure + * cvs checkout savannah.gnu.org:config into ../savannah.config and, + * add a rule `make configsub` in Makefile.mk to update the two files + uses/config.sub and uses/config.guess to the latest versions. + +2003-07-30 + * creating a 0.12.82 out of the source for 0.10.82 and make up a rpm + spec which does alias the .so files for these generations + +2003-07-29 + * the include of _LARGEFILE_SOURCE to do ZZIP_LARGEFILE_RENAME is + actually a bad idea - the respective symbol does not provoke + 64bit off_t on newer platforms. Only _LARGE_FILES seems to + be correct here for older aix platform to get them define + off_t = 64bit where others are using _FILE_OFFSET_BITS=64 now. + * after changes to README, remember to package updated test.zip !! + otherwise `make check` will fail. + * modify _msvc.sed to include "define ssize_t int" + * use ZZIP_EXPORTS instead of ZZIP_DLL for DLL export, that's the + automatic way of MSVC 6 saying that "zzip" is a DLL project. + * create new msvc6/zzip.dsp and delete msvc6/zziplib_DLL.dsp + * all examples shall import from zzip.dll by linking with zzip.lib + whereas that other zziplib.lib is just the static library + * do a looong and detailed information in README.MSVC6 + * create a rule to pack the *.dll,*.exe,*lib files into a zip + +2003-07-28 + * doc bug in zzip-zip reported by j.scrott.frank + * remind me: unzip from memory seems to be more of a task lately... + * forgot to modify RELASEINFO in rpm for zzip64 variant + * also do not just use -D_LARGEFILE_SOURCE, it does not have the + desired effect on all systems. Instead invent a new name + -D_ZZIP_LARGEFILE to make it happen magically. + * invent a rule to create zziplib64.pc from zziplib.pc for the + renamed libzzip.so -> libzzip64.so + * invent a rule to create zziplib64.la from zziplib.la for the + renamed libzzip.so -> libzzip64.so + * do also rename default libzzip.so to libzzip32.so and then create + a symlink to it under the old name libzzip.so + * create zziplib32.pc and zziplib32.la files accordingly. Following + an application may choose explicitly between 32 or 64bit off_t + version. This allows us to claim now that the default libzzip.so + library may be either of them and not anymore strict 32bit off_t + * aaahm, note that all of these account for rules in the linux rpm spec! + other system do not get this packaging support from vanilla tarfile + * well, better make it lib01 instead of lib0.10 for the rpm name + * already roll out visualc7.zip and msvc6 files in subdirectories, + do not ship them as .zip files + * already adapt msvc6 .dsp files but not yet tested + * rename main "rpm" target into "rpm2" to get rid of the warning message + * use (cd zzip64 && make install) instead of (... make install-ltLIBRARIES) + since otherwise we do not get any .pc file installed (oops) + * while modifying *.la into *64.la, take care to fixup reference to the + "old archive" *.a as well making it *64.a - same for *32.la file. + * some file.c reports there was not previous declaration of some of + its functions, but _only_ in 64bit compile step. + Reason: looks like a gcc 3.2.2 bug, no fix here. + * convert a few "ln -s" into "ln -s -f" in "make install" parts + * update README to point out staticlink model + in a separated LICENSE section. + +2003-07-28 + * add three extra gcc options: -Wpointer-arith, -Wsign-compare, and + -Wmissing-declarations which will help about portability to + platforms where that is enabled by default in -Wall + * sign-compare fix in, zzobfuscated (zzip_size_t -> zzip_ssize_t), + * make 5 functions in zzipwrap/wrap.c global=>to=>static + * add pre-delcare headers for 2 functions in zzip/zip.c + __zzip_find_disk_trailer(), __zzip_parse_root_directory() + * rewording of "ends/tail" in find-disk-trailer which does also find + a little bug (ends-1 or not) in there, It should not have shown any + practical problem so far, also corrected by anotgher little bug + in there (ends-tail > sizeof or ends-tail >= sizeof) + * adding a parts of a patch from Martin Schitter to harden zziplib + for corrupted zip files. + * remove a few duplicates in Makefile.mk, still need to keep "rpm" + * add declaration for zzip_dir_alloc_ext_io into zzip/lib.h + +2003-07-27 + * redefine size_t maplen -> off_t maplen and for each of the calls to + mmap()/munmap()/read()/getpagesize() we cast to size_t - this might + get us rid of a few warnings about signed/unsigned comparisons. + * introduce AC_TYPE_SIZE_T and use the prefixed variant _zzip_size_t + within plugin.h for io->read() calls. That makes for a little + bit of portability - it seems some platforms (dot-net f.e.) + do not `typedef unsigned int size_t;`, perhaps because int is 16bit + and a 32bit or even 64bit entitity is needed. + * now we do not need to AC_COMPILE_CHECK_SIZEOF(size_t) anymore, perhaps + even stand io-wrap is not needed anymore. Let's see. + * both changes need update of zzip/conf.h for _zzip_size_t plus + - plugin.h for io->read(,,size_t) + - zzip.h for zzip_file_read (,,size_t) + - zzip.h for zzip_read(,,size_t) + - zzip.h for zzip_fread(,size_t,size_t,) + - zzip.h for zzip_seek(,off_t,) + - zzip.h for zzip_tell(,off_t,) + - file.h int => size_t for zzip_file's restlen crestlen usize csize + * the io->seeks(,off_t,) has not been respected so far sometimes. + and like lseek(2), we define the returntype of zzip_seek as off_t + * introduce zzip_ssize_t as well, and modify + - zzip.h for zzip_read and zzip_fread and zzip_file_read + - plugin.h for io->read() return type + * dot-net bug in aligned4() - sizeof(long) < sizeof(void*) !! + better use off_t in the hope that it does fix it + * tested on ia32-linux, alpha64-linux, sparc32-solaris + * ooops, we need to update io-plugin examples and documentation as well, + since we define a custom _read() routine righ there. + +2003-07-26 + * updating to AX_SPEC_DEFAULTS macro + * zzshowme does not work with no libzzip installed in the system + * add automake option dist-bzip2 + * use tar.bz2 for rpm build + * add dist-bzip for the latter + * use zziplib-lib0.10 package which provides zziplib and libzzip0 + * forgot to add *.la files into the rpm devel package + * AC_SET_RELEASEINFO_VERSIONINFO => AX_SET_VERSION_INFO + * adjust all RELEASEINFO -> RELEASE_INFO accordingly + * and choose 0.10.82.pre1 as a vesion number for testing + which is possible now as the new macro does it right. + * forgot override of default_includes in test/*.am + * somehow ax_prefix gets the wrong input, i.e. _config.h instead of config.h + so we make that one explicit now + +2003-05-13 + * the off64_t mode renaming for 64on32 was done incorrectly and + it lead to problems on solaris8 - fix it. + * fixup `make check` to work on subdir build + +2003-05-11 + * adapt README file to clarify LICENSE details as suggested by + a discussion with ACE/TAO developers that want to use the + library for some compressed xml archives. + * fix a few zzip_char_t bugs that got visible in MSVC mode as + reported by Olge Ryabukha + * kill sfnet strand of the rpm build, the docs are installed + into the share/groups part and the omf file points to that + place. The index.html file is the one at sourceforge while + the other one is the entry point of the local documentation. + +2003-04-21 + * quite a few updates are need to --enable-builddir by default + * watch out: subdir build is the default now! + +2003-04-20 + * pick up AX_ENABLE_BUILDDIR + * throw out ac_subst CONFIG_ARGS + * use AX_SPEC_PACKAGE_VERSION + +2003-04-20 + * memory leak in zzip/file.c - adding free(dir->realname) zzip/zip.c + in function zzip_dir_close called via zzip_file_close + (bug reported by Olge Ryabukha, thanks!) + * "/" is hardcoded for finding subpaths but on windows that could be + a backslash as well. That should be handled better, we add some + alternative implementations for dirsep_strrchr and dirsep_casecmp + but the default is OFF!! even on WINDOWS !! + * thereby seen another problem: we did deliberatly use strcasecmp but + this symbol is not available on all unix systems - the manual + says its a BSD4.3 addition. Some other systems call it strcmpi + or stricmp instead, or they do not have it at all. Here we add + a configure rule to check for that symbol, and when we do not + have it then we _enable_ dirsep_casecmp automatically. + +2003-01-16 + * change extension of intermediate docbookfiles to ".xml" + * throw out attempts to compile docs with php + +2003-01-15 + * lots of doc updates in between. (forgot to document them). + * a zzip-config update, and installing an aclocal macro now. + +2003-01-06 + * defattr(root,root) !! - why that had been forgotten? hmmm... + * allowing for --disable-debug to clean cflags from -g entries + but it has not effect on callframe generation... actually. + +2003-01-05 + * we need to stop the manpages.ar bloat - now! + +2003-01-05 + * add largefile tests in configure.ac + * add largefile detection in zzip/conf.h + * add renamings for zzip_telldir/seekdir in zzip/zzip.h + * add extra exports in zzip/dir.c to have both 32bit and 64bit names exported + i.e. zzip_telldir _and_ zzip_telldir64 + * add renamings in zzip/plugin.h to ensure that 64bit-off_t-compiled zziplib + is not given io-callbacks being from another program that is actually + compiled as 32bit-off_t and where therefore arguments do not match. + * detected a dubious export of "aligned4()" - rename this export now. + * also rename everything having "_io" in the name - just to guard ourselves + from the case where two -lzzip are in the libpath and one is + compiled 64bit-off_t while the other is not. + * rename the younger function s/zzip_open_shared/zzip_open_shared_io/ + * make up functions for zzip_open_ext_io and zzip_opendir_ext_io for the + case of 32/64bit dual systems where lib is compiled in largefile mode. + Let the call succeed unless an "io" structure was given - return + the EOVERFLOW errno as specified in the large.file WG documents. + * make all parallel defines for 32/64 bit dual off_t dependent on + defined EOVERFLOW and defined PIC - i.e. only for dynamic linkage. + * adding LARGEFILE_CFLAGS into zziplib.pc and bins/zzip-config.in + * NOTE: the default for --with-largefile is still OFF !! + * NOTE: our zzip_readdir is not depenent on off_t size + * adding -64 into the --release info for the sharedlibrary build + it should have been a --variant but such does not exist so far + in libtool, sorry. + * extract AC_SYS_LARGEFILE_SENSITIVE and put it into an extra ac-macro + * clean zzip/file.h from compatibility-install as zzip-file.h + the structure in there contains zzip_off_t items and they + should be internal always anyway - so disallow access for + old programs now just to be sure. + * adding zzip64 compilation into zziplib.spec - an rpm package will now + install both 32bit off_t and 64bit off_t variants of the sharedlib + * note: we do not copy 64bit zzcat into the rpm, perhaps we should? + +2002-12-31 + * add make check-sfx + * add zzipself.c and zzipsetstub.c for the sfx test + * zzip_file_open takes o_modes flags, clarify in zzip.h + +2002-12-27 + * adding scrollkeeper omf file generation in docs/ + * adding omf file installation in docs/make-install-doc + * replace %post-doc message in zziplib.spec with scrollkeeper-update call. + * need *.pc *.omf in CLEANFILES now + * mingw32 crossgcc tests for win32 dirent emulation - did need some fixing + +2002-12-23 + * adding generation/installation of pkgconfig files + * making SDL a build-requirement for rpm packaging + +2002-12-22 + * add compatibility subdirectory "zziplib" + * zzipback.sed to create zziplib/* files from current release files + * include into distribution tarball + * IMPORTANT: flashback - 12.24 is now called 10.74 - + the old source line will cease to exist, only the compatibility + directory will survive a while - that should put some pressure + on developers to update to the new source tree. And it saves me + some work to keep two trees in sync. + +2002-12-20 + * fix some problems of make-doc.pl with the current project + * make a standard inlude info referring to zziplib.h as well + * unpack htmpages.ar on SFNET and register it on the frontpage + * dont forget to modify includes of internal headers + * ... + * fixed an annoying bug in make-doc.pl + * include htmpages.ar into the tarball + +2002-12-19 Guido Drhaeim + * completed new directory structure - the library is called 0.12.22 as + to match 0.10.72, it's the same C source in its content + * install-headers modified - the new structure is now compatible both + as a shared libary (binary compatible) and for the include headers + too - source compatible not only for function names but also for + the #include lines + * 0.12.23 fixes a bug in make doc: the xmlto html was never done. + * and we implant make-doc.pl which was founded on the base of the local + zzip-doc.pl but has since gone a lot further. It's currently just + a third variant but it is now used as the primary master default. + +2002-12-18 Guido Draheim + * man page update for zzip_open_shared (it turns out to be a good name). + * let frontpage point to http://www.gzip.org/zlib for primary zlib site. + +2002-12-17 Guido Draheim + * introduce zzip_open_file that may have an extra argument of a factory + file to share the zzip internal directory if that is possible. + * introduce zzip_freopen to take an extra argument. The supplied handle + is freed unless of course one puts ZZIP_FACTORY into o_modes so + that it becomes a wrapper around zzip_open_file + * the zzip_open_file, in that case, is the old zzip_open_ext_io call + but extended with checking the factory stream for a matching + basename. + * while being there: introduce ZZIP_ALLOWREAL o_mode that will make it + that a real file is open/read/close with the standard posixish + routines. This is most useful when having an obfuscated zip + file around but during development one wants to sometimes check + with a real file - so the call mode is something in the middle + of ZZIP_ALLOWREAL - ZZIP_PREFERZIP|ZZIP_ALLOWREAL - ZZIP_ONLYZIP + where the middle is for "yet another file not yet included", + hmm, perhaps a cheat file? ;-)=) + * cleaning rwops example: fix the mode check, it's not needful to start + with "r" to be a readfile mode, it may be somewhere in between. + * introduced __zzip_dir_parse as a cut off from zzip_dir_fdopen_ext_io, + but it did turn out to be not necessary, so it is made static in + the end. Still, it works as documenting the control flow better. + +2002-12-17 Guido Draheim + * win32 mmap removing extra braces + * win32 dirent implementation added - new file __dirent.h + and modified zzip-dir.c + * a couple of arg[n] -> argv[argn] cleanups. + * a missing argc > 1 check added. + * all changes due tests / bug reports by Thomas-dot-Eder-at-nmi-AT + +2002-12-16 Guido Draheim + * the infozip `zip` tool puts out messages per default on some machines + fix by adding >/dev/null in some places of Makefile.am + * the hpux10.20 platform has sys/mman.h but no MAP_FAILED + the `man mmap` says it returnes "-1" as done on all other unix + compatible platforms, so we add a default define ((void*)(-1)) + * update TODO file with some hints on test runs. + * add --with-zlib configure call to make it easier to specify a path + * make zlib error messages to point to this configure option. + * beautify error output on all other options as well. + * create `make brute` to make a bruteforce test + * solaris8 make has a problem with $< ... change sometimes into $? + * freebsd/darwin have 64bit off_t by default - and that reveals a problem + in the zzip_telldir/zzip_seekdir code. Let's change the code to make + it return/receive a byte-offset of "dir->hdr" to "dir->hdr0". + This makes printing of those values also more intelligible (if ever). + * ia64-linux reveals a problem in "default_io" since size_t is 64bit. + We modify --with-wrapwrap to autodetect this case. This is okay + since zip-files can not get bigger than 32bit offsets anyway. + +2002-12-16 Guido Draheim + * merging corrected README.SDL and __hints.h + courtesy of Thomas-dot-Eder-at-nmi-AT + * update CFLAGS ac-macros to the new generation as shipped with + latest ac-archive-0.5.39 (did upload just yesterday...) + +2002-12-14 Guido Draheim + * many hours of debugging - I don't remember which flaw came in through + the latest changes or which others were there before *sigh* + * e.g. the error-code mappings were refined on linux errno codes + * fix "caseless" bugs reported by Thomas-dot-Eder-at-nmi-AT + * fix MSVC related flaw when taking a casted value as an lvalue + * replace AC_CREATE_PREFIX_CONFIG_H with new style AX_PREFIX_CONFIG_H + * invent zzip-msvc.sed to turn config.h.in into zzip-msvc.in and + finalize a fresh zzip-msvc.h via AX_PREFIX_CONFIG_H + +2002-12-13 Guido Draheim + * shown by Mike Nordell tamlin-at-algonet-SE we can support win32 mmap + * modify configure.ac : if have:winbase.h then auto -enable-mmap + * refactor mmap'ing - it goes into __mmap.h and uses the io->use_mmap value + and that include file contains both posix and win32 mmap variants + * rewrite pagesize/mapoff calculations - this should be faster in itself + and also easier to maintain in the future for being more obvious. + * rewrite read/write defines and wrapwrap's. The zzip-conf.h does now + contain defines for _zzip_read/_zzip_lseek - and it should us get + rid of the nasty win32 problems with redefining _read/read + * refactor DBG defines - put them into __debug.h - oops, xbuf() was + an exported symbol, better be not. Use only newer NOTE/WARN macros! + * implant __hints.h include - that's taken from another project but it + is so damn useful ;-) + +2002-12-12 Guido Draheim + * modifizied zzip-zip.c to include a sanity check on getpagesize () + for mmap () functionality and ZZIP_BUFSIZ (the default is good). + * modify configure.ac : const char strings + * modify configure.ac : strict prototypes + * modify configure.ac : all warnings + * ... and so it reveals something missed along ;-) + +2002-08-27 Guido Draheim + * modified zzip-stdint.h along the example patch for FreeBSD done + by wjpalentstijn at sourceforge in projet uwadv. + +2002-07-24 Guido Draheim + * did teach myself php over converting zzip-doc.pl into zzip-doc.php + * added php-test and another way to create the docbook file, with php + +2002-07-20 Guido Draheim + * lots of fixes around docbook/manpage - and generate a zziplib.3 + overview page. Fixes also lots of comments in the sources. + * modified fopen-mode interpration nicely. + * added zzip-api for full overview of the zzip's API + +2002-07-19 Guido Draheim + * greatly enhanced docbook/manpage generation - including to attach + author and license info from the respective source file header + +2002-07-18 Guido Draheim + * extended the perlscript to generate zziplib.docbook + * use xmlto to generated manpages.ar + * install-man3 target and push into rpm-devel package + +2002-07-17 Guido Draheim + * no new code, just doc updates. The perl-script is now capable to + combine _ext_io functions with their non-ext/io cousin, and the + sources have been modified to honour this new mode. + * the perl-script is now ready to spit out other data like docbook + files that we can generate man-pages from later. + +2002-07-16 Guido Draheim + * extern-C in SDL_rwops_zzip.h ... and ifdef'able DECLSPEC for staticlinking + * zzip_fopen allows to greatly simplify SDL_rwops_zzip.c + * zzxordir.c zzxorcat.c zzxorcopy.c invented + * lots of new documentation added + zzip-extio.html zzip-xor.html zzip-refs.html + * new checks that test the zzxor examples + * and found an zzxor bug in the course + +2002-07-15 Guido Draheim + * Michael-dot-Fink-at-asamnet-dot-de did some code review while + going after a specialty he wanted to do with the libs, and therefore.. + * PREFERZIP did never test real file - stupid bug, inverted logic.... + * add ZIPONLY zzipmode - we have plenty of options availabe... on 32bit + platforms however, since I want to keep with the access-bits in + the lower parts. + +2002-07-12 Guido Draheim + * watcom-c-10.5 project file added + * used my old watcom compiler to debug the win32 problems, and it turned + out to be a mismatch in proccall for zlib - while the default in + zlib.h inferred WINAPI, it turned out that zlib114dll.zip had in + fact been compiled with __syscall procframe callmethod. Duh!!! + * some things had to be rearranged in header files - most classically it + seems that this compiler does not support __inline in C mode. + +2002-07-11 Guido Draheim + * convert all API const types into those with _zzip_const and use new + types like zzip_char_t and zzip_strings_t throughout the sources. + * add ZZIP_RDONLY and friends. Do not use fcntl bits anymore, and limit + use routines to convert them into O_DEFs later one in the next + version of this lib - here we just declare them to be their O_DEFs + but code should start to pick up ZZIP_DEFs in the meantime. + * add zzip_fopen and friends as another type of magic wrappers. + * modify open_ext_io to use receive separate arguments for the two + zzip extraflags - use these from now on, the others are just + for limited backward compatibility. + * modify all _close functions to return "int". + +2002-07-10 Guido Draheim + * Marlin Prowell mbp-at-cadalog-inc-dot-com did hit a problem on FreeBSD + showing off a config problem - the configure.ac macro for off_t is + written to be _undefined_ if off_t existed in the system. Instead we + chose to defined zzip_off_t into a "long" as it is needed on win32, + and since FreeBSD on LFP32 uses OFF64 it did fall flat on calls to + lseek - without io-wrap the gcc did cast them correctly, so it worked. + * the fix: use off_t if zzip_off_t undefined. Add a define zzip_off_t into + long in conf-msvc.h. Add a configure-option to have wrappers for the + default lowlevel calls as suggested by Marlin but I choose to have + them off by default - a bsd ports package may start using it. + * there have not been reported problems in the last three months where only + developers knew about the new version. Guess it's time to push this + tarball and announce it on freshmeat. + +2002-04-30 Guido Draheim + * fix typo in zzip-zip.c: __USE_MMAP -> _USE_MMAP + * if zlib.h not found, make it a fatal exit + +2002-04-25 Guido Draheim + * adding a few more `make check` rules for bigger zip files + * add even negative tests + * add some spaces in error-messaging in zzdir.c and let return + an exitcode when some argument files could not be read + +2002-04-24 Guido Draheim + * apply patch from Mike Nordell + changes all "const char * *" into the intended "const char * const *" + changes some typecasts + corrects comment and adds some + and two fixes + * put the updated MSVC6 files into the project, again Mike Nordell + * me, add new zzwrap.dsp to DIST in Makefile.am, following Mike's addition + * me, modify some typecasts to use off_t/size_t where apropriate + * modified COPYING.ZZIP to be a bit more general than just for ZZIPLIB + as noted by Tomi Olilla + * zzipwrap demo_callback, how can we do void* and char* at the same time... + +2002-04-23 Guido Draheim + * changed ssize_t into int in zzipwrap-mem for portability reasons + * fix zzip_dir_fdopen_ext for access to uninitialized io-vtable + (thanks to Lutz Sammer johns98-at-web-dot-de for testing) + +2002-04-22 Guido Draheim + * add MSVC6 project files contributed by Mike Nordell tamlin-at-algonet-dot-SE + * add plugin_io-patch from Mike Nordell + and dump the iowrap-patch from Andreas Shiffler from earlier release + * append the Mike Nordell's zzobfuscated.c to Makefile.am + * add a new file COPYING for new less-strictly license + after Tomi Ollila has transferred full copyright to me + * remove Tomi Ollila from all copyright entries in the sources + but honour his name where apropriate + * modify LGPL hints in sources and point to COPYING.ZZIP as well + and change copyright year info + * create COPYING.ZZIP with some general LGPL exceptions. + * use newer AC_CREATE_CONFIG_H macro and start using acinclude.m4 + to allow retooling of the project. + * and use zzip_off_t instead of ZZIP_off_t (but keep backward compatibility) + * apply patch for the problem detected and corrected by + Steve Dillon steved-at-phone-IVR-dot-com + * try with an updated ac_create_prefix_config_h due to a bug report by + John W. O'Brien john-at-jugglers-dot.com + where his shell-and-echo combination did interpret \\1 twice. + * add use_mmap flag to plugin_io_t, so the feature can be used + along USE_MMAP configured setups + * change USE_MMAP #ifdefs to use if()s and to rely on the + compiler to do code removal for unreachable code + * remove tell() part of plugin_io and rename seek()-indirection + to seeks()-indirection using a tells()-macro in zzip-file + * also rename s/seek/seeks/ in zzip-zip and kill the (*function)(x) + for the indirection functions into just function(x)-calls + * fix zzobfuscated example code - there's no read() without unistd.h + in unix, and global zzip_install_io had been removed lately. + * add zzipwrap-io.c and zzipwrap.c from Andreas Schiffler's patch + on the new ground of Mike Nordell's plugin_io + * modify zzipwrap sources to work with plugin-io + * add io pointer to dir-structure, and use it as the default for file-structs + * __zzip_open_zip is called __zzip_try_open now and takes two arguments + * typedef struct zzip_plugin_io * zzip_plugin_io_t; + * zzip_opendir_ext_io .. for magic convenience + * create new zzipwrap.la in Makefile.am + * move plugin_io struct from zziplib.h to zzip-io.h + along with its helper functions + * change all filesize into zzip_off_t + * s/zzip_find_disk_trailer/__zzip_find_disk_trailer/ (additional io arg) + * s/zzip_parse_root_directory/__zzip_parse_root_directory/ (ditto) + +2001-10-11 Guido Draheim + * added zzipwrap feature contributed by Andreas Schiffler + +2001-09-18 Guido Draheim + * fix bug for `zzip-config --cflags` + which did print /xx/include instead of -I/xx/include + (thanks to Roger Ostrander ) + * change the for-loop in zzip-config - the "for i ; do" is not portable + because I had problems on solaris-sh. Use "$@" which expands + to a list (!!) of argv entries for this for-loop even for + arguments that contain spaces. fascinating. + * use AC_HELP_STRING ... the `configure --help` screen got a bit + misformatted lately. + * add a `make check` rule. + +2001-08-19 Guido Draheim + * add that /programs magic to the $prefix check in configure.ac + * add that /usr/share magic to the $prefix check in configure.ac + * fix zzip-sdl-rwops.html layout (and copying.zlib link). + * fix some flaws in sdl-rwops example source (just by code review). + * add unistd.h include to zziptest.c to silence off the warning about sleep + * add non-dll compile to extern in zzip-conf.h - does that fix anything? + +2001-08-18 Guido Draheim + * SDL_rwops_zzip.c/SDL_rwops_zzip.h SDL-example file. + * change all filename args to be const + * add ZZIP_const to zzip-conf.h, but do not use it for now. + It seems that all current lib-users have a modern compiler... + +2001-08-16 Guido Draheim + * export zzip_dir_free / zzip_dir_alloc + * bring in fileext field to check for multiple fileextensions. + * make zzip_open check for multiple (default) fileextensions. + * add ifdef USE_ZZIPLIKES to implement feature proposed by + Julien Cayzac + * make zzip_open check along the dirpath for a zip-file + a feature proposed by Lutz Sammer + +2001-08-15 Guido Draheim + * add "stroustrup" style to all c files to ensure that casual + developers do not trash the layout unintentionally. + * modify examples a bit with more newlines / comments. + * re-license examples to ZLIB license + * include COPYING.ZLIB into doc_FILES + +2001-08-10 Guido Draheim + * change frontpage of webpages - including a few crosslinks to + other projects + +2001-08-07 Guido Draheim + * split version X.Y.Z into -relese X -version-info Y:Z + * adding --disable-thread-safe, and add -thread-safe linkage by default + * modify releaseinfo for with-debug + * install-zip target to make a windows package + * change serial to _vendor - rpm has never been used for other than linux + +2001-08-06 Guido Draheim + * reorganize docs, update docs to new style + * split version X.Y.Z into -release X.Y -version-info Z + +2001-08-05 Guido Draheim + * add zzip-msvc.h, a header file that will be included when + a windows compiler is detected in zzip-conf.h, e.g. + _MSC_VER or __BORLANDC__ + * mv index.html zzip-index.html and add makerule that patches + the VERSION in before installing it as index.html + * add a makerule to build sourceforge htdocs and add it + to the rpm build. + * add generic patches for libtool into configure.ac + +2001-07-18 Guido Draheim + * check up bugs in automake 1.4beef, now using a rule to + override AUTO* in non-maintainer-mode. we also set + libtool to silent in non-maintainer-mode + * docs are installed to $datadir/doc/$package as default + * rpms can now be built. + * create --with-docdir and let it be filled in rpm-configure + so that docs will end up where rpmopt says it should. + * ChangeLog goes into %doc of rpms. + * uhmm, forgot to install the test*.c files into the docdir + * the bin rpms had not been built + * compress into base and devel package + * errnolist should be static + +2001-07-17 Guido Draheim + * nuke Makerule system, use plain autotools style including + configure && make install to rebuild + * update Makefile.am (which is new now) + * use next-generation autotools as a basis, update configure.ac + to newer style, update configscreen at the end of file + * check perl in configure and let it default to "echo" + * check HAVE_ defines coming from config.h - it is not anymore + included by zzip-config.h, so each config-def usage + must now use the prefix'd version + * provide a zziplib.spec file + +2001-01-05 Guido Draheim + * apply zzip_seek-patch from Ted [sourceforge.net/users/tam4] + * -> 0.10.12 + +2001-01-02 Guido Draheim + * gone through a couple of trial and error versions until + I finally arrived at a mingw32msvc zzip.dll - basically + I had to update the included libtool files to 1.3.5 + and the zzip.dll source-files have a ZZIP_DLL define + before the first include that points to zzip-conf.h - + and there is the magic about dllexport and dllimport. + Hopefully the same can run under MSVC without further + changes to the sources. + * try to package a zip-file that contains the relevant files + from the mingw32msvc install, so that windows user + get a clean dll without the need to compile it. + * -> 0.10.11 + +2001-01-01 Guido Draheim + * received a patch for MSVC compatibility from Ted A. (@lehigh.edu) + which made me to look after the project again. There + were two support requrest during summer that asked for + MSVC support, especially a prebuilt dll and headers. + * added AC_PREFIX_CONFIG_H that I made originally for + another project. It enables me to push the configure + detections into a global include/-dir. Ted's patch + used an `IFDEF MSVC DEFINE HAVE_SYS_TYPES_H` which + is a symptom of using config.h&HAVE_CONFIG_H and + zzip-file.h&IFDEF HAVE_xx. Change all header-IFDEF-HAVE + to use IFDEF-ZZIP_HAVE, and install zzip-config.h + along with the other headers, change the original + include"config.h" in zzip-stdint.h and make it rely + on zzip-conf.h - where zzip-conf.h includes zzip-config.h + and lists the detected features to be used, along with most + important extra defs for MSVC compatibility. (!!!) + * added AC_COMPILE_CHECK_SIZEOF (cross-compile clean!) + to always use the correct STDINT defines. Delete + use of glib.h if present, it's not needed anymore. + * use ZZIP_off_t instead of off_t + * prepare for a MSVC' ZZIP.DLL with _zzip_export defines.. + -DZZIP_DLL -> declspec(dllexport) + -DHAVE_LIBZZIP -> declspec(dllimport) + * make sure, __attribute__ is okay with non-gcc compilers + and attache packed-attribute to *all* zipformat-structs. The + whole of zzipformat.h is also enclosed in pack-pragmas. + * -> 0.10.7 + * create zzip-config.in and install it. + * mingw32msvc has shown that we need -lz on the command-line + to resolve a few symbols + * go automake + * install zzip-config along + * mingw32msvc does not build with cross-make.sh as seen on + http://libsdl.org/Xmingw32 - it needs the cross-tool/lib + just as well. There we have LDLIBADD in Makefile.mk now. + Now everything works for making win32 target with cross-tools. + * The rest of the make-struture should ensure to be able to + create an MSVC nmake Makefile - the Makerule.am is clean and + can be directly included... hopefully. + * -> 0.10.8 + + +2000-06-03 Guido Draheim + * Tomi did a final test round for solaris, oh well, + configure needs some fixes... + * checking for myself at the university's solaris2.6 with + gcc-2.95.2, hmm... there's an sys/int_types.h that + seems to define some of C9X int-types, put it into + the configure.in and know about it in zzip-stdint.h + (btw, glibc seems to have include/inttypes.h that + includes stdint.h). + * tomi did report a problem with gcc 2.7.2... probably + sth. about -rpath + * release 0.10.6 and going to announce it... + +2000-05-31 Guido Draheim + * created the main doc html files, index.html, zzip-zip.html + and zzip-file.html. the README and README.API is deleted, + and the TODO is a bit updated. + * This version is meant to be announced very soon now. + * release 0.10.5 and contact Tomi for his final nod. + +2000-05-31 Guido Draheim + * ifdef HAVE_SYS_STAT_H where stat is used. Removed + the stats from zzip-file.h - it will now just try + to open the file or zip-file and assume that + open(2) will fail if the file is not there. I do + hereby assume that the returned fd is seekable.. + * two new functions, zzip_dir_real and zzip_file_real + to check if the ZZIP_XX structures are wrapping a + real file or directory. Otherwise it is a zip-archive + or a zip-contained file respectivly. + * zzip_compr_str does now know about stat-types and + will return names for S_ISTYPE bits. + * remove zzip_fd. It was identical to zzip_dirfd + whose name is consistent with dirent.h + * zzip_stat -> zzip_dir_stat since it does not neither + return a stat structure nor does it use stat(2) + * Checking the doc-comments + +2000-05-30 Guido Draheim + * zzip_fp -> zzip_file and _fp_ functions to _file_ + * zzip-stdint.h to ensure iso c9x typedefs + * ZZIP_GET16/32 macros in zzip.h header. + * minor updates in cosmetics and documentation + * have full replacements for dirent.h functions, + the zip-specific functions are now called + zip_dir_open (and more alike). The zzdir can + now show a list of files in a real directory, + or magically the files contained in a zip-arch. + * release 0.10.4 + +2000-05-29 Guido Draheim + * zzipmain -> zziptest and some cleanups + in the Makefile. zziptest is now just + another test program, so it gets compiled + in full similarity with zzcat and zzdir. + * removed zziptest from install-bin + * the long forgotten simplicistic dependency + rule is now in here too. + * cosmetics to pointer declar' stars in + zziplib.h + * ZZIP_FP -> ZZIP_FILE and + zzip-fp.h -> zzip-file.h + * removed the use of zzip.h where suggested + by Tomi. (use public zziplib.h instead) + * removed errno.h from zziplib.h + * printing configuration at end of configure. + * add install-includeHEADERS rule, so that + zziplib.h does now get installed. + + +2000-05-27 Guido Draheim + * zzipformat.h carries information about the + zip-file structure. The typedefs are now + used to access members of the zip-archive + (instead of using the offsets directly). + * notice that the members are declared + bytewise due to compiler semantics that is + making a structure packed&aligned to the + greatest common size (which would be 4). + setting as attribute(packed) is not very + portable. + * reworked the files, esp. zzip-zip.c and + zzip-ar.c + * _USE_MMAP in autoconf, including option + and CFLAGS setting. instead of open/read + to a scan buffer the zip-file is mmapped + and scanned directly. + * _LOWSTK in autoconf, including option and + a CFLAGS setting. Still need a scan buffer + and this flag tells us not to carve the + scan buffer from the auto-stack and use + instead some malloc for the scan buffer. + * DEBUG in autoconf, including option and + a CFLAGS setting. The macros should now + be able to be found everyone and only. + * revamped EDH find routine, dumped old-style. + * revamped read-EDH to use mmap and to use + copy/read only for the parts we need. The + read-EDH buffer is not limited to 32K + anymore and can have any length. No realloc + need anymore. + * opendir does not allocate the cache.buf32k + anymore - it does have no need for it. the + buffer is still cached for subsequent Open + calls. May want to setvbuf later. + * a few renamings to be more bits/dirent.h-like, + so many things are now called d_name and + d_reclen instead of name or next as before. + * renamed the package to "zziplib" as being + suggested by Tomi. + * release 0.10.3 + +2000-05-26 Guido Draheim + * -release at link-line for the lib + * zzcat.c as a test program, which uncovered + a few flaws. + * a flaw w/_fd_opendir when being given a + non-inited err-return-variable and no + error did occur. + * the error to errno table was incomplete, + and the ZZIP_INFLATE error is superfluous. + * zzdir.c as a test program, needs still to + be given the full zip-arch name. + * changed member names of zzip_dirent to + match similar names in dirent and stat, + (ie. d_name and st_size) and added furthermore + a z_size that returns the compressed size. + * little updates to names and comments. + * release 0.10.2 + +2000-05-22 Guido Draheim + * merge with zip08x-0.9.6 - actually just + a bugfix for zzip_fp_open IGNOREPATH - + I even applied it in a different way than + Tomi did. + * bugfixes for zzip_open, it did not always + set errno(2) to the value of zzip_errno. + * The zzip_read is now seperate from + zzip_fp_read, so that setting errno(2) is + only done in zzip_read, not in the zzip-touching + function. + * zzip-doc.pl to generate libzzip.html + * release 0.10.1 + +2000-05-21 Guido Draheim + * drop-in replacements ready for daily use, + just use zzip_open with a normal path to + a fs file. If that file is not found in + a normal fs directory, then the path is + splitted into a basepath and a filename, + a ".zip" is appended to the basepath to + form a zip-arch name, and the filename + is then searched inside the zip-arch if + that one exists. Very nice for distribution + of a subdirectory full of scripts and that + is what it is meant for - the PFE will be + able to use this one for Forth-files. + * have a VERSION file containing "0.10.0" and + add some rules to Mk-rules + * start with in-source docs that will be used + for documenting the lib calls. A jdoc like + doc extractor should be able to grok these, + I'll see to release docs with the next + release, but this time... + * make it release 0.10.0 and upload it to + pfe.sourceforge.net/pub where it will lurk + around until I contacted Tomi. He seems to + be currently working on zip08x + +2000-05-17 Guido Draheim + * decided to have it actually called zzip_ and so + all of the stuff is going to get renamed again. + +2000-05-16 Guido Draheim + * obtained Tomi's code and made changes so that the + resulting library is more portable, esp. the glib + usage is being abolished. The name of the library + (and package) has been renamed to libunzip and + all types, consts and funcs to now carry the unzip_ + prefix. + * autoconf !!!! + * drop-in functions that can be made to easily replace + dirent and filefd functions. + + +Mon Apr 5 11:23:46 2000 Tomi Ollila (too@iki.fi) + + * Release 0.9.5 + + * Made some tiny modifications after Matthew's code. + +Sun Apr 4 8:30:00 2000 Matthew D. Campbell (matt@campbellhome.dhs.org) + + * Cleaned up compile warnings in SuSE Linux + + * Cleaned up code for cross-compilation with Xmingw32 + + * Modified zipx.h to support linking to C++ apps + +Wed Jul 28 11:23:46 1999 Tomi Ollila (too@iki.fi) + + * Release 0.9.4 + + * Fixed support for simultaneous open files with each + open `ZipFile'. + +Thu Jul 22 11:57:46 1999 Tomi Ollila (too@iki.fi) + + * Release 0.9.3 + + * Added premilinary README.API. + +Sat Jul 10 11:49:58 1999 Tomi Ollila (too@iki.fi) + + * Release 0.9.2 + + * Fixed code to read start-of-file offset from local header + instead relying directory info is sufficient (were TOO naive + about that, the first user reported this library won't work + with his archives). + +Sun Jun 13 20:40:11 1999 Tomi Ollila (too@iki.fi) + + * Initial release (0.9.1). diff --git a/project/jni/zzip/README b/project/jni/zzip/README new file mode 100644 index 000000000..5668eda04 --- /dev/null +++ b/project/jni/zzip/README @@ -0,0 +1,47 @@ +PROJECT + The zziplib provides read access to zipped files in a zip-archive, + using compression based solely on free algorithms provided by zlib. + It also provides a functionality to overlay the archive filesystem + with the filesystem of the operating system environment. + +AUTHOR + The project was originally written by Tomi Ollila, later largely + rewritten by Guido Draheim, and extended with contributions in + the years to follow. Guido Draheim holds the full + copyright to the zziplib sources. + +COPYING + The zziplib may be used freely under the restrictions of the + GNU Lesser General Public License version 2 or later. Alternativly + the Mozilla Public license can be chosen. The sources are under + a dual license, as long as the MPL hint is not removed, the modified + files will be again under a dual license for the final recipient. + +LICENSING + If you can not use a dynalinked library according to LGPL rules, + then look at docs/copying.htm for a few hints. Generally the LGPL + has a way for staticlinking as well as the MPL has a way. Anyway, + special (paid) licenses can be negotiated with the copyright holder. + +HOMEPAGE + The zziplib project is hosted at SourceForge, the complete + documentation can be found at http://zziplib.sf.net - the + SourceForge servers are also used to distribute the sources + of the zziplib project. Releases are announced via the + freshmeat services on http://freshmeat.net/projects/zziplib + +INSTALLATION + The zziplib sources are built with gnu autotools and they should + be easy to install on unixish systems via the usual sequence of + `configure && make && make check && make install`. Many distributors + ship prebuilt packages e.g. in rpm format. Additionally there are + MSVC project files shipped along for usage with the Microsoft + VisualC series of compilers. There should be no problem either + when crosscompiling the zziplib for a third host platform. + +MAINTAINANCE + The zziplib library is intentionally a lightweight interface to + zip files. The author take patches but please consider to put + complex extensions into separate modules rather than implanting them + right into the core of the library engine. All Patches and Bug Reports + should be sent to Guido Draheim . diff --git a/project/jni/zzip/TODO b/project/jni/zzip/TODO new file mode 100644 index 000000000..1a408e4a1 --- /dev/null +++ b/project/jni/zzip/TODO @@ -0,0 +1,107 @@ +SHORTTERM +- handle international filenames more gracefully (unicode API?) +- most is multithreaded ... but zzip_dir_open (Thorsten Schöning) +- rboerdijk@ does also report errors on overlapping reads, another + one pointed to the usage of seek_set that may cause the problems + +WISHLIST + +- Check the CRC value at the end of read... and add more error codes. + +- Do more test. Currently use only with tested "friendly" archives. + This is also related to usages of zziplib in virus detection + code which should better have a hardened library code. That does + also include inflate interface code to need the most testing. + +- the buffer reusage code was not strictly multithreading. It should + be fixed by now but it would be better to have an automatic test + routine to check reentrancy/multithreaded functionality. + +- Sligthly More documentation. With the generation of man pages and + multiple pages for the website, it does already look acceptable. + It should still get better of course - kinda newbie friendly *g* + +- Boris Schäling likes to open a zzip archive in memory. + +KNOWN PROBLEMS + +The win32 compilers need each a different config.h derivate that +matches both the headers shipped with the compiler and installed +with updates of the SDK. There is no autoconfigure on win32 as +that - unless you install some unix tools along. + +The sparc-sun-solaris2.* will utter warnings for "char subscript" +which is caused by isdigit() from ctype.h - this will NOT FIX as +it is only in the example source code and we want to keep those +lean and mean to make them easy to adopt by developers. + +The hppa1.1-hp-hpux10.20 did show spurious problems of making +shared libraries - this may well fix with an update of the +libtool package, the libtool 1.4 is dated 2001/04/24 + +There are reports of misaligned access to some zip fields that +I would guess to be on little-endian non-x86 platforms. The current +bytewise access of multibyte fields is targetted towards the +bigendian unix machines. The fix would need to go to fetch.h but +so far no response came about as that one could test a solution. + +There are spurious reports of users on win32 platforms that tell +of some problems with a specific zip file they have but it was +not possible so far to recreate an environment abroad to show +the problem too. One can not say if that is due some general +instability out of DLL hell, or if there is a bug hiding somewhere. +Please send all those zip files to the maintainer, perhaps it +can help to find the real cause (I doubt it is in zziplib, but..) + +Since lately the xml docbook tools have hardened the checks on the +input xml that is used for manpage generation. Interestingly the +resulting manpages are still okay but one should try to fixaway the +warnings as may be later the result would lead to garbage output +due more changes in the tools. Needs to change the xml generator +used in zzip (a python script). + +TESTED PLATFORMS +sparc-sun-solaris2.6/gcc2.95.3 +sparc-sun-solaris2.8/gcc2.95.3 +hppa1.1-hp-hpux10.20 +i686-mandrake-linux-9.0/gcc3.2 +i686-mandrake-linux-9.1/gcc3.2.2 +i686-debian-linux-2.2/gcc2.95.2 +i386-unknown-freebsd4.7/gcc2.95.4 (formerly with wrapwrap) +powerpc-apple-darwin5.5 (formerly with wrapwrap) +alphaev67-unknown-linux-gnu/gcc2.95.4 (that's a 64bit platform) +i386-ms-win32/msvc6 +i386-ms-win32/msvc7 +i386-ms-win32/mingw+msys +... and probably a lot of others not known to the maintainer. + +Additionally, note that Sourceforge has discontinued their compilefarm +server laboratory. That makes it unlikely that proper support for +crossplatform functionality can be provided. Expect a compile problem +here or there - the code however should be prepared to get around any +problems easily. Send patches! (especially Linux distributions makers +are usually not sending their patches to upstream maintainers). + +Note: the latest cross platform tests are done indirectly by using +the build.opensuse.org rpm packaging where one can run "make check" +just before doing the "make install" of the compiled library. + + +SUSE BUILDSERVER INFO + +I: A function overflows or underflows an array access. This could be a real error, +but occasionaly this condition is also misdetected due to loop unrolling or strange pointer +handling. So this is warning only, please review. +W: zziplib arraysubscript ../../zzip/memdisk.c:114 + +I: File is compiled without RPM_OPT_FLAGS +W: zziplib no-rpm-opt-flags :../../SDL/SDL_rwops_zzcat.c, ../../SDL/SDL_rwops_zzip.c + +I: Program is likely to break with new gcc. Try -fno-strict-aliasing. +W: zziplib strict-aliasing-punning ../../zzip/file.c:275 +W: zziplib strict-aliasing-punning ../../zzip/fseeko.c:99, 126, 147, 158, 182, 281, 288, 301, 360, 539, 543, 546, 563 +W: zziplib strict-aliasing-punning ../../zzip/memdisk.c:181, 182, 183, 185, 186, 187, 188, 189, 192, 193, 194, 195, 247, 455, 456 +W: zziplib strict-aliasing-punning ../../zzip/mmapped.c:277, 289, 311, 314, 339, 340, 393, 397, 410, 438, 440, 443, 444, 549, 551, 552, 558, 559, 561 +W: zziplib strict-aliasing-punning ../../zzip/zip.c:318, 320, 321, 322, 339, 341, 342, 343, 484, 485, 486, 497, 498, 499, 500, 501 +E: zziplib 64bit-portability-issue ../../zzip/memdisk.c:112 +System halted. diff --git a/project/jni/zzip/include/zzip/SDL_rwops_zzip.h b/project/jni/zzip/include/zzip/SDL_rwops_zzip.h new file mode 100644 index 000000000..1a2d188de --- /dev/null +++ b/project/jni/zzip/include/zzip/SDL_rwops_zzip.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2001 Guido Draheim + * Use freely under the restrictions of the ZLIB License + * + * You should be able to drop it in the place of a SDL_RWFromFile. Then + * go to X/share/myapp and do `cd graphics && zip -9r ../graphics.zip .` + * and rename the graphics/ subfolder - and still all your files + * are found: a filepath like X/shared/graphics/game/greetings.bmp + * will open X/shared/graphics.zip and return the zipped file + * game/greetings.bmp in the zip-archive (for reading that is). + * + */ + +#ifndef _SDL_RWops_ZZIP_h +#define _SDL_RWops_ZZIP_h + +#include + +#ifndef ZZIP_NO_DECLSPEC +#define ZZIP_DECLSPEC +#else /* use DECLSPEC from SDL/begin_code.h */ +#define ZZIP_DECLSPEC DECLSPEC +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +extern ZZIP_DECLSPEC +SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode); + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/__debug.h b/project/jni/zzip/include/zzip/__debug.h new file mode 100644 index 000000000..13c7d8954 --- /dev/null +++ b/project/jni/zzip/include/zzip/__debug.h @@ -0,0 +1,89 @@ +#ifndef __ZZIP_INTERNAL_DEBUG_H +#define __ZZIP_INTERNAL_DEBUG_H + +#include +#include + +/* perhaps want to show on syslog(3) ?? */ + +#ifdef DEBUG +#include +#define DBG1(X1) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ); } ZZIP_END1 +#define DBG2(X1,X2) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ,X2);} ZZIP_END1 +#define DBG3(X1,X2,X3) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ,X2,X3); } ZZIP_END1 +#define DBG4(X1,X2,X3,X4) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ,X2,X3,X4); } ZZIP_END1 +#define DBG5(X1,X2,X3,X4,X5) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ,X2,X3,X4,X5); } ZZIP_END1 +#define DBG6(X1,X2,X3,X4,X5,X6) ZZIP_FOR1 { \ + fprintf(stderr,"\n%s:%i:"X1"\n", ZZIP_FUNC,__LINE__ \ + ,X2,X3,X4,X5,X6); } ZZIP_END1 + +#else +#define DBG1(X1) {} +#define DBG2(X1,X2) {} +#define DBG3(X1,X2,X3) {} +#define DBG4(X1,X2,X3,X4) {} +#define DBG5(X1,X2,X3,X4,X5) {} +#define DBG6(X1,X2,X3,X4,X5,X6) {} +#endif + +#define HINT1(X1) DBG1("HINT: " X1) +#define HINT2(X1,X2) DBG2("HINT: " X1,X2) +#define HINT3(X1,X2,X3) DBG3("HINT: " X1,X2,X3) +#define HINT4(X1,X2,X3,X4) DBG4("HINT: " X1,X2,X3,X4) +#define HINT5(X1,X2,X3,X4,X5) DBG5("HINT: " X1,X2,X3,X4,X5) +#define HINT6(X1,X2,X3,X4,X5,X6) DBG6("HINT: " X1,X2,X3,X4,X5,X6) + +#define NOTE1(X1) DBG1("NOTE: " X1) +#define NOTE2(X1,X2) DBG2("NOTE: " X1,X2) +#define NOTE3(X1,X2,X3) DBG3("NOTE: " X1,X2,X3) +#define NOTE4(X1,X2,X3,X4) DBG4("NOTE: " X1,X2,X3,X4) +#define NOTE5(X1,X2,X3,X4,X5) DBG5("NOTE: " X1,X2,X3,X4,X5) +#define NOTE6(X1,X2,X3,X4,X5,X6) DBG6("NOTE: " X1,X2,X3,X4,X5,X6) + +#define WARN1(X1) DBG1("WARN: " X1) +#define WARN2(X1,X2) DBG2("WARN: " X1,X2) +#define WARN3(X1,X2,X3) DBG3("WARN: " X1,X2,X3) +#define WARN4(X1,X2,X3,X4) DBG4("WARN: " X1,X2,X3,X4) +#define WARN5(X1,X2,X3,X4,X5) DBG5("WARN: " X1,X2,X3,X4,X5) +#define WARN6(X1,X2,X3,X4,X5,X6) DBG6("WARN: " X1,X2,X3,X4,X5,X6) + +#define FAIL1(X1) DBG1("FAIL: " X1) +#define FAIL2(X1,X2) DBG2("FAIL: " X1,X2) +#define FAIL3(X1,X2,X3) DBG3("FAIL: " X1,X2,X3) +#define FAIL4(X1,X2,X3,X4) DBG4("FAIL: " X1,X2,X3,X4) +#define FAIL5(X1,X2,X3,X4,X5) DBG5("FAIL: " X1,X2,X3,X4,X5) +#define FAIL6(X1,X2,X3,X4,X5,X6) DBG6("FAIL: " X1,X2,X3,X4,X5,X6) + + + +#ifdef DEBUG +_zzip_inline static void zzip_debug_xbuf (unsigned char* p, int l) + /* ZZIP_GNUC_UNUSED */ +{ +# define q(a) ((a&0x7F)<32?32:(a&0x7F)) + while (l > 0) + { + fprintf (stderr, + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%c%c%c%c %c%c%c%c\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], + q(p[0]), q(p[1]), q(p[2]), q(p[3]), + q(p[4]), q(p[5]), q(p[6]), q(p[7])); + p += 8; l -= 8; + } +# undef q +} +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/__dirent.h b/project/jni/zzip/include/zzip/__dirent.h new file mode 100644 index 000000000..ba53ed3f0 --- /dev/null +++ b/project/jni/zzip/include/zzip/__dirent.h @@ -0,0 +1,395 @@ +#ifndef ZZIP_INTERNAL_DIRENT_H +#define ZZIP_INTERNAL_DIRENT_H +#include + +/* + * DO NOT USE THIS CODE. + * + * It is an internal header file for zziplib that carries some inline + * functions (or just static members) and a few defines, simply to be + * able to reuse these across - and have everything in a specific place. + * + * Copyright (c) 2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifdef ZZIP_HAVE_DIRENT_H +#define USE_DIRENT 1 + +#define _zzip_opendir opendir +#define _zzip_readdir readdir +#define _zzip_closedir closedir +#define _zzip_rewinddir rewinddir +#ifndef ANDROID +#define _zzip_telldir telldir +#define _zzip_seekdir seekdir +#endif +#define _zzip_DIR DIR + +#include + +#elif defined ZZIP_HAVE_WINBASE_H +#define USE_DIRENT 2 + +#define _zzip_opendir win32_opendir +#define _zzip_readdir win32_readdir +#define _zzip_closedir win32_closedir +#define _zzip_rewinddir win32_rewinddir +#define _zzip_telldir win32_telldir +#define _zzip_seekdir win32_seekdir +#define _zzip_DIR DIR + +/* + * DIRENT.H (formerly DIRLIB.H) + * + * by M. J. Weinstein Released to public domain 1-Jan-89 + * + * Because I have heard that this feature (opendir, readdir, closedir) + * it so useful for programmers coming from UNIX or attempting to port + * UNIX code, and because it is reasonably light weight, I have included + * it in the Mingw32 package. I have also added an implementation of + * rewinddir, seekdir and telldir. + * - Colin Peters + * + * This code is distributed in the hope that is will be useful but + * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAMED. This includeds but is not limited to warranties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#include + +struct dirent +{ + long d_ino; /* Always zero. */ + unsigned short d_reclen; /* Always zero. */ + unsigned short d_namlen; /* Length of name in d_name. */ + char* d_name; /* File name. */ + /* NOTE: The name in the dirent structure points to the name in the + * finddata_t structure in the DIR. */ +}; + +/* + * This is an internal data structure. Good programmers will not use it + * except as an argument to one of the functions below. + */ +typedef struct +{ + /* disk transfer area for this dir */ + struct _finddata_t dd_dta; + + /* dirent struct to return from dir (NOTE: this makes this thread + * safe as long as only one thread uses a particular DIR struct at + * a time) */ + struct dirent dd_dir; + + /* _findnext handle */ + long dd_handle; + + /* + * Status of search: + * 0 = not started yet (next entry to read is first entry) + * -1 = off the end + * positive = 0 based index of next entry + */ + short dd_stat; + + /* given path for dir with search pattern (struct is extended) */ + char dd_name[1]; +} DIR; + +/* + * dirent.c + * + * Derived from DIRLIB.C by Matt J. Weinstein + * This note appears in the DIRLIB.H + * DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89 + * + * Updated by Jeremy Bettis + * Significantly revised and rewinddir, seekdir and telldir added by Colin + * Peters + */ + +#include +#include +#include +#include +#include +#include + +#define win32_SUFFIX "*" +#define win32_SLASH "\\" + +#ifndef S_ISDIR +#define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) /* is a directory */ +#endif S_ISDIR + + +/* + opendir + + Returns a pointer to a DIR structure appropriately filled in to begin + searching a directory. +*/ +static DIR* +win32_opendir (const char *szPath) +{ + DIR *nd; + struct _stat statDir; + + errno = 0; + + if (!szPath) { + errno = EFAULT; + return (DIR *) 0; + } + + if (szPath[0] == '\0') { + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Attempt to determine if the given path really is a directory. */ + if (_stat (szPath, &statDir)) { + /* Error, stat should have set an error value. */ + return (DIR *) 0; + } + + if (!S_ISDIR (statDir.st_mode)) { + /* Error, stat reports not a directory. */ + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Allocate enough space to store DIR structure and the complete * + directory path given. */ + nd = (DIR *) calloc (1, sizeof (DIR) + strlen (szPath) + + strlen (win32_SLASH) + strlen (win32_SUFFIX)); + + if (!nd) { + /* Error, out of memory. */ + errno = ENOMEM; + return (DIR *) 0; + } + + /* Create the search expression. */ + strcpy (nd->dd_name, szPath); + + /* Add on a slash if the path does not end with one. */ + if (nd->dd_name[0] != '\0' && + nd->dd_name[strlen (nd->dd_name) - 1] != '/' && + nd->dd_name[strlen (nd->dd_name) - 1] != '\\') { + strcat (nd->dd_name, win32_SLASH); + } + + /* Add on the search pattern */ + strcat (nd->dd_name, win32_SUFFIX); + + /* Initialize handle to -1 so that a premature closedir doesn't try * to + call _findclose on it. */ + nd->dd_handle = -1; + + /* Initialize the status. */ + nd->dd_stat = 0; + + /* Initialize the dirent structure. ino and reclen are invalid under * + Win32, and name simply points at the appropriate part of the * + findfirst_t structure. */ + nd->dd_dir.d_ino = 0; + nd->dd_dir.d_reclen = 0; + nd->dd_dir.d_namlen = 0; + nd->dd_dir.d_name = nd->dd_dta.name; + + return nd; +} + +/* + readdir + + Return a pointer to a dirent structure filled with the information on the + next entry in the directory. +*/ +static struct dirent * +win32_readdir (DIR * dirp) +{ + errno = 0; + + /* Check for valid DIR struct. */ + if (!dirp) { + errno = EFAULT; + return (struct dirent *) 0; + } + + if (dirp->dd_dir.d_name != dirp->dd_dta.name) { + /* The structure does not seem to be set up correctly. */ + errno = EINVAL; + return (struct dirent *) 0; + } + + if (dirp->dd_stat < 0) { + /* We have already returned all files in the directory * (or the + structure has an invalid dd_stat). */ + return (struct dirent *) 0; + } else if (dirp->dd_stat == 0) { + /* We haven't started the search yet. */ + /* Start the search */ + dirp->dd_handle = _findfirst (dirp->dd_name, &(dirp->dd_dta)); + + if (dirp->dd_handle == -1) { + /* Whoops! Seems there are no files in that * directory. */ + dirp->dd_stat = -1; + } else { + dirp->dd_stat = 1; + } + } else { + /* Get the next search entry. */ + if (_findnext (dirp->dd_handle, &(dirp->dd_dta))) { + /* We are off the end or otherwise error. */ + _findclose (dirp->dd_handle); + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } else { + /* Update the status to indicate the correct * number. */ + dirp->dd_stat++; + } + } + + if (dirp->dd_stat > 0) { + /* Successfully got an entry. Everything about the file is * already + appropriately filled in except the length of the * file name. */ + dirp->dd_dir.d_namlen = (unsigned short) strlen (dirp->dd_dir.d_name); + return &dirp->dd_dir; + } + + return (struct dirent *) 0; +} + +/* + closedir + + Frees up resources allocated by opendir. +*/ +static int +win32_closedir (DIR * dirp) +{ + int rc; + + errno = 0; + rc = 0; + + if (!dirp) { + errno = EFAULT; + return -1; + } + + if (dirp->dd_handle != -1) { + rc = _findclose (dirp->dd_handle); + } + + /* Delete the dir structure. */ + free (dirp); + + return rc; +} + +/* + rewinddir + + Return to the beginning of the directory "stream". We simply call findclose + and then reset things like an opendir. +*/ +static void +win32_rewinddir (DIR * dirp) +{ + errno = 0; + + if (!dirp) { + errno = EFAULT; + return; + } + + if (dirp->dd_handle != -1) { + _findclose (dirp->dd_handle); + } + + dirp->dd_handle = -1; + dirp->dd_stat = 0; +} + +/* + telldir + + Returns the "position" in the "directory stream" which can be used with + seekdir to go back to an old entry. We simply return the value in stat. +*/ +static long +win32_telldir (DIR * dirp) +{ + errno = 0; + + if (!dirp) { + errno = EFAULT; + return -1; + } + return dirp->dd_stat; +} + +/* + seekdir + + Seek to an entry previously returned by telldir. We rewind the directory + and call readdir repeatedly until either dd_stat is the position number + or -1 (off the end). This is not perfect, in that the directory may + have changed while we weren't looking. But that is probably the case with + any such system. +*/ +static void +win32_seekdir (DIR * dirp, long lPos) +{ + errno = 0; + + if (!dirp) { + errno = EFAULT; + return; + } + + if (lPos < -1) { + /* Seeking to an invalid position. */ + errno = EINVAL; + return; + } else if (lPos == -1) { + /* Seek past end. */ + if (dirp->dd_handle != -1) { + _findclose (dirp->dd_handle); + } + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } else { + /* Rewind and read forward to the appropriate index. */ + win32_rewinddir (dirp); + + while ((dirp->dd_stat < lPos) && win32_readdir (dirp)); + } +} + +#else +#define USE_DIRENT 0 + +#define _zzip_opendir(_N_) 0 +#define _zzip_readdir(_D_) 0 +#define _zzip_closedir(_D_) /* omit return code */ +#define _zzip_rewinddir(_D_) +#define _zzip_telldir(_D_) 0 +#define _zzip_seekdir(_D_,_V_) /* omit return code */ +#define _zzip_DIR void* + +/* end of DIRENT implementation */ +#endif + +/* once */ +#endif diff --git a/project/jni/zzip/include/zzip/__fnmatch.h b/project/jni/zzip/include/zzip/__fnmatch.h new file mode 100644 index 000000000..55d96b6d1 --- /dev/null +++ b/project/jni/zzip/include/zzip/__fnmatch.h @@ -0,0 +1,29 @@ +#ifndef __ZZIP_INTERNAL_FNMATCH_H +#define __ZZIP_INTERNAL_FNMATCH_H +/** included by fseeko.c, mmapped.c, memdisk.c */ + +#include +#include + +#ifdef ZZIP_HAVE_FNMATCH_H +#include +#endif + +#ifdef ZZIP_HAVE_FNMATCH_H +#define _zzip_fnmatch fnmatch +# ifdef FNM_CASEFOLD +# define _zzip_fnmatch_CASEFOLD FNM_CASEFOLD +# else +# define _zzip_fnmatch_CASEFOLD 0 +# endif +#else +# define _zzip_fnmatch_CASEFOLD 0 +/* if your system does not have fnmatch, we fall back to strcmp: */ +static int _zzip_fnmatch(char* pattern, char* string, int flags) +{ + fprintf (stderr, ""); + return strcmp (pattern, string); +} +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/__hints.h b/project/jni/zzip/include/zzip/__hints.h new file mode 100644 index 000000000..d071c4ebd --- /dev/null +++ b/project/jni/zzip/include/zzip/__hints.h @@ -0,0 +1,195 @@ +#ifndef __ZZIP_INTERNAL_HINTS_H +#define __ZZIP_INTERNAL_HINTS_H +#include + +#ifndef ZZIP_GNUC_ATLEAST +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define ZZIP_GNUC_ATLEAST(_M_,_N_) \ + ((__GNUC__ << 10) + __GNUC_MINOR__ >= ((_M_) << 10) + (_N_)) +# elif defined __GNUC__ +# define ZZIP_GNUC_ATLEAST(_M_,_N_) \ + ((__GNUC__ << 10) >= ((_M_) << 10)) +# else +# define ZZIP_GNUC_ATLEAST(_M_, _N_) 0 +# endif +#endif + +#ifndef ZZIP_GNUC_EXTENSION +# if ZZIP_GNUC_ATLEAST(2,8) +# define ZZIP_GNUC_EXTENSION __extension__ +# else +# define ZZIP_GNUC_EXTENSION +# endif +#endif + +/* func has no side effects, return value depends only on params and globals */ +#ifndef ZZIP_GNUC_PURE +# if ZZIP_GNUC_ATLEAST(2,8) +# define ZZIP_GNUC_PURE __attribute__((__pure__)) +# else +# define ZZIP_GNUC_PURE +# endif +#endif + +/* func has no side effects, return value depends only on params */ +#ifndef ZZIP_GNUC_CONST +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_CONST __attribute__((__const__)) +# else +# define ZZIP_GNUC_CONST +# endif +#endif + +/* typename / variable / function possibly unused */ +#ifndef ZZIP_GNUC_UNUSED +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_UNUSED __attribute__((__unused__)) +# else +# define ZZIP_GNUC_UNUSED +# endif +#endif + +/* obvious. btw, a noreturn-func should return void */ +#ifndef ZZIP_GNUC_NORETURN +# if ZZIP_GNUC_ATLEAST(2,5) +# define ZZIP_GNUC_NORETURN __attribute__((__noreturn__)) +# else +# define ZZIP_GNUC_NORETURN +# endif +#endif + +/* omit function from profiling with -finstrument-functions */ +#ifndef ZZIP_GNUC_NO_INSTRUMENT +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_NO_INSTRUMENT __attribute__((__no_instrument_function__)) +# else +# define ZZIP_GNUC_NO_INSTRUMENT +# endif +#endif + +/* all pointer args must not be null, and allow optimiztons based on the fact*/ +#ifndef ZZIP_GNUC_NONNULL +# if ZZIP_GNUC_ATLEAST(3,1) +# define ZZIP_GNUC_NONNULL __attribute__((nonnull)) +# else +# define ZZIP_GNUC_NONNULL +# endif +#endif + +/* the function can not throw - the libc function are usually nothrow */ +#ifndef ZZIP_GNUC_NOTHROW +# if ZZIP_GNUC_ATLEAST(3,2) +# define ZZIP_GNUC_NOTHROW __attribute__((nothrow)) +# else +# define ZZIP_GNUC_NOTHROW +# endif +#endif + +/* typename / function / variable is obsolete but still listed in headers */ +#ifndef ZZIP_GNUC_DEPRECATED +# if ZZIP_GNUC_ATLEAST(3,1) +# define ZZIP_GNUC_DEPRECATED __attribute__((deprecated)) +# else +# define ZZIP_GNUC_DEPRECATED +# endif +#endif + +/* resolve references to this function during pre-linking the libary */ +#ifndef ZZIP_GNUC_LIB_PROTECTED +# if ZZIP_GNUC_ATLEAST(3,1) +# define ZZIP_GNUC_LIB_PROTECTED __attribute__((visiblity("protected"))) +# else +# define ZZIP_GNUC_LIB_PROTECTED +# endif +#endif + +/* func shall only be usable within the same lib (so, no entry in lib symtab)*/ +#ifndef ZZIP_GNUC_LIB_PRIVATE +# if ZZIP_GNUC_ATLEAST(3,1) +# define ZZIP_GNUC_LIB_PRIVATE __attribute__((visiblity("hidden"))) +# else +# define ZZIP_GNUC_LIB_PRIVATE +# endif +#endif + +/* ... and not even passed as a function pointer reference to outside the lib*/ +#ifndef ZZIP_GNUC_LIB_INTERNAL +# if ZZIP_GNUC_ATLEAST(3,1) +# define ZZIP_GNUC_LIB_INTERNAL __attribute__((visiblity("internal"))) +# else +# define ZZIP_GNUC_LIB_INTERNAL +# endif +#endif + + +#ifndef ZZIP_GNUC_FORMAT +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_FORMAT(_X_) __attribute__((__format_arg__(_X_))) +# else +# define ZZIP_GNUC_FORMAT(_X_) +# endif +#endif + +#ifndef ZZIP_GNUC_SCANF +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_SCANF(_S_,_X_) __attribute__((__scanf__(_S_,_X_))) +# else +# define ZZIP_GNUC_SCANF(_S_,_X_) +# endif +#endif + +#ifndef ZZIP_GNUC_PRINTF +# if ZZIP_GNUC_ATLEAST(2,4) +# define ZZIP_GNUC_PRINTF(_S_,_X_) __attribute__((__printf__(_S_,_X_))) +# else +# define ZZIP_GNUC_PRINTF(_S_,_X_) +# endif +#endif + +#ifdef __GNUC__ +#define ZZIP_GNUC_PACKED __attribute__((packed)) +#else +#define ZZIP_GNUC_PACKED +#endif + +#ifndef ZZIP_FUNCTION +# if ZZIP_GNUC_ATLEAST(2,6) +# define ZZIP_FUNC __FUNCTION__ +# define ZZIP_FUNCTION __FUNCTION__ +# elif defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +# define ZZIP_FUNC __func__ +# define ZZIP_FUNCTION "" +# else +# define ZZIP_FUNC 0 +# define ZZIP_FUNCTION "" +# endif +#endif + +#ifndef ZZIP_STRING +#define ZZIP_STRING(_X_) ZZIP_STRING_(_X_) +#define ZZIP_STRING_(_Y_) #_Y_ +#endif + +#ifndef ZZIP_DIM +#define ZZIP_DIM(_A_) (sizeof(_A_) / sizeof ((_A_)[0])) +#endif + +#if !(defined ZZIP_FOR1 && defined ZZIP_END1) +# if defined sun || defined __sun__ +# define ZZIP_FOR1 if (1) +# define ZZIP_END1 else (void)0 +# else +# define ZZIP_FOR1 do +# define ZZIP_END1 while (0) +# endif +#endif + +#ifndef ZZIP_BRANCH_OVER +# if ZZIP_GNUC_ATLEAST(2,96) +# define ZZIP_BRANCH_OVER(_X_) __builtin_expect((_X_),0) +# else +# define ZZIP_BRANCH_OVER(_X_) (_X_) +# endif +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/__mmap.h b/project/jni/zzip/include/zzip/__mmap.h new file mode 100644 index 000000000..d70419dcb --- /dev/null +++ b/project/jni/zzip/include/zzip/__mmap.h @@ -0,0 +1,107 @@ +#ifndef __ZZIP_INTERNAL_MMAP_H +#define __ZZIP_INTERNAL_MMAP_H +#include + +/* + * DO NOT USE THIS CODE. + * + * It is an internal header file for zziplib that carries some inline + * functions (or just static members) and a few defines, simply to be + * able to reuse these across - and have everything in a specific place. + * + * Copyright (c) 2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifdef _USE_MMAP +#if defined ZZIP_HAVE_SYS_MMAN_H +#include +#define USE_POSIX_MMAP 1 +#elif defined ZZIP_HAVE_WINBASE_H || defined WIN32 +#include +#define USE_WIN32_MMAP 1 +#else +#undef _USE_MMAP +#endif +#endif + +/* -------------- specify MMAP function imports --------------------------- */ + +#if defined USE_POSIX_MMAP +#define USE_MMAP 1 + +#define _zzip_mmap(user, fd, offs, len) \ + mmap (0, len, PROT_READ, MAP_SHARED, fd, offs) +#define _zzip_munmap(user, ptr, len) \ + munmap (ptr, len) +#define _zzip_getpagesize(user) getpagesize() + +#ifndef MAP_FAILED /* hpux10.20 does not have it */ +#define MAP_FAILED ((void*)(-1)) +#endif + +#elif defined USE_WIN32_MMAP +#define USE_MMAP 1 +#ifndef MAP_FAILED +#define MAP_FAILED 0 +#endif +/* we (ab)use the "*user" variable to store the FileMapping handle */ + /* which assumes (sizeof(long) == sizeof(HANDLE)) */ + +static size_t win32_getpagesize (void) +{ + SYSTEM_INFO si; GetSystemInfo (&si); + return si.dwAllocationGranularity; +} +static void* win32_mmap (long* user, int fd, zzip_off_t offs, size_t len) +{ + if (! user || *user != 1) /* || offs % getpagesize() */ + return 0; + { + HANDLE hFile = (HANDLE)_get_osfhandle(fd); + if (hFile) + *user = (int) CreateFileMapping (hFile, 0, PAGE_READONLY, 0, 0, NULL); + if (*user) + { + char* p = 0; + p = MapViewOfFile(*(HANDLE*)user, FILE_MAP_READ, 0, offs, len); + if (p) return p + offs; + CloseHandle (*(HANDLE*)user); *user = 1; + } + return MAP_FAILED; + } +} +static void win32_munmap (long* user, char* fd_map, size_t len) +{ + UnmapViewOfFile (fd_map); + CloseHandle (*(HANDLE*)user); *user = 1; +} + +#define _zzip_mmap(user, fd, offs, len) \ + win32_mmap ((long*) &(user), fd, offs, len) +#define _zzip_munmap(user, ptr, len) \ + win32_munmap ((long*) &(user), ptr, len) +#define _zzip_getpagesize(user) win32_getpagesize() + +#else /* disable */ +#define USE_MMAP 0 +/* USE_MAP is intentional: we expect the compiler to do some "code removal" + * on any source code enclosed in if (USE_MMAP) {...} i.e. the unreachable + * branch of an if (0) {....} is not emitted to the final object binary. */ + +#ifndef MAP_FAILED +#define MAP_FAILED 0 +#endif + +#define _zzip_mmap(user, fd, offs, len) (MAP_FAILED) +#define _zzip_munmap(user, ptr, len) {} +#define _zzip_getpagesize(user) 1 + +#endif /* USE_MMAP defines */ + + +#endif diff --git a/project/jni/zzip/include/zzip/_config.h b/project/jni/zzip/include/zzip/_config.h new file mode 100644 index 000000000..1c16128f3 --- /dev/null +++ b/project/jni/zzip/include/zzip/_config.h @@ -0,0 +1,252 @@ +#ifndef _ZZIP__CONFIG_H +#define _ZZIP__CONFIG_H 1 + +/* zzip/_config.h. Generated automatically at end of configure. */ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Define if pointers to integers require aligned access */ +#define HAVE_ALIGNED_ACCESS_REQUIRED 1 + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_BYTESWAP_H +#define ZZIP_HAVE_BYTESWAP_H 1 +#endif + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DIRECT_H */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#ifndef ZZIP_HAVE_DIRENT_H +#define ZZIP_HAVE_DIRENT_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_DLFCN_H +#define ZZIP_HAVE_DLFCN_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_FNMATCH_H +#define ZZIP_HAVE_FNMATCH_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_INTTYPES_H +#define ZZIP_HAVE_INTTYPES_H 1 +#endif + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IO_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_MEMORY_H +#define ZZIP_HAVE_MEMORY_H 1 +#endif + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STDINT_H +#define ZZIP_HAVE_STDINT_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STDLIB_H +#define ZZIP_HAVE_STDLIB_H 1 +#endif + +/* Define to 1 if you have the `strcasecmp' function. */ +#ifndef ZZIP_HAVE_STRCASECMP +#define ZZIP_HAVE_STRCASECMP 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STRINGS_H +#define ZZIP_HAVE_STRINGS_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STRING_H +#define ZZIP_HAVE_STRING_H 1 +#endif + +/* Define to 1 if you have the `strndup' function. */ +#ifndef ZZIP_HAVE_STRNDUP +#define ZZIP_HAVE_STRNDUP 1 +#endif + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INT_TYPES_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_MMAN_H +#define ZZIP_HAVE_SYS_MMAN_H 1 +#endif + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_PARAM_H +#define ZZIP_HAVE_SYS_PARAM_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_STAT_H +#define ZZIP_HAVE_SYS_STAT_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_TYPES_H +#define ZZIP_HAVE_SYS_TYPES_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_UNISTD_H +#define ZZIP_HAVE_UNISTD_H 1 +#endif + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINBASE_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINNT_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_ZLIB_H +#define ZZIP_HAVE_ZLIB_H 1 +#endif + +/* whether the system defaults to 32bit off_t but can do 64bit when requested + */ +/* #undef LARGEFILE_SENSITIVE */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#ifndef ZZIP_LT_OBJDIR +#define ZZIP_LT_OBJDIR ".libs/" +#endif + +/* Name of package */ +#ifndef ZZIP_PACKAGE +#define ZZIP_PACKAGE "zziplib" +#endif + +/* Define to the address where bug reports for this package should be sent. */ +#ifndef ZZIP_PACKAGE_BUGREPORT +#define ZZIP_PACKAGE_BUGREPORT "" +#endif + +/* Define to the full name of this package. */ +#ifndef ZZIP_PACKAGE_NAME +#define ZZIP_PACKAGE_NAME "" +#endif + +/* Define to the full name and version of this package. */ +#ifndef ZZIP_PACKAGE_STRING +#define ZZIP_PACKAGE_STRING "" +#endif + +/* Define to the one symbol short name of this package. */ +#ifndef ZZIP_PACKAGE_TARNAME +#define ZZIP_PACKAGE_TARNAME "" +#endif + +/* Define to the version of this package. */ +#ifndef ZZIP_PACKAGE_VERSION +#define ZZIP_PACKAGE_VERSION "" +#endif + +/* The number of bytes in type int */ +#ifndef ZZIP_SIZEOF_INT +#define ZZIP_SIZEOF_INT 4 +#endif + +/* The number of bytes in type long */ +#ifndef ZZIP_SIZEOF_LONG +#define ZZIP_SIZEOF_LONG 8 +#endif + +/* The number of bytes in type short */ +#ifndef ZZIP_SIZEOF_SHORT +#define ZZIP_SIZEOF_SHORT 2 +#endif + +/* Define to 1 if you have the ANSI C header files. */ +#ifndef ZZIP_STDC_HEADERS +#define ZZIP_STDC_HEADERS 1 +#endif + +/* Version number of package */ +#ifndef ZZIP_VERSION +#define ZZIP_VERSION "0.13.59" +#endif + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to `long long' if does not define. */ +#ifndef ZZIP___int64 +#define ZZIP___int64 long long +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `_zzip_off_t' if does not define. */ +#ifndef _zzip_off64_t +#define _zzip_off64_t _zzip_off_t +#endif + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to equivalent of C99 restrict keyword, or to nothing if this is not + supported. Do not define if restrict is supported directly. */ +#ifndef _zzip_restrict +#define _zzip_restrict __restrict__ +#endif + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define to `int' if does not define. */ +/* #undef ssize_t */ + +/* once: _ZZIP__CONFIG_H */ +#endif diff --git a/project/jni/zzip/include/zzip/_msvc.h b/project/jni/zzip/include/zzip/_msvc.h new file mode 100644 index 000000000..5e109cb02 --- /dev/null +++ b/project/jni/zzip/include/zzip/_msvc.h @@ -0,0 +1,229 @@ +#ifndef _ZZIP__MSVC_H +#define _ZZIP__MSVC_H 1 + +/* zzip/_msvc.h. Generated automatically at end of configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Define if pointers to integers require aligned access */ +/* #undef HAVE_ALIGNED_ACCESS_REQUIRED */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_BYTESWAP_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_DIRECT_H +#define ZZIP_HAVE_DIRECT_H 1 +#endif + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_DIRENT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLFCN_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FNMATCH_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_INTTYPES_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_IO_H +#define ZZIP_HAVE_IO_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_MEMORY_H +#define ZZIP_HAVE_MEMORY_H 1 +#endif + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STDINT_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STDLIB_H +#define ZZIP_HAVE_STDLIB_H 1 +#endif + +/* Define to 1 if you have the `strcasecmp' function. */ +/* #undef HAVE_STRCASECMP */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STRINGS_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_STRING_H +#define ZZIP_HAVE_STRING_H 1 +#endif + +/* Define to 1 if you have the `strndup' function. */ +/* #undef HAVE_STRNDUP */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INT_TYPES_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MMAN_H */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PARAM_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_STAT_H +#define ZZIP_HAVE_SYS_STAT_H 1 +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_SYS_TYPES_H +#define ZZIP_HAVE_SYS_TYPES_H 1 +#endif + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UNISTD_H */ + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_WINBASE_H +#define ZZIP_HAVE_WINBASE_H 1 /* hmm, is that win32 ? */ +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_WINDOWS_H +#define ZZIP_HAVE_WINDOWS_H 1 /* yes, this is windows */ +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_WINNT_H +#define ZZIP_HAVE_WINNT_H 1 /* is that always true? */ +#endif + +/* Define to 1 if you have the header file. */ +#ifndef ZZIP_HAVE_ZLIB_H +#define ZZIP_HAVE_ZLIB_H 1 /* you do have it, right? */ +#endif + +/* whether the system defaults to 32bit off_t but can do 64bit when requested + */ +/* #undef LARGEFILE_SENSITIVE */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +/* #undef LT_OBJDIR */ + +/* Name of package */ +#ifndef ZZIP_PACKAGE +#define ZZIP_PACKAGE "zziplib-msvc" /* yes, make it known */ +#endif + +/* Define to the address where bug reports for this package should be sent. */ +/* #undef PACKAGE_BUGREPORT */ + +/* Define to the full name of this package. */ +/* #undef PACKAGE_NAME */ + +/* Define to the full name and version of this package. */ +/* #undef PACKAGE_STRING */ + +/* Define to the one symbol short name of this package. */ +/* #undef PACKAGE_TARNAME */ + +/* Define to the version of this package. */ +/* #undef PACKAGE_VERSION */ + +/* The number of bytes in type int */ +#ifndef ZZIP_SIZEOF_INT +#define ZZIP_SIZEOF_INT 4 +#endif + +/* The number of bytes in type long */ +#ifndef ZZIP_SIZEOF_LONG +#define ZZIP_SIZEOF_LONG 4 +#endif + +/* The number of bytes in type short */ +#ifndef ZZIP_SIZEOF_SHORT +#define ZZIP_SIZEOF_SHORT 2 +#endif + +/* Define to 1 if you have the ANSI C header files. */ +#ifndef ZZIP_STDC_HEADERS +#define ZZIP_STDC_HEADERS 1 +#endif + +/* Version number of package */ +#ifndef ZZIP_VERSION +#define ZZIP_VERSION "0.13.x" +#endif + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to `long long' if does not define. */ +/* #undef __int64 */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#ifndef _zzip_inline +#define _zzip_inline __inline +#endif +#endif + +/* Define to `_zzip_off_t' if does not define. */ +#ifndef _zzip_off64_t +#define _zzip_off64_t __int64 +#endif + +/* Define to `long int' if does not define. */ +#ifndef _zzip_off_t +#define _zzip_off_t long +#endif + +/* Define to equivalent of C99 restrict keyword, or to nothing if this is not + supported. Do not define if restrict is supported directly. */ +#ifndef _zzip_restrict +#define _zzip_restrict +#endif + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define to `int' if does not define. */ +#ifndef _zzip_ssize_t +#define _zzip_ssize_t int +#endif + +/* once: _ZZIP__MSVC_H */ +#endif diff --git a/project/jni/zzip/include/zzip/autoconf.h b/project/jni/zzip/include/zzip/autoconf.h new file mode 100644 index 000000000..f0d684145 --- /dev/null +++ b/project/jni/zzip/include/zzip/autoconf.h @@ -0,0 +1,45 @@ +#ifndef _ZZIP_AUTOCONF_H_ +#define _ZZIP_AUTOCONF_H_ 1 + +/* + * This file is trying to override configure time checks of zzip with + * definitions at compile time. This is not used by zzip sources themselves + * but it may be really helpful with thirdparty software that happens to + * include zzip headers from a central place but running on a different host. + */ + +#include "conf.h" /* : */ + +#if defined HAVE_ENDIAN_H || defined ZZIP_HAVE_ENDIAN_H +#include /* glibc */ +#elif defined HAVE_SYS_PARAM_H || defined ZZIP_HAVE_SYS_PARAM_H +#include /* solaris */ +#endif + +#if defined __BYTE_ORDER +#define ZZIP_BYTE_ORDER __BYTE_ORDER +#elif defined BYTE_ORDER +#define ZZIP_BYTE_ORDER BYTE_ORDER +#elif defined _LITTLE_ENDIAN +#define ZZIP_BYTE_ORDER 1234 +#elif defined _BIG_ENDIAN +#define ZZIP_BYTE_ORDER 4321 +#elif defined __i386__ +#define ZZIP_BYTE_ORDER 1234 +#elif defined WORDS_BIGENDIAN || defined ZZIP_WORDS_BIGENDIAN +#define ZZIP_BYTE_ORDER 4321 +#else +#define ZZIP_BYTE_ORDER 1234 +#endif + +/* override ZZIP_WORDS_BIGENDIAN : macros ZZIP_GET16 / ZZIP_GET32 */ +#ifdef ZZIP_BYTE_ORDER+0 == 1234 +#undef ZZIP_WORDS_BIGENDIAN +#endif +#ifdef ZZIP_BYTE_ORDER+0 == 4321 +#ifndef ZZIP_WORDS_BIGENDIAN +#define ZZIP_WORDS_BIGENDIAN 1 +#endif +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/conf.h b/project/jni/zzip/include/zzip/conf.h new file mode 100644 index 000000000..52b33e287 --- /dev/null +++ b/project/jni/zzip/include/zzip/conf.h @@ -0,0 +1,264 @@ +/* + * Here we postprocess autoconf generated prefix-config.h entries. + * This is generally for things like "off_t" which is left undefined + * in plain config.h if the host system does already have it but we do + * need the prefix variant - so we add here a #define _zzip_off_t off_t + * + * This file is supposed to only carry '#define's. + * See for definitions that might be seen by the compiler. + * + * Author: + * Guido Draheim + * + * Copyright (c) 2001,2002,2003,2004 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifndef _ZZIP_CONF_H +#define _ZZIP_CONF_H 1 + +#if !defined ZZIP_OMIT_CONFIG_H +# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ +# include +# elif defined ZZIP_1_H +# include "zzip-1.h" +# elif defined ZZIP_2_H +# include "zzip-2.h" +# elif defined ZZIP_3_H +# include "zzip-3.h" +# elif defined ZZIP_4_H +# include "zzip-4.h" +# elif defined ZZIP_5_H +# include "zzip-5.h" +# else /* autoconf generated */ +# include +# endif +#endif + +/* especially win32 platforms do not declare off_t so far - see zzip-msvc.h */ +#ifndef _zzip_off_t +#ifdef ZZIP_off_t +#define _zzip_off_t ZZIP_off_t +#else +#define _zzip_off_t off_t +#endif +#endif + +#ifndef _zzip_off64_t +#ifdef ZZIP_off64_t +#define _zzip_off64_t ZZIP_off64_t +#else +#define _zzip_off64_t off64_t +#endif +#endif + +/* currently unused, all current zziplib-users do have ansi-C94 compilers. */ +#ifndef _zzip_const +#ifdef ZZIP_const +#define _zzip_const ZZIP_const +#else +#define _zzip_const const +#endif +#endif +#ifndef _zzip_inline +#ifdef ZZIP_inline +#define _zzip_inline ZZIP_inline +#else +#define _zzip_inline inline +#endif +#endif +#ifndef _zzip_restrict +#ifdef ZZIP_restrict +#define _zzip_restrict ZZIP_restrict +#else +#define _zzip_restrict restrict +#endif +#endif +#if defined __linux__ && __GNUC__+0 >= 4 +#define zzip__new__ __attribute__((malloc)) +#elif defined __linux__ && __GNUC__+0 >= 3 && __GNUC_MINOR_+0 >= 3 +#define zzip__new__ __attribute__((malloc)) +#else +#define zzip__new__ +#endif + +#ifndef _zzip_size_t +#ifdef ZZIP_size_t +#define _zzip_size_t ZZIP_size_t +#else +#define _zzip_size_t size_t +#endif +#endif +#ifndef _zzip_ssize_t +#ifdef ZZIP_ssize_t +#define _zzip_ssize_t ZZIP_ssize_t +#else +#define _zzip_ssize_t ssize_t +#endif +#endif +#ifndef _zzip___int64 +#ifdef ZZIP___int64 +#define _zzip___int64 ZZIP___int64 +#else +#define _zzip___int64 long long +#endif +#endif + +/* whether this library shall use a 64bit off_t largefile variant in 64on32: */ +/* (some exported names must be renamed to avoid bad calls after linking) */ +#if defined ZZIP_LARGEFILE_SENSITIVE +# if _FILE_OFFSET_BITS+0 == 64 +# define ZZIP_LARGEFILE_RENAME +# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */ +# define ZZIP_LARGEFILE_RENAME +# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */ +# define ZZIP_LARGEFILE_RENAME +# endif +#endif + +/* if the environment did not setup these for 64bit off_t largefile... */ +#ifdef ZZIP_LARGEFILE_RENAME +# ifndef _FILE_OFFSET_BITS +# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */ +# define _FILE_OFFSET_BITS ZZIP__FILE_OFFSET_BITS +# endif +# endif +# ifndef _LARGE_FILES +# ifdef ZZIP__LARGE_FILES /* == 1 */ +# define _LARGE_FILES ZZIP__LARGE_FILES +# endif +# endif +# ifndef _LARGEFILE_SOURCE +# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */ +# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE +# endif +# endif +#endif + +#include + +/* mingw32msvc errno : would be in winsock.h */ +#ifndef EREMOTE +#define EREMOTE ESPIPE +#endif + +#ifndef ELOOP +#if defined EILSEQ +#define ELOOP EILSEQ +#else +#define ELOOP ENOEXEC +#endif +#endif + +#if defined __WATCOMC__ +#undef _zzip_inline +#define _zzip_inline static +#endif + +#if defined _MSC_VER || defined __WATCOMC__ +#include +#endif + +#ifdef _MSC_VER +# if !__STDC__ +# ifndef _zzip_lseek +# define _zzip_lseek _lseek +# endif +# ifndef _zzip_read +# define _zzip_read _read +# endif +# ifndef _zzip_write +# define _zzip_write _write +# endif +# if 0 +# ifndef _zzip_stat +# define _zzip_stat _stat +# endif +# endif +# endif /* !__STDC__ */ +#endif + /*MSVC*/ + +#if defined _MSC_VER || defined __WATCOMC__ +# ifndef strcasecmp +# define strcasecmp _stricmp +# endif +#endif + +# ifndef _zzip_lseek +# define _zzip_lseek lseek +# endif + +# ifndef _zzip_read +# define _zzip_read read +# endif + +# ifndef _zzip_write +# define _zzip_write write +# endif + +# if 0 +# ifndef _zzip_stat +# define _zzip_stat stat +# endif +# endif + + +#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS +# undef ZZIP_DLL +#define ZZIP_DLL 1 +#endif + +/* based on zconf.h : */ +/* compile with -DZZIP_DLL for Windows DLL support */ +#if defined ZZIP_DLL +# if defined _WINDOWS || defined WINDOWS || defined _WIN32 +/*# include */ +# endif +# if !defined _zzip_export && defined _MSC_VER && (defined WIN32 || defined _WIN32) +# define _zzip_export __declspec(dllexport) /*WINAPI*/ +# endif +# if !defined _zzip_export && defined __BORLANDC__ +# if __BORLANDC__ >= 0x0500 && defined WIN32 +# include +# define _zzip_export __declspec(dllexport) /*WINAPI*/ +# else +# if defined _Windows && defined __DLL__ +# define _zzip_export _export +# endif +# endif +# endif +# if !defined _zzip_export && defined __GNUC__ +# if defined __declspec +# define _zzip_export extern __declspec(dllexport) +# else +# define _zzip_export extern +# endif +# endif +# if !defined _zzip_export && defined __BEOS__ +# define _zzip_export extern __declspec(export) +# endif +# if !defined _zzip_export && defined __WATCOMC__ +# define _zzip_export extern __declspec(dllexport) +# define ZEXPORT __syscall +# define ZEXTERN extern +# endif +#endif + +#if !defined _zzip_export +# if defined __GNUC__ /* || !defined HAVE_LIBZZIP */ +# define _zzip_export extern +# elif defined __declspec || (defined _MSC_VER && defined ZZIP_DLL) +# define _zzip_export extern __declspec(dllimport) +# else +# define _zzip_export extern +# endif +#endif + +#endif + + diff --git a/project/jni/zzip/include/zzip/fetch.h b/project/jni/zzip/include/zzip/fetch.h new file mode 100644 index 000000000..ca51a8026 --- /dev/null +++ b/project/jni/zzip/include/zzip/fetch.h @@ -0,0 +1,374 @@ +#ifndef _ZZIP_FORMATS_H +#define _ZZIP_FORMATS_H + +#include +#include +#include +#include + +/* linux knows "byteswap.h" giving us an optimized variant */ +#ifdef ZZIP_HAVE_BYTESWAP_H +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* get 16/32 bits from little-endian zip-file to host byteorder */ +extern uint32_t __zzip_get32(zzip_byte_t * s) ZZIP_GNUC_CONST; +extern uint16_t __zzip_get16(zzip_byte_t * s) ZZIP_GNUC_CONST; +extern void __zzip_set32(zzip_byte_t * s, uint32_t v); +extern void __zzip_set16(zzip_byte_t * s, uint16_t v); + +extern uint64_t __zzip_get64(zzip_byte_t * s) ZZIP_GNUC_CONST; +extern void __zzip_set64(zzip_byte_t * s, uint64_t v); + +/* just in case that you use a non-configure-d setup (e.g. MSVC) */ +#ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED +# if defined __mips__ || defined __sparc__ || defined __powerpc__ || defined __arm__ || defined __ia64__ +# define ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED 11 +# endif +#endif + +/* on linux with a cisc processor we can use the bswap for some extra speed */ +#ifdef ZZIP_WORDS_BIGENDIAN +# ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED +# if defined bswap_16 && defined bswap_32 && defined bswap_64 /* i.e. linux */ +# define _ZZIP_USE_BSWAP +# endif +# endif +#endif + +/* little endian on intel cisc processors is the original zip format byteorder */ +#ifndef ZZIP_WORDS_BIGENDIAN +# ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED +# if defined __i386__ || defined __x86_64__ || defined _M_X86 || defined _M_X64 +# define _ZZIP_USE_DEREF +# endif +#endif + +#ifdef _ZZIP_USE_BSWAP +#define ZZIP_GET16(__p) bswap_16(*(uint16_t*)(__p)) +#define ZZIP_GET32(__p) bswap_32(*(uint32_t*)(__p)) +#define ZZIP_GET64(__p) bswap_64(*(uint64_t*)(__p)) +#define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = bswap_16((uint16_t)(__x))) +#define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = bswap_32((uint32_t)(__x))) +#define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = bswap_64((uint64_t)(__x))) +#elif defined _ZZIP_USE_DEREF +#define ZZIP_GET16(__p) (*(uint16_t*)(__p)) +#define ZZIP_GET32(__p) (*(uint32_t*)(__p)) +#define ZZIP_GET64(__p) (*(uint64_t*)(__p)) +#define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = (uint16_t)(__x)) +#define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = (uint32_t)(__x)) +#define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = (uint64_t)(__x)) +#else +#define ZZIP_GET64(__p) (__zzip_get64((__p))) +#define ZZIP_GET32(__p) (__zzip_get32((__p))) +#define ZZIP_GET16(__p) (__zzip_get16((__p))) +#define ZZIP_SET64(__p,__x) (__zzip_set64((__p),(__x))) +#define ZZIP_SET32(__p,__x) (__zzip_set32((__p),(__x))) +#define ZZIP_SET16(__p,__x) (__zzip_set16((__p),(__x))) +#endif +#endif + +/* ..................... bitcorrect physical access .................... */ + +/* zzip_file_header - the local file header */ +#define zzip_file_header_get_magic(__p) ZZIP_GET32((__p)->z_magic) +#define zzip_file_header_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x)) +#define zzip_file_header_get_flags(__p) ZZIP_GET16((__p)->z_flags) +#define zzip_file_header_set_flags(__p,__x) ZZIP_SET16((__p)->z_flags,(__x)) +#define zzip_file_header_get_compr(__p) ZZIP_GET16((__p)->z_compr) +#define zzip_file_header_set_compr(__p,__x) ZZIP_SET16((__p)->z_compr,(__x)) +#define zzip_file_header_get_crc32(__p) ZZIP_GET32((__p)->z_crc32) +#define zzip_file_header_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x)) +#define zzip_file_header_get_csize(__p) ZZIP_GET32((__p)->z_csize) +#define zzip_file_header_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x)) +#define zzip_file_header_get_usize(__p) ZZIP_GET32((__p)->z_usize) +#define zzip_file_header_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x)) +#define zzip_file_header_get_namlen(__p) ZZIP_GET16((__p)->z_namlen) +#define zzip_file_header_set_namlen(__p,__x) ZZIP_SET16((__p)->z_namlen,(__x)) +#define zzip_file_header_get_extras(__p) ZZIP_GET16((__p)->z_extras) +#define zzip_file_header_set_extras(__p,__x) ZZIP_SET16((__p)->z_extras,(__x)) +#define zzip_file_header_sizeof_tails(__p) (zzip_file_header_get_namlen(__p)+\ + zzip_file_header_get_extras(__p) ) +#define zzip_file_header_check_magic(__p) ZZIP_FILE_HEADER_CHECKMAGIC((__p)) + +/* zzip_file_trailer - data descriptor per file block */ +#define zzip_file_trailer_get_magic(__p) ZZIP_GET32((__p)->z_magic) +#define zzip_file_trailer_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x)) +#define zzip_file_header_get_crc32(__p) ZZIP_GET32((__p)->z_crc32) +#define zzip_file_trailer_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x)) +#define zzip_file_trailer_get_csize(__p) ZZIP_GET32((__p)->z_csize) +#define zzip_file_trailer_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x)) +#define zzip_file_trailer_get_usize(__p) ZZIP_GET32((__p)->z_usize) +#define zzip_file_trailer_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x)) +#define zzip_file_trailer_sizeof_tails(__p) 0 +#define zzip_file_trailer_check_magic(__p) ZZIP_FILE_TRAILER_CHECKMAGIC((__p)) +/* zzip_disk_entry (currently named zzip_root_dirent) */ +#define zzip_disk_entry_get_magic(__p) ZZIP_GET32((__p)->z_magic) +#define zzip_disk_entry_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x)) +#define zzip_disk_entry_get_flags(__p) ZZIP_GET16((__p)->z_flags) +#define zzip_disk_entry_set_flags(__p,__x) ZZIP_SET16((__p)->z_flags,(__x)) +#define zzip_disk_entry_get_compr(__p) ZZIP_GET16((__p)->z_compr) +#define zzip_disk_entry_set_compr(__p,__x) ZZIP_SET16((__p)->z_compr,(__x)) +#define zzip_disk_entry_get_crc32(__p) ZZIP_GET32((__p)->z_crc32) +#define zzip_disk_entry_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x)) +#define zzip_disk_entry_get_csize(__p) ZZIP_GET32((__p)->z_csize) +#define zzip_disk_entry_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x)) +#define zzip_disk_entry_get_usize(__p) ZZIP_GET32((__p)->z_usize) +#define zzip_disk_entry_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x)) +#define zzip_disk_entry_get_namlen(__p) ZZIP_GET16((__p)->z_namlen) +#define zzip_disk_entry_set_namlen(__p,__x) ZZIP_SET16((__p)->z_namlen,(__x)) +#define zzip_disk_entry_get_extras(__p) ZZIP_GET16((__p)->z_extras) +#define zzip_disk_entry_set_extras(__p,__x) ZZIP_SET16((__p)->z_extras,(__x)) +#define zzip_disk_entry_get_comment(__p) ZZIP_GET16((__p)->z_comment) +#define zzip_disk_entry_set_comment(__p,__x) ZZIP_SET16((__p)->z_comment,(__x)) +#define zzip_disk_entry_get_diskstart(__p) ZZIP_GET16((__p)->z_diskstart) +#define zzip_disk_entry_set_diskstart(__p,__x) ZZIP_SET16((__p)->z_diskstart,(__x)) +#define zzip_disk_entry_get_filetype(__p) ZZIP_GET16((__p)->z_filetype) +#define zzip_disk_entry_set_filetype(__p,__x) ZZIP_SET16((__p)->z_filetype,(__x)) +#define zzip_disk_entry_get_filemode(__p) ZZIP_GET32((__p)->z_filemode) +#define zzip_disk_entry_set_filemode(__p,__x) ZZIP_SET32((__p)->z_filemode,(__x)) +#define zzip_disk_entry_get_offset(__p) ZZIP_GET32((__p)->z_offset) +#define zzip_disk_entry_set_offset(__p,__x) ZZIP_SET32((__p)->z_offset,(__x)) +#define zzip_disk_entry_sizeof_tails(__p) (zzip_disk_entry_get_namlen(__p) +\ + zzip_disk_entry_get_extras(__p) +\ + zzip_disk_entry_get_comment(__p) ) +#define zzip_disk_entry_check_magic(__p) ZZIP_DISK_ENTRY_CHECKMAGIC((__p)) + +/* zzip_disk_trailer - the zip archive entry point */ +#define zzip_disk_trailer_get_magic(__p) ZZIP_GET32((__p)->z_magic) +#define zzip_disk_trailer_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x)) +#define zzip_disk_trailer_get_disk(__p) ZZIP_GET16((__p)->z_disk) +#define zzip_disk_trailer_set_disk(__p,__x) ZZIP_SET16((__p)->z_disk,(__x)) +#define zzip_disk_trailer_get_finaldisk(__p) ZZIP_GET16((__p)->z_finaldisk) +#define zzip_disk_trailer_set_finaldisk(__p,__x) ZZIP_SET16((__p)->z_finaldisk,(__x)) +#define zzip_disk_trailer_get_entries(__p) ZZIP_GET16((__p)->z_entries) +#define zzip_disk_trailer_set_entries(__p,__x) ZZIP_SET16((__p)->z_entries,(__x)) +#define zzip_disk_trailer_get_finalentries(__p) ZZIP_GET16((__p)->z_finalentries) +#define zzip_disk_trailer_set_finalentries(__p,__x) ZZIP_SET16((__p)->z_finalentries,(__x)) +#define zzip_disk_trailer_get_rootsize(__p) ZZIP_GET32((__p)->z_rootsize) +#define zzip_disk_trailer_set_rootsize(__p,__x) ZZIP_SET32((__p)->z_rootsize,(__x)) +#define zzip_disk_trailer_get_rootseek(__p) ZZIP_GET32((__p)->z_rootseek) +#define zzip_disk_trailer_set_rootseek(__p,__x) ZZIP_SET32((__p)->z_rootseek,(__x)) +#define zzip_disk_trailer_get_comment(__p) ZZIP_GET16((__p)->z_comment) +#define zzip_disk_trailer_set_comment(__p,__x) ZZIP_SET16((__p)->z_comment,(__x)) +#define zzip_disk_trailer_sizeof_tails(__p) ( zzip_disk_entry_get_comment(__p)) +#define zzip_disk_trailer_check_magic(__p) ZZIP_DISK_TRAILER_CHECKMAGIC((__p)) + +/* extra field should be type + size + data + type + size + data ... */ +#define zzip_extra_block_get_datatype(__p) ZZIP_GET16((zzip_byte_t*)(__p)) +#define zzip_extra_block_set_datatype(__p,__x) ZZIP_SET16((zzip_byte_t*)(__p),__x) +#define zzip_extra_block_get_datasize(__p) ZZIP_GET16((zzip_byte_t*)(__p)+2) +#define zzip_extra_block_set_datasize(__p,__x) ZZIP_SET16((zzip_byte_t*)(__p)+2,__x) + +/* zzip64_disk_trailer - the zip64 archive entry point */ +#define zzip_disk64_trailer_get_magic(__p) ZZIP_GET32((__p)->z_magic) +#define zzip_disk64_trailer_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x)) +#define zzip_disk64_trailer_get_size(__p) ZZIP_GET64((__p)->z_size) +#define zzip_disk64_trailer_set_size(__p,__x) ZZIP_SET64((__p)->z_size,(__x)) +#define zzip_disk64_trailer_get_disk(__p) ZZIP_GET32((__p)->z_disk) +#define zzip_disk64_trailer_set_disk(__p,__x) ZZIP_SET32((__p)->z_disk,(__x)) +#define zzip_disk64_trailer_get_finaldisk(__p) ZZIP_GET32((__p)->z_finaldisk) +#define zzip_disk64_trailer_set_finaldisk(__p,__x) ZZIP_SET32((__p)->z_finaldisk,(__x)) +#define zzip_disk64_trailer_get_entries(__p) ZZIP_GET64((__p)->z_entries) +#define zzip_disk64_trailer_set_entries(__p,__x) ZZIP_SET64((__p)->z_entries,(__x)) +#define zzip_disk64_trailer_get_finalentries(__p) ZZIP_GET64((__p)->z_finalentries) +#define zzip_disk64_trailer_set_finalentries(__p,__x) ZZIP_SET64((__p)->z_finalentries,(__x)) +#define zzip_disk64_trailer_get_rootsize(__p) ZZIP_GET64((__p)->z_rootsize) +#define zzip_disk64_trailer_set_rootsize(__p,__x) ZZIP_SET64((__p)->z_rootsize,(__x)) +#define zzip_disk64_trailer_get_rootseek(__p) ZZIP_GET64((__p)->z_rootseek) +#define zzip_disk64_trailer_set_rootseek(__p,__x) ZZIP_SET64((__p)->z_rootseek,(__x)) +#define zzip_disk64_trailer_check_magic(__p) ZZIP_DISK64_TRAILER_CHECKMAGIC((__p)) + +/* .............. some logical typed access wrappers ....................... */ + +/* zzip_file_header - the local file header */ +#define zzip_file_header_csize(__p) ((zzip_size_t) \ + zzip_file_header_get_csize(__p)) +#define zzip_file_header_usize(__p) ((zzip_size_t) \ + zzip_file_header_get_usize(__p)) +#define zzip_file_header_namlen(__p) ((zzip_size_t) \ + zzip_file_header_get_namlen(__p)) +#define zzip_file_header_extras(__p) ((zzip_size_t) \ + zzip_file_header_get_extras(__p)) +#define zzip_file_header_sizeof_tail(__p) ((zzip_size_t) \ + zzip_file_header_sizeof_tails(__p)) +#define zzip_file_header_sizeto_end(__p) ((zzip_size_t) \ + (zzip_file_header_sizeof_tail(__p) + zzip_file_header_headerlength)) +#define zzip_file_header_skipto_end(__p) ((void*) (__p) + \ + (zzip_file_header_sizeof_tail(__p) + zzip_file_header_headerlength)) + +#define zzip_file_header_to_filename(__p) ((char*) \ + ((char*)(__p) + zzip_file_header_headerlength)) +#define zzip_file_header_to_extras(__p) ((char*) \ + (zzip_file_header_to_filename(__p) + zzip_file_header_namlen(__p))) +#define zzip_file_header_to_data(__p) ((zzip_byte_t*) \ + (zzip_file_header_to_extras(__p) + zzip_file_header_extras(__p))) +#define zzip_file_header_to_trailer(__p) ((struct zzip_file_trailer*) \ + (zzip_file_header_to_data(__p) + zzip_file_header_csize(__p))) + +/* zzip_file_trailer - data descriptor per file block */ +#define zzip_file_trailer_csize(__p) ((zzip_size_t) \ + zzip_file_trailer_get_csize(__p)) +#define zzip_file_trailer_usize(__p) ((zzip_size_t) \ + zzip_file_trailer_get_usize(__p)) +#define zzip_file_trailer_sizeof_tail(__p) ((zzip_size_t) \ + zzip_file_trailer_sizeof_tails(__p)) +#define zzip_file_trailer_sizeto_end(__p) ((zzip_size_t) \ + (zzip_file_trailer_sizeof_tail(__p) + zzip_file_trailer_headerlength)) +#define zzip_file_trailer_skipto_end(__p) ((void*) (__p) + \ + (zzip_file_trailer_sizeof_tail(__p) + zzip_file_trailer_headerlength)) + +/* zzip_disk_entry (currently named zzip_root_dirent) */ +#define zzip_disk_entry_csize(__p) ((zzip_size_t) \ + zzip_disk_entry_get_csize(__p)) +#define zzip_disk_entry_usize(__p) ((zzip_size_t) \ + zzip_disk_entry_get_usize(__p)) +#define zzip_disk_entry_namlen(__p) ((zzip_size_t) \ + zzip_disk_entry_get_namlen(__p)) +#define zzip_disk_entry_extras(__p) ((zzip_size_t) \ + zzip_disk_entry_get_extras(__p)) +#define zzip_disk_entry_comment(__p) ((zzip_size_t) \ + zzip_disk_entry_get_comment(__p)) +#define zzip_disk_entry_diskstart(__p) ((int) \ + zzip_disk_entry_get_diskstart(__p)) +#define zzip_disk_entry_filetype(__p) ((int) \ + zzip_disk_entry_get_filetype(__p)) +#define zzip_disk_entry_filemode(__p) ((int) \ + zzip_disk_entry_get_filemode(__p)) +#define zzip_disk_entry_fileoffset(__p) ((zzip_off_t) \ + zzip_disk_entry_get_offset(__p)) +#define zzip_disk_entry_sizeof_tail(__p) ((zzip_size_t) \ + zzip_disk_entry_sizeof_tails(__p)) +#define zzip_disk_entry_sizeto_end(__p) ((zzip_size_t) \ + (zzip_disk_entry_sizeof_tail(__p) + zzip_disk_entry_headerlength)) +#define zzip_disk_entry_skipto_end(__p) ((zzip_byte_t*) (__p) + \ + (zzip_disk_entry_sizeof_tail(__p) + zzip_disk_entry_headerlength)) + +#define zzip_disk_entry_to_filename(__p) ((char*) \ + ((char*)(__p) + zzip_disk_entry_headerlength)) +#define zzip_disk_entry_to_extras(__p) ((char*) \ + (zzip_disk_entry_to_filename(__p) + zzip_disk_entry_namlen(__p))) +#define zzip_disk_entry_to_comment(__p) ((char*) \ + (zzip_disk_entry_to_extras(__p) + zzip_disk_entry_extras(__p))) +#define zzip_disk_entry_to_next_entry(__p) ((struct zzip_disk_entry*) \ + (zzip_disk_entry_to_comment(__p) + zzip_disk_entry_comment(__p))) + +/* zzip_disk_trailer - the zip archive entry point */ +#define zzip_disk_trailer_localdisk(__p) ((int) \ + zzip_disk_trailer_get_disk(__p)) +#define zzip_disk_trailer_finaldisk(__p) ((int) \ + zzip_disk_trailer_get_finaldisk(__p)) +#define zzip_disk_trailer_localentries(__p) ((int) \ + zzip_disk_trailer_get_entries(__p)) +#define zzip_disk_trailer_finalentries(__p) ((int) \ + zzip_disk_trailer_get_finalentries(__p)) +#define zzip_disk_trailer_rootsize(__p) ((zzip_off_t) \ + zzip_disk_trailer_get_rootsize(__p)) +#define zzip_disk_trailer_rootseek(__p) ((zzip_off_t) \ + zzip_disk_trailer_get_rootseek(__p)) +#define zzip_disk_trailer_comment(__p) ((zzip_size_t) \ + zzip_disk_trailer_get_comment(__p)) +#define zzip_disk_trailer_sizeof_tail(__p) ((zzip_size_t) \ + zzip_disk_trailer_sizeof_tails(__p)) +#define zzip_disk_trailer_sizeto_end(__p) ((zzip_size_t) \ + (zzip_disk_trailer_sizeof_tail(__p) + zzip_disk_trailer_headerlength)) +#define zzip_disk_trailer_skipto_end(__p) ((void*) (__p) \ + (zzip_disk_trailer_sizeof_tail(__p) + zzip_disk_trailer_headerlength)) + +#define zzip_disk_trailer_to_comment(__p) ((char*) \ + ((char*)(__p) + zzip_disk_trailer_headerlength)) +#define zzip_disk_trailer_to_endoffile(__p) ((void*) \ + (zzip_disk_trailer_to_comment(__p) + zzip_disk_trailer_comment(__p))) + +/* zzip_disk64_trailer - the zip archive entry point */ +#define zzip_disk64_trailer_localdisk(__p) ((int) \ + zzip_disk64_trailer_get_disk(__p)) +#define zzip_disk64_trailer_finaldisk(__p) ((int) \ + zzip_disk64_trailer_get_finaldisk(__p)) +#define zzip_disk64_trailer_localentries(__p) ((int) \ + zzip_disk64_trailer_get_entries(__p)) +#define zzip_disk64_trailer_finalentries(__p) ((int) \ + zzip_disk64_trailer_get_finalentries(__p)) +#define zzip_disk64_trailer_rootsize(__p) ((zzip_off64_t) \ + zzip_disk64_trailer_get_rootsize(__p)) +#define zzip_disk64_trailer_rootseek(__p) ((zzip_off64_t) \ + zzip_disk64_trailer_get_rootseek(__p)) +#define zzip_disk64_trailer_sizeof_tail(__p) ((zzip_size_t) \ + zzip_disk64_trailer_get_size(__p) - zzip_disk64_trailer_headerlength) +#define zzip_disk64_trailer_sizeto_end(__p) ((zzip_size_t) \ + zzip_disk64_trailer_get_size(__p)) +#define zzip_disk64_trailer_skipto_end(__p) ((void*) \ + ((char*)(__p) + zzip_disk64_sizeto_end(__p))) + +/* extra field should be type + size + data + type + size + data ... */ +#define zzip_extra_block_sizeof_tail(__p) ((zzip_size_t) \ + (zzip_extra_block_get_datasize(__p))) +#define zzip_extra_block_sizeto_end(__p) ((zzip_size_t) \ + (zzip_extra_block_sizeof_tail(__p) + zzip_extra_block_headerlength)) +#define zzip_extra_block_skipto_end(__p) ((void*) (__p) \ + (zzip_extra_block_sizeof_tail(__p) + zzip_extra_block_headerlength)) + +/* ................... and put these to the next level ................ */ + +#define zzip_file_header_data_encrypted(__p) \ + ZZIP_IS_ENCRYPTED( zzip_file_header_get_flags(__p) ) +#define zzip_file_header_data_comprlevel(__p) \ + ZZIP_IS_COMPRLEVEL( zzip_file_header_get_flags(__p) ) +#define zzip_file_header_data_streamed(__p) \ + ZZIP_IS_STREAMED( zzip_file_header_get_flags(__p) ) +#define zzip_file_header_data_stored(__p) \ + ( ZZIP_IS_STORED == zzip_file_header_get_compr(__p) ) +#define zzip_file_header_data_deflated(__p) \ + ( ZZIP_IS_DEFLATED == zzip_file_header_get_compr(__p) ) + +#define zzip_disk_entry_data_encrypted(__p) \ + ZZIP_IS_ENCRYPTED( zzip_disk_entry_get_flags(__p) ) +#define zzip_disk_entry_data_comprlevel(__p) \ + ZZIP_IS_COMPRLEVEL( zzip_disk_entry_get_flags(__p) ) +#define zzip_disk_entry_data_streamed(__p) \ + ZZIP_IS_STREAMED( zzip_disk_entry_get_flags(__p) ) +#define zzip_disk_entry_data_stored(__p) \ + ( ZZIP_IS_STORED == zzip_disk_entry_get_compr(__p) ) +#define zzip_disk_entry_data_deflated(__p) \ + ( ZZIP_IS_DEFLATED == zzip_disk_entry_get_compr(__p) ) +#define zzip_disk_entry_data_ascii(__p) \ + ( zzip_disk_entry_get_filetype(__p) & 1) + +#define zzip_file_header_data_not_deflated(__p) \ + (zzip_file_header_data_stored(__p)) +#define zzip_file_header_data_std_deflated(__p) \ + (zzip_file_header_data_deflated(__p) && \ + zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_STD_COMPR) +#define zzip_file_header_data_max_deflated(__p) \ + (zzip_file_header_data_deflated(__p) && \ + zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_MAX_COMPR) +#define zzip_file_header_data_low_deflated(__p) \ + (zzip_file_header_data_deflated(__p) && \ + zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_LOW_COMPR) +#define zzip_file_header_data_min_deflated(__p) \ + (zzip_file_header_data_deflated(__p) && \ + zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_MIN_COMPR) + +#define zzip_disk_entry_data_not_deflated(__p) \ + (zzip_disk_entry_data_stored(__p)) +#define zzip_disk_entry_data_std_deflated(__p) \ + (zzip_disk_entry_data_deflated(__p) && \ + zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_STD_COMPR) +#define zzip_disk_entry_data_max_deflated(__p) \ + (zzip_disk_entry_data_deflated(__p) && \ + zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_MAX_COMPR) +#define zzip_disk_entry_data_low_deflated(__p) \ + (zzip_disk_entry_data_deflated(__p) && \ + zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_LOW_COMPR) +#define zzip_disk_entry_data_min_deflated(__p) \ + (zzip_disk_entry_data_deflated(__p) && \ + zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_MIN_COMPR) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/project/jni/zzip/include/zzip/file.h b/project/jni/zzip/include/zzip/file.h new file mode 100644 index 000000000..7a35aeb14 --- /dev/null +++ b/project/jni/zzip/include/zzip/file.h @@ -0,0 +1,81 @@ +/* + * this is an internal header file - the structure contains two off_t + * atleast making it LARGEFILE_SENSITIVE on linux2 and solaris systems + * whereas about all functions just return a ZZIP_FILE* in zzip/zzip.h + * + * and so, this structure should be handled version-specific and + * subject to change - it had been kept binary-compatible for quite + * a while now so perhaps some program sources have errnously taken + * advantage of this file. + * + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifndef _ZZIP_FILE_H /* zzip-file.h */ +#define _ZZIP_FILE_H 1 + +#ifndef ZZIP_32K +#ifdef __GNUC__ +/* include zzip/lib.h beforehand in order to suppress the following warning */ +#warning zzip/file.h is an internal header, do not use it freely +#endif +#endif + +#include +#include + +#ifdef ZZIP_HAVE_UNISTD_H +#include +#else +#include +# ifdef ZZIP_HAVE_SYS_TYPES_H +# include +# endif +#endif + +#ifdef ZZIP_HAVE_SYS_PARAM_H +#include /* PATH_MAX */ +#endif + +#ifndef PATH_MAX +# ifdef MAX_PATH /* windows */ +# define PATH_MAX MAX_PATH +# else +# define PATH_MAX 512 +# endif +#endif +/* + * ZZIP_FILE structure... currently no need to unionize, since structure needed + * for inflate is superset of structure needed for unstore. + * + * Don't make this public. Instead, create methods for needed operations. + */ + +struct zzip_file +{ + struct zzip_dir* dir; + int fd; + int method; + zzip_size_t restlen; + zzip_size_t crestlen; + zzip_size_t usize; + zzip_size_t csize; + /* added dataoffset member - data offset from start of zipfile*/ + zzip_off_t dataoffset; + char* buf32k; + zzip_off_t offset; /* offset from the start of zipfile... */ + z_stream d_stream; + zzip_plugin_io_t io; +}; + +#endif /* _ZZIP_FILE_H */ + diff --git a/project/jni/zzip/include/zzip/format.h b/project/jni/zzip/include/zzip/format.h new file mode 100644 index 000000000..0881479c1 --- /dev/null +++ b/project/jni/zzip/include/zzip/format.h @@ -0,0 +1,234 @@ +/* + * Author: + * Guido Draheim + * + * Copyright (c) 2000,2001,2002,2003 Guido Draheim + * All rights reserved + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * The information was taken from appnote-981119-iz.zip + * at http://www.freesoftware.com/pub/infozip/doc/ + * which in turn is based on PKWARE's appnote.txt + * (newer link: ftp://ftp.info-zip.org/pub/infozip/doc/) + */ +#ifndef _ZZIP_FORMAT_H /* zzipformat.h */ +#define _ZZIP_FORMAT_H + +#include +#include +/* we have ICO C 9X types defined */ + +/* + * Overall zipfile format + * [local file header + file data stream + checksum descriptor] ... + * ... [disk central directory] [disk trailer record] + */ + +# ifdef _MSC_VER +# pragma pack(push, 1) +# endif + +struct zzip_version +{ + zzip_byte_t version[1]; + zzip_byte_t ostype[1]; +} ZZIP_GNUC_PACKED; + +struct zzip_dostime +{ + zzip_byte_t time[2]; + zzip_byte_t date[2]; +} ZZIP_GNUC_PACKED; + +#ifdef ZZIP_NEED_PACKED +/* if your compiler does interesting things about struct packing... */ +typedef zzip_byte_t zzip_version_t[2]; +typedef zzip_byte_t zzip_dostime_t[4]; +#else +typedef struct zzip_version zzip_version_t; +typedef struct zzip_dostime zzip_dostime_t; +#endif + +#define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \ + ( (((zzip_byte_t*)(__p))[0]==(__A)) && \ + (((zzip_byte_t*)(__p))[1]==(__B)) && \ + (((zzip_byte_t*)(__p))[2]==(__C)) && \ + (((zzip_byte_t*)(__p))[3]==(__D)) ) + +/* A. Local file header */ +struct zzip_file_header +{ +# define ZZIP_FILE_HEADER_MAGIC 0x04034b50 +# define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4') + zzip_byte_t z_magic[4]; /* local file header signature (0x04034b50) */ + zzip_version_t z_extract; /* version needed to extract */ + zzip_byte_t z_flags[2]; /* general purpose bit flag */ + zzip_byte_t z_compr[2]; /* compression method */ + zzip_dostime_t z_dostime; /* last mod file time (dos format) */ + zzip_byte_t z_crc32[4]; /* crc-32 */ + zzip_byte_t z_csize[4]; /* compressed size */ + zzip_byte_t z_usize[4]; /* uncompressed size */ + zzip_byte_t z_namlen[2]; /* filename length (null if stdin) */ + zzip_byte_t z_extras[2]; /* extra field length */ + /* followed by filename (of variable size) */ + /* followed by extra field (of variable size) */ +} ZZIP_GNUC_PACKED; +#define zzip_file_header_headerlength (4+2+2+2+4+4+4+4+2+2) + +/* B. data descriptor + * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned + * and immediately follows the last byte of compressed data. It is only used if + * the output media of the compressor was not seekable, eg. standard output. + */ +struct zzip_file_trailer +{ +# define ZZIP_FILE_TRAILER_MAGIC 0x08074B50 +# define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8') + zzip_byte_t z_magic[4]; /* data descriptor signature (0x08074b50) */ + zzip_byte_t z_crc32[4]; /* crc-32 */ + zzip_byte_t z_csize[4]; /* compressed size */ + zzip_byte_t z_usize[4]; /* uncompressed size */ +} ZZIP_GNUC_PACKED; +#define zzip_file_trailer_headerlength (4+4+4+4) + +/* C. central directory structure: + [file header] . . . end of central dir record +*/ + +/* directory file header + * - a single entry including filename, extras and comment may not exceed 64k. + */ + +struct zzip_disk_entry +{ +# define ZZIP_DISK_ENTRY_MAGIC 0x02014b50 +# define ZZIP_DISK_ENTRY_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2') + zzip_byte_t z_magic[4]; /* central file header signature (0x02014b50) */ + zzip_version_t z_encoder; /* version made by */ + zzip_version_t z_extract; /* version need to extract */ + zzip_byte_t z_flags[2]; /* general purpose bit flag */ + zzip_byte_t z_compr[2]; /* compression method */ + zzip_dostime_t z_dostime; /* last mod file time&date (dos format) */ + zzip_byte_t z_crc32[4]; /* crc-32 */ + zzip_byte_t z_csize[4]; /* compressed size */ + zzip_byte_t z_usize[4]; /* uncompressed size */ + zzip_byte_t z_namlen[2]; /* filename length (null if stdin) */ + zzip_byte_t z_extras[2]; /* extra field length */ + zzip_byte_t z_comment[2]; /* file comment length */ + zzip_byte_t z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */ + zzip_byte_t z_filetype[2]; /* internal file attributes, bit0 = ascii */ + zzip_byte_t z_filemode[4]; /* extrnal file attributes, eg. msdos attrib byte */ + zzip_byte_t z_offset[4]; /* relative offset of local file header, seekval if singledisk */ + /* followed by filename (of variable size) */ + /* followed by extra field (of variable size) */ + /* followed by file comment (of variable size) */ +} ZZIP_GNUC_PACKED; +#define zzip_disk_entry_headerlength (4+2+2+2+2+4+4+4+4+2+2+2+2+2+4+4) + + +struct zzip_root_dirent +{ /* the old name of the structure above */ +# define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50 +# define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_DISK_ENTRY_CHECKMAGIC(__p) + zzip_byte_t z_magic[4]; + zzip_version_t z_encoder; + zzip_version_t z_extract; + zzip_byte_t z_flags[2]; + zzip_byte_t z_compr[2]; + zzip_dostime_t z_dostime; + zzip_byte_t z_crc32[4]; + zzip_byte_t z_csize[4]; + zzip_byte_t z_usize[4]; + zzip_byte_t z_namlen[2]; + zzip_byte_t z_extras[2]; + zzip_byte_t z_comment[2]; + zzip_byte_t z_diskstart[2]; + zzip_byte_t z_filetype[2]; + zzip_byte_t z_filemode[4]; + zzip_byte_t z_off[4]; +} ZZIP_GNUC_PACKED; + + +/* end of central dir record */ +struct zzip_disk_trailer +{ +# define ZZIP_DISK_TRAILER_MAGIC 0x06054b50 +# define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6') + zzip_byte_t z_magic[4]; /* end of central dir signature (0x06054b50) */ + zzip_byte_t z_disk[2]; /* number of this disk */ + zzip_byte_t z_finaldisk[2]; /* number of the disk with the start of the central dir */ + zzip_byte_t z_entries[2]; /* total number of entries in the central dir on this disk */ + zzip_byte_t z_finalentries[2]; /* total number of entries in the central dir */ + zzip_byte_t z_rootsize[4]; /* size of the central directory */ + zzip_byte_t z_rootseek[4]; /* offset of start of central directory with respect to * + * the starting disk number */ + zzip_byte_t z_comment[2]; /* zipfile comment length */ + /* followed by zipfile comment (of variable size) */ +} ZZIP_GNUC_PACKED; +#define zzip_disk_trailer_headerlength (4+2+2+2+2+4+4+2) + +/* extra field should be type + size + data + type + size + data ... */ +struct zzip_extra_block +{ /* fetch.h macros do not need this struct */ + zzip_byte_t z_datatype[2]; /* as input type - a mere is okay */ + zzip_byte_t z_datasize[2]; /* being returned by xx_to_extras usually */ +} ZZIP_GNUC_PACKED; +#define zzip_extra_block_headerlength (2+2) + +/* Zip64 end of central dir record */ +struct zzip_disk64_trailer +{ +# define ZZIP_DISK64_TRAILER_MAGIC 0x06064b50 +# define ZZIP_DISK64_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\6','\6') + zzip_byte_t z_magic[4]; /* end of central dir signature (0x06054b50) */ + zzip_byte_t z_size[8]; /* size of this central directory record */ + zzip_version_t z_encoder; /* version made by */ + zzip_version_t z_extract; /* version need to extract */ + zzip_byte_t z_disk[4]; /* number of this disk */ + zzip_byte_t z_finaldisk[4]; /* number of the disk with the start of the central dir */ + zzip_byte_t z_entries[8]; /* total number of entries in the central dir on this disk */ + zzip_byte_t z_finalentries[8]; /* total number of entries in the central dir */ + zzip_byte_t z_rootsize[8]; /* size of the central directory */ + zzip_byte_t z_rootseek[8]; /* offset of start of central directory with respect to * + * the starting disk number */ + /* followed by zip64 extensible data sector (of variable size) */ +} ZZIP_GNUC_PACKED; +#define zzip_disk64_trailer_headerlength (4+8+2+2+4+4+8+8+8+8) + +/* z_flags */ +#define ZZIP_IS_ENCRYPTED(p) ((*(zzip_byte_t*)p)&1) +#define ZZIP_IS_COMPRLEVEL(p) (((*(zzip_byte_t*)p)>>1)&3) +#define ZZIP_IS_STREAMED(p) (((*(zzip_byte_t*)p)>>3)&1) +#define ZZIP_IS_PATCHED(p) (((*(zzip_byte_t*)p)>>5)&1) + +/* z_compr */ +#define ZZIP_IS_STORED 0 +#define ZZIP_IS_SHRUNK 1 +#define ZZIP_IS_REDUCEDx1 2 +#define ZZIP_IS_REDUCEDx2 3 +#define ZZIP_IS_REDUCEDx3 4 +#define ZZIP_IS_REDUCEDx4 5 +#define ZZIP_IS_IMPLODED 6 +#define ZZIP_IS_TOKENIZED 7 +#define ZZIP_IS_DEFLATED 8 +#define ZZIP_IS_DEFLATED_BETTER 9 +#define ZZIP_IS_IMPLODED_BETTER 10 + +/* deflated comprlevel */ +#define ZZIP_DEFLATED_STD_COMPR 0 +#define ZZIP_DEFLATED_MAX_COMPR 1 +#define ZZIP_DEFLATED_LOW_COMPR 2 +#define ZZIP_DEFLATED_MIN_COMPR 3 + +# ifdef _MSC_VER +# pragma pack(pop) +# endif + +#endif /* _ZZIPFORMAT_H */ + + + + diff --git a/project/jni/zzip/include/zzip/fseeko.h b/project/jni/zzip/include/zzip/fseeko.h new file mode 100644 index 000000000..9abade745 --- /dev/null +++ b/project/jni/zzip/include/zzip/fseeko.h @@ -0,0 +1,129 @@ +#ifndef _ZZIP_FSEEKO_H_ +#define _ZZIP_FSEEKO_H_ +/* + * NOTE: this is part of libzzipfseeko (i.e. it is not libzzip). + * + * simplified zip disk access using fseeko on a stdio FILE handle + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003,2004 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + + +#include +#include + +#ifdef _ZZIP_ENTRY_STRUCT +#include +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct zzip_entry ZZIP_ENTRY; +typedef struct zzip_entry_file ZZIP_ENTRY_FILE; + +typedef int (*zzip_strcmp_fn_t)(char*, char*); +typedef int (*zzip_fnmatch_fn_t)(char*, char*, int); + +#ifndef zzip_entry_extern +#define zzip_entry_extern extern +#endif + +zzip_entry_extern zzip_off_t +zzip_entry_data_offset(ZZIP_ENTRY* entry); + +zzip__new__ +zzip_entry_extern ZZIP_ENTRY* +zzip_entry_findfirst(FILE* file); + +zzip__new__ +zzip_entry_extern ZZIP_ENTRY* +zzip_entry_findnext(ZZIP_ENTRY* _zzip_restrict entry); + +#define zzip_entry_findlast zzip_entry_free +#define zzip_entry_findlastfile zzip_entry_free +#define zzip_entry_findlastmatch zzip_entry_free + +zzip_entry_extern int +zzip_entry_free(ZZIP_ENTRY* entry); + +zzip__new__ +zzip_entry_extern char* +zzip_entry_strdup_name(ZZIP_ENTRY* entry); +zzip_entry_extern char* +zzip_entry_to_data(ZZIP_ENTRY* entry); + +zzip__new__ +zzip_entry_extern ZZIP_ENTRY* +zzip_entry_findfile(FILE* disk, char* filename, + ZZIP_ENTRY* _zzip_restrict old, + zzip_strcmp_fn_t compare); +zzip__new__ +zzip_entry_extern ZZIP_ENTRY* +zzip_entry_findmatch(FILE* disk, char* filespec, + ZZIP_ENTRY* _zzip_restrict old, + zzip_fnmatch_fn_t compare, int flags); +zzip__new__ +zzip_entry_extern ZZIP_ENTRY_FILE* +zzip_entry_fopen (ZZIP_ENTRY* entry, int takeover); + +zzip__new__ +zzip_entry_extern ZZIP_ENTRY_FILE* +zzip_entry_ffile (FILE* disk, char* filename); + +zzip_entry_extern _zzip_size_t +zzip_entry_fread (void* ptr, _zzip_size_t size, _zzip_size_t nmemb, + ZZIP_ENTRY_FILE* file); +zzip_entry_extern int +zzip_entry_fclose (ZZIP_ENTRY_FILE* file); +int +zzip_entry_feof (ZZIP_ENTRY_FILE* file); + +# ifdef _ZZIP_ENTRY_STRUCT +# ifdef __cplusplus +# define __zzip_entry_extends_zzip_disk_entry +struct zzip_entry : public struct zzip_disk_entry +{ + char* _zzip_restrict tail; + zzip_off_t tailalloc; /* the allocated size of tail */ + FILE* diskfile; /* a file reference */ + zzip_off_t disksize; /* the size of the file */ + zzip_off_t headseek; /* the offset within the file */ + zzip_off_t zz_usize; + zzip_off_t zz_csize; /* items scanned from header */ + zzip_off_t zz_offset; /* or zip64 extension block */ + int zz_diskstart; +}; +# else +struct zzip_entry /* : struct zzip_disk_entry */ +{ + struct zzip_disk_entry head; + char* _zzip_restrict tail; + zzip_off_t tailalloc; /* the allocated size of tail */ + FILE* diskfile; /* a file reference */ + zzip_off_t disksize; /* the size of the file */ + zzip_off_t headseek; /* the offset within the file */ + zzip_off_t zz_usize; + zzip_off_t zz_csize; /* items scanned from header */ + zzip_off_t zz_offset; /* or zip64 extension block */ + int zz_diskstart; +}; +# endif /* __cplusplus */ +# endif /* _ZZIP_MEM_ENTRY_PRIVATE */ + +#ifdef __cplusplus +extern "C" { +} +#endif +#endif + diff --git a/project/jni/zzip/include/zzip/info.h b/project/jni/zzip/include/zzip/info.h new file mode 100644 index 000000000..0ab6edab5 --- /dev/null +++ b/project/jni/zzip/include/zzip/info.h @@ -0,0 +1,25 @@ +/* + * Author: + * Guido Draheim + * + * Copyright (c) 2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifdef ZZIP_USE_INTERNAL +/* do not make these public, they are for internal use only */ + +#define ZZIP_error(__dir) __dir->errcode +#define ZZIP_seterror(__dir, __code) __dir->errcode = __code +#define ZZIP_dirhandle(__fp) __fp->dir +#define ZZIP_dirfd(__dir) __dir->fd +#define ZZIP_dir_real(__dir) __dir->realdir != 0 +#define ZZIP_file_real(__fp) __fp->dir == 0 +#define ZZIP_realdir(__dir) __dir->realdir +#define ZZIP_reafd(__fp) __fp->fd + +#endif diff --git a/project/jni/zzip/include/zzip/lib.h b/project/jni/zzip/include/zzip/lib.h new file mode 100644 index 000000000..28b5311d6 --- /dev/null +++ b/project/jni/zzip/include/zzip/lib.h @@ -0,0 +1,91 @@ +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * This is the private header containing definitions that are not + * use by a libzzip user application. Writing an extension lib that + * uses libzzip will still want to include this. The extension + * write should make way to have the ISO C9X integer types defined. + */ +#ifndef _ZZIP_LIB_H /* zzip.h */ +#define _ZZIP_LIB_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * this structure cannot be wildly enlarged... (see zzip-zip.c) + */ +struct zzip_dir_hdr +{ + uint32_t d_usize; /* uncompressed size */ + uint32_t d_csize; /* compressed size */ + uint32_t d_crc32; /* the adler32-checksum */ + uint32_t d_off; /* offset of file in zipfile */ + uint16_t d_reclen; /* next dir_hdr structure offset */ + uint16_t d_namlen; /* explicit namelen of d_name */ + uint8_t d_compr; /* the compression type, 0 = store, 8 = inflate */ + char d_name[1]; /* the actual name of the entry, may contain DIRSEPs */ +}; +#define _ZZIP_DIRENT_HAVE_D_NAMLEN +#define _ZZIP_DIRENT_HAVE_D_OFF +#define _ZZIP_DIRENT_HAVE_D_RECLEN + +/* + * you shall not use this struct anywhere else than in zziplib sources. + */ +struct zzip_dir +{ + int fd; + int errcode; /* zzip_error_t */ + long refcount; + struct { /* reduce a lot of alloc/deallocations by caching these: */ + int * volatile locked; + struct zzip_file * volatile fp; + char * volatile buf32k; + } cache; + struct zzip_dir_hdr * hdr0; /* zfi; */ + struct zzip_dir_hdr * hdr; /* zdp; directory pointer, for dirent stuff */ + struct zzip_file * currentfp; /* last fp used... */ + struct zzip_dirent dirent; + void* realdir; /* e.g. DIR* from posix dirent.h */ + char* realname; + zzip_strings_t* fileext; /* list of fileext to test for */ + zzip_plugin_io_t io; /* vtable for io routines */ +}; + +#define ZZIP_32K 32768 + +/* try to open a zip-basename with default_fileext */ +int __zzip_try_open (zzip_char_t* filename, int filemode, + zzip_strings_t* ext, zzip_plugin_io_t io); + +ZZIP_DIR * +zzip_dir_fdopen(int fd, zzip_error_t * errcode_p); + +ZZIP_DIR* +zzip_dir_fdopen_ext_io(int fd, zzip_error_t * errorcode_p, + zzip_strings_t* ext, const zzip_plugin_io_t io); + +ZZIP_DIR* /*depracated*/ +zzip_dir_alloc_ext_io (zzip_strings_t* ext, const zzip_plugin_io_t io); + +#ifdef __cplusplus +} +#endif +#endif /* _ZZIP_H */ + diff --git a/project/jni/zzip/include/zzip/memdisk.h b/project/jni/zzip/include/zzip/memdisk.h new file mode 100644 index 000000000..2411f642c --- /dev/null +++ b/project/jni/zzip/include/zzip/memdisk.h @@ -0,0 +1,171 @@ +#ifndef __ZZIP_MEMDISK_H +#define __ZZIP_MEMDISK_H + +/* NOTE: this is part of libzzipmmapped (i.e. it is not libzzip). */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _zzip_mem_disk ZZIP_MEM_DISK; +typedef struct _zzip_mem_entry ZZIP_MEM_ENTRY; + +struct _zzip_mem_disk { + ZZIP_DISK* disk; + ZZIP_MEM_ENTRY* list; + ZZIP_MEM_ENTRY* last; +}; + +#ifndef zzip_mem_disk_extern +#define zzip_mem_disk_extern +#endif + +zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK* +zzip_mem_disk_new (void); +zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK* +zzip_mem_disk_open (char* filename); +zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK* +zzip_mem_disk_fdopen (int fd); +zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK * +zzip_mem_disk_buffer(char *buffer, size_t buflen); +zzip_mem_disk_extern void +zzip_mem_disk_close (ZZIP_MEM_DISK* _zzip_restrict dir); + +zzip_mem_disk_extern long +zzip_mem_disk_load (ZZIP_MEM_DISK* dir, ZZIP_DISK* disk); +zzip_mem_disk_extern void +zzip_mem_disk_unload (ZZIP_MEM_DISK* dir); +ZZIP_EXTRA_BLOCK* +zzip_mem_entry_extra_block (ZZIP_MEM_ENTRY* entry, short datatype); + +#ifdef USE_INLINE +_zzip_inline ZZIP_DISK* zzip_disk (ZZIP_MEM_DISK* dir) { return dir->disk; } +#else +#define zzip_disk(_X_) ((_X_)->disk) +#endif + + +/* these functions are much faster than the orgiinal zzip_disk_ functions */ + +/* zzip_mem_entry zzip_disk_entry */ +struct _zzip_mem_entry { + struct _zzip_mem_entry* zz_next; + char* zz_name; /* zero-terminated (from "filename") */ + zzip_byte_t* zz_data; /* compressed content start (mmap addr) */ + int zz_flags; /* (from "z_flags") */ + int zz_compr; /* (from "z_compr") */ + long zz_mktime; /* (from "z_dostime") */ + long zz_crc32; /* (from "z_crc32") */ + zzip_off_t zz_csize; /* (from "z_csize") overridden by zip64 */ + zzip_off_t zz_usize; /* (from "z_usize") overridden by zip64 */ + zzip_off_t zz_offset; /* (from "z_offset") overridden by zip64 */ + int zz_diskstart; /* (from "z_diskstart") rridden by zip64 */ + int zz_filetype; /* (from "z_filetype") */ + char* zz_comment; /* zero-terminated (from "comment") */ + ZZIP_EXTRA_BLOCK* zz_ext[3]; /* terminated by null in z_datatype */ +}; /* the extra blocks are NOT converted */ + +#define _zzip_mem_disk_findfirst(_d_) ((_d_)->list) +#define _zzip_mem_disk_findnext(_d_,_e_) (!(_e_)?(_d_)->list:(_e_)->zz_next) +#define _zzip_mem_entry_findnext(_e_) ((_e_)->zz_next) + +#ifndef USE_INLINE +#define zzip_mem_disk_findfirst _zzip_mem_disk_findfirst +#define zzip_mem_disk_findnext _zzip_mem_disk_findnext +#define zzip_mem_entry_findnext _zzip_mem_entry_findnext +#else + +_zzip_inline ZZIP_MEM_ENTRY* +zzip_mem_disk_findfirst(ZZIP_MEM_DISK* dir) { + if (! dir) return 0; + return _zzip_mem_disk_findfirst(dir); } +_zzip_inline ZZIP_MEM_ENTRY* +zzip_mem_disk_findnext(ZZIP_MEM_DISK* dir, ZZIP_MEM_ENTRY* entry) { + if (! dir) return 0; + return _zzip_mem_disk_findnext(dir, entry); } +_zzip_inline ZZIP_MEM_ENTRY* +zzip_mem_entry_findnext(ZZIP_MEM_ENTRY* entry) { + if (! entry) return 0; + return _zzip_mem_entry_findnext(entry); } +#endif + +#define _zzip_mem_entry_to_name(_e_) ((_e_)->zz_name) +#define _zzip_mem_entry_to_comment(_e_) ((_e_)->zz_comment) +#define _zzip_mem_entry_strdup_name(_e_) (strdup((_e_)->zz_name)) +#define _zzip_mem_entry_to_data(_e_) ((_e_)->zz_data) + +#ifndef USE_INLINE +#define zzip_mem_entry_to_name _zzip_mem_entry_to_name +#define zzip_mem_entry_to_comment _zzip_mem_entry_to_comment +#define zzip_mem_entry_strdup_name _zzip_mem_entry_strdup_name +#define zzip_mem_entry_to_data _zzip_mem_entry_to_data +#else +_zzip_inline char* +zzip_mem_entry_to_name(ZZIP_MEM_ENTRY* entry) { + if (! entry) return 0; + return _zzip_mem_entry_to_name(entry); } +_zzip_inline char* +zzip_mem_entry_to_comment(ZZIP_MEM_ENTRY* entry) { + if (! entry) return 0; + return _zzip_mem_entry_to_comment(entry); } +zzip__new__ +_zzip_inline char* +zzip_mem_entry_strdup_name(ZZIP_MEM_ENTRY* entry) { + if (! entry) return 0; + return _zzip_mem_entry_strdup_name(entry); } +_zzip_inline zzip_byte_t* +zzip_mem_entry_to_data(ZZIP_MEM_ENTRY* entry) { + if (! entry) return 0; + return _zzip_mem_entry_to_data(entry); } +#endif + +ZZIP_MEM_ENTRY* +zzip_mem_disk_findfile(ZZIP_MEM_DISK* dir, + char* filename, ZZIP_MEM_ENTRY* after, + zzip_strcmp_fn_t compare); + +ZZIP_MEM_ENTRY* +zzip_mem_disk_findmatch(ZZIP_MEM_DISK* dir, + char* filespec, ZZIP_MEM_ENTRY* after, + zzip_fnmatch_fn_t compare, int flags); + +/* named access -------------------------------------------------------- */ +#define zzip_mem_entry_usize(_e_) ((_e_)->zz_usize) +#define zzip_mem_entry_csize(_e_) ((_e_)->zz_csize) +#define zzip_mem_entry_data_encrypted(_e_) ZZIP_IS_ENCRYPTED((_e_)->zz_flags) +#define zzip_mem_entry_data_streamed(_e_) ZZIP_IS_STREAMED((_e_)->zz_flags) +#define zzip_mem_entry_data_comprlevel(_e_) ((_e_)->zz_compr) +#define zzip_mem_entry_data_stored(_e_) ((_e_)->zz_compr == ZZIP_IS_STORED) +#define zzip_mem_entry_data_deflated(_e_) ((_e_)->zz_compr == ZZIP_IS_DEFLATED) + +/* zzip_mem_disk_file -------------------------------------------------- */ + +/* since only the header data is being cached, all the real data + * operations are actually the same as in mmapped.h - just fopen makes + * access to the header data in memory instead of the zip archive. + */ + +typedef ZZIP_DISK_FILE ZZIP_MEM_DISK_FILE; + +zzip__new__ ZZIP_MEM_DISK_FILE* +zzip_mem_entry_fopen (ZZIP_MEM_DISK* dir, ZZIP_MEM_ENTRY* entry); +zzip__new__ ZZIP_MEM_DISK_FILE* +zzip_mem_disk_fopen (ZZIP_MEM_DISK* dir, char* filename); +_zzip_size_t +zzip_mem_disk_fread (void* ptr, _zzip_size_t size, _zzip_size_t nmemb, + ZZIP_MEM_DISK_FILE* file); +int +zzip_mem_disk_fclose (ZZIP_MEM_DISK_FILE* file); +int +zzip_mem_disk_feof (ZZIP_MEM_DISK_FILE* file); + +/* convert dostime of entry to unix time_t */ +long zzip_disk_entry_get_mktime(ZZIP_DISK_ENTRY* entry); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/project/jni/zzip/include/zzip/mmapped.h b/project/jni/zzip/include/zzip/mmapped.h new file mode 100644 index 000000000..ee2ba5ad8 --- /dev/null +++ b/project/jni/zzip/include/zzip/mmapped.h @@ -0,0 +1,138 @@ +#ifndef _ZZIP_MMAPPED_H_ +#define _ZZIP_MMAPPED_H_ +/* + * NOTE: this is part of libzzipmmapped (i.e. it is not libzzip). + * + * simplified zip disk access using a mmapping of the whole archive. + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003,2004 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + + +#include + +#ifdef _ZZIP_DISK_FILE_STRUCT +#include /* z_stream */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct zzip_disk_file ZZIP_DISK_FILE; +typedef struct zzip_disk ZZIP_DISK; +/* def struct zzip_disk_entry ZZIP_DISK_ENTRY; */ + +/* we expose this structure so third party applications can augment + * on them. The mmapped zip access usually just needs the two pointers + * specifying the mmapped area, whereever you have that from. + */ +struct zzip_disk +{ + zzip_byte_t* buffer; /* start of mmapped area, the base of all seekvals */ + zzip_byte_t* endbuf; /* end of mmapped area, i.e. buffer + buflen */ + void* reserved; /* - for later extensions (might be renamed) */ + void* user; /* - free for applications (use this!) */ + long flags; /* bit 0: findfile searches case-insensitive */ + long mapped; /* used for mmap() wrappers of zzip/__mmap.h */ + long unused; /* - for later extensions (might be renamed) */ + long code; /* - free for applications (use this!) */ +}; + +/* fnmatch search shall be case insensitive */ +#define ZZIP_DISK_FLAGS_MATCH_NOCASE 1 +#define ZZIP_DISK_FLAGS_OWNED_BUFFER 2 + +typedef int (*zzip_strcmp_fn_t)(char*, char*); +typedef int (*zzip_fnmatch_fn_t)(char*, char*, int); + +#define zzip_disk_extern extern + +zzip_disk_extern int +zzip_disk_init(ZZIP_DISK* disk, void* buffer, zzip_size_t buflen); + +zzip_disk_extern zzip__new__ ZZIP_DISK* +zzip_disk_new(void); + +zzip_disk_extern zzip__new__ ZZIP_DISK* +zzip_disk_mmap(int fd); + +zzip_disk_extern int +zzip_disk_munmap(ZZIP_DISK* disk); + +zzip_disk_extern zzip__new__ ZZIP_DISK* +zzip_disk_open(char* filename); + +zzip_disk_extern zzip__new__ ZZIP_DISK * +zzip_disk_buffer(void *buffer, size_t buflen); + +zzip_disk_extern int +zzip_disk_close(ZZIP_DISK* disk); + + +zzip_disk_extern ZZIP_DISK_ENTRY* +zzip_disk_findfirst(ZZIP_DISK* disk); + +zzip_disk_extern ZZIP_DISK_ENTRY* +zzip_disk_findnext(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); + +zzip_disk_extern zzip__new__ char* +zzip_disk_entry_strdup_name(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); +zzip_disk_extern zzip__new__ char* +zzip_disk_entry_strdup_comment(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); +zzip_disk_extern struct zzip_file_header* +zzip_disk_entry_to_file_header(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); +zzip_disk_extern zzip_byte_t* +zzip_disk_entry_to_data(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); + +zzip_disk_extern ZZIP_DISK_ENTRY* +zzip_disk_findfile(ZZIP_DISK* disk, + char* filename, ZZIP_DISK_ENTRY* after, + zzip_strcmp_fn_t compare); +zzip_disk_extern ZZIP_DISK_ENTRY* +zzip_disk_findmatch(ZZIP_DISK* disk, + char* filespec, ZZIP_DISK_ENTRY* after, + zzip_fnmatch_fn_t compare, int flags); + + +zzip_disk_extern zzip__new__ ZZIP_DISK_FILE* +zzip_disk_entry_fopen (ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); + +zzip_disk_extern zzip__new__ ZZIP_DISK_FILE* +zzip_disk_fopen (ZZIP_DISK* disk, char* filename); + +zzip_disk_extern _zzip_size_t +zzip_disk_fread (void* ptr, _zzip_size_t size, _zzip_size_t nmemb, + ZZIP_DISK_FILE* file); +zzip_disk_extern int +zzip_disk_fclose (ZZIP_DISK_FILE* file); +int +zzip_disk_feof (ZZIP_DISK_FILE* file); + +#ifdef _ZZIP_DISK_FILE_STRUCT +/** + * typedef struct zzip_disk_file ZZIP_DISK_FILE; + */ +struct zzip_disk_file +{ + zzip_byte_t* buffer; /* fopen disk->buffer */ + zzip_byte_t* endbuf; /* fopen disk->endbuf */ + zzip_size_t avail; /* memorized for checks on EOF */ + z_stream zlib; /* for inflated blocks */ + zzip_byte_t* stored; /* for stored blocks */ +}; +#endif + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/project/jni/zzip/include/zzip/plugin.h b/project/jni/zzip/include/zzip/plugin.h new file mode 100644 index 000000000..b6ccbe8a6 --- /dev/null +++ b/project/jni/zzip/include/zzip/plugin.h @@ -0,0 +1,96 @@ +/* + * Author: + * Guido Draheim + * + * Copyright (c) 2002,2003 Guido Draheim + * All rights reserved + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * the interfaces for the plugin_io system + * + * Using the following you can provide your own file I/O functions to + * e.g. read data directly from memory, provide simple + * "encryption"/"decryption" of on-disk .zip-files... + * Note that this currently only provides a subset of the functionality + * in zziplib. It does not attempt to provide any directory functions, + * but if your program 1) only uses ordinary on-disk files and you + * just want this for file obfuscation, or 2) you only access your + * .zip archives using zzip_open & co., this is sufficient. + * + * Currently the default io are the POSIX functions, except + * for 'filesize' that is zziplibs own provided zzip_filesize function, + * using standard POSIX fd's. You are however free to replace this with + * whatever data type you need, so long as you provide implementations + * for all the functions, and the data type fits an int. + * + * all functions receiving ext_io are able to cope with both arguments + * set to zero which will let them default to a ZIP ext and posix io. + */ +#ifndef _ZZIP_PLUGIN_H /* zzip-io.h */ +#define _ZZIP_PLUGIN_H 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* we have renamed zzip_plugin_io.use_mmap to zzip_plugin_io.sys */ +#define ZZIP_PLUGIN_IO_SYS 1 + +struct zzip_plugin_io { /* use "zzip_plugin_io_handlers" in applications !! */ + int (*open)(zzip_char_t* name, int flags, ...); + int (*close)(int fd); + zzip_ssize_t (*read)(int fd, void* buf, zzip_size_t len); + zzip_off_t (*seeks)(int fd, zzip_off_t offset, int whence); + zzip_off_t (*filesize)(int fd); + long sys; + long type; + zzip_ssize_t (*write)(int fd, _zzip_const void* buf, zzip_size_t len); +}; + +typedef union _zzip_plugin_io +{ + struct zzip_plugin_io fd; + struct { void* padding[8]; } ptr; +} zzip_plugin_io_handlers; + +#define _zzip_plugin_io_handlers zzip_plugin_io_handlers +/* for backward compatibility, and the following to your application code: + * #ifndef _zzip_plugin_io_handlers + * #define _zzip_plugin_io_handlers struct zzip_plugin_io + */ +typedef zzip_plugin_io_handlers* zzip_plugin_io_handlers_t; + +#ifdef ZZIP_LARGEFILE_RENAME +#define zzip_filesize zzip_filesize64 +#define zzip_get_default_io zzip_get_default_io64 +#define zzip_init_io zzip_init_io64 +#endif + +_zzip_export zzip_off_t +zzip_filesize(int fd); + +/* get the default file I/O functions */ +_zzip_export zzip_plugin_io_t zzip_get_default_io(void); + +/* + * Initializes a zzip_plugin_io_t to the zziplib default io. + * This is useful if you only want to override e.g. the 'read' function. + * all zzip functions that can receive a zzip_plugin_io_t can + * handle a zero pointer in that place and default to posix io. + */ +_zzip_export +int zzip_init_io(zzip_plugin_io_handlers_t io, int flags); + +/* zzip_init_io flags : */ +# define ZZIP_IO_USE_MMAP 1 + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/project/jni/zzip/include/zzip/stdint.h b/project/jni/zzip/include/zzip/stdint.h new file mode 100644 index 000000000..3310566c8 --- /dev/null +++ b/project/jni/zzip/include/zzip/stdint.h @@ -0,0 +1,45 @@ +#ifndef _ZZIP__STDINT_H /* zzip-stdint.h */ +#define _ZZIP__STDINT_H 1 +/* this file ensures that we have some kind of typedef declarations for + unsigned C9X typedefs. The ISO C 9X: 7.18 Integer types file is stdint.h + */ + +#include + +/* enforce use of ifdef'd C9X entries in system headers */ +#define __USE_ANSI 1 +#define __USE_ISOC9X 1 + +#ifdef ZZIP_HAVE_STDINT_H + /* ISO C 9X: 7.18 Integer types */ +#include +#elif defined ZZIP_HAVE_SYS_INT_TYPES_H /*solaris*/ +#include +#elif defined ZZIP_HAVE_INTTYPES_H /*freebsd*/ +#include +#else + typedef unsigned char uint8_t; typedef signed char int8_t; + +# if ZZIP_SIZEOF_INT && ZZIP_SIZEOF_INT == 2 + typedef unsigned int uint16_t; typedef signed int int16_t; +# elif ZZIP_SIZEOF_SHORT && ZZIP_SIZEOF_SHORT == 2 + typedef unsigned short uint16_t; typedef signed short int16_t; +# else +# error unable to typedef int16_t from either int or short + typedef unsigned short uint16_t; typedef signed short int16_t; +# endif + +# if defined ZZIP_SIZEOF_INT && ZZIP_SIZEOF_INT == 4 + typedef unsigned int uint32_t; typedef signed int int32_t; +# elif defined ZZIP_SIZEOF_LONG && ZZIP_SIZEOF_LONG == 4 + typedef unsigned long uint32_t; typedef signed long int32_t; +# else +# error unable to typedef int32_t from either int or long + typedef unsigned long uint32_t; typedef signed long int32_t; +# endif + +typedef unsigned _zzip___int64 uint64_t; typedef _zzip___int64 int64_t; +#endif + +#endif /*_ZZIP_STDINT_H*/ + diff --git a/project/jni/zzip/include/zzip/types.h b/project/jni/zzip/include/zzip/types.h new file mode 100644 index 000000000..6f9c6e6f9 --- /dev/null +++ b/project/jni/zzip/include/zzip/types.h @@ -0,0 +1,57 @@ +/* + * unlike in we are allowed to make up typedefs here, + * while over there only #defines are allowed + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003,2004 Guido Draheim + * All rights reserved, + * usage allowed under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * This file is usually the first to define some real symbols. If you do + * see some errors here then it is most likely the includepath is wrong + * or some includeheader is missing / unreadable on your system. + * (a) we include local headers with a "zzip/" prefix just to be sure + * to not actually get the wrong one. Consider to add `-I..` somewhere + * and especially VC/IDE users (who make up their own workspace files) + * should include the root source directory of this project. + * (b) size_t and ssize_t are sometimes found be `configure` but they are + * not in the usual places (ANSI C = stddef.h; UNIX = sys/types.h), so + * be sure to look for them and add the respective header as an #include. + */ + +#ifndef _ZZIP_TYPES_H_ +#define _ZZIP_TYPES_H_ + +#include +#include +#include /* size_t and friends */ +#ifdef ZZIP_HAVE_SYS_TYPES_H +#include /* bsd (mac) has size_t here */ +#endif +/* msvc6 has neither ssize_t (we assume "int") nor off_t (assume "long") */ + +typedef unsigned char zzip_byte_t; // especially zlib decoding data + +typedef _zzip_off64_t zzip_off64_t; +typedef _zzip_off_t zzip_off_t; +typedef _zzip_size_t zzip_size_t; /* Some error here? */ +typedef _zzip_ssize_t zzip_ssize_t; /* See notes above! */ + +/* in */ +typedef struct zzip_disk64_trailer ZZIP_DISK64_TRAILER; +typedef struct zzip_disk_trailer ZZIP_DISK_TRAILER; +typedef struct zzip_file_trailer ZZIP_FILE_TRAILER; +typedef struct zzip_root_dirent ZZIP_ROOT_DIRENT; +typedef struct zzip_file_header ZZIP_FILE_HEADER; +typedef struct zzip_disk_entry ZZIP_DISK_ENTRY; +typedef struct zzip_extra_block ZZIP_EXTRA_BLOCK; + + + +#endif + diff --git a/project/jni/zzip/include/zzip/write.h b/project/jni/zzip/include/zzip/write.h new file mode 100644 index 000000000..6db6b09ee --- /dev/null +++ b/project/jni/zzip/include/zzip/write.h @@ -0,0 +1,58 @@ +#ifndef _ZZIP_WRITE_H +#define _ZZIP_WRITE_H + +#include + +/* ........................................................................ + * write support is not yet implemented + * zzip/write.c + */ +#define ZZIP_NO_CREAT 1 + +ZZIP_DIR* zzip_dir_creat_ext_io(zzip_char_t* name, int o_mode, + zzip_strings_t* ext, zzip_plugin_io_t io); +ZZIP_DIR* zzip_dir_creat(zzip_char_t* name, int o_mode); +int zzip_file_mkdir(ZZIP_DIR* dir, zzip_char_t* name, int o_mode); +ZZIP_FILE* zzip_file_creat(ZZIP_DIR* dir, zzip_char_t* name, int o_mode); +zzip_ssize_t zzip_file_write(ZZIP_FILE* file, + const void* ptr, zzip_size_t len); + +ZZIP_DIR* zzip_createdir(zzip_char_t* name, int o_mode); +zzip_ssize_t zzip_write(ZZIP_FILE* file, const void* ptr, zzip_size_t len); +zzip_size_t zzip_fwrite(const void* ptr, zzip_size_t len, + zzip_size_t multiply, ZZIP_FILE* file); +#ifndef zzip_savefile +#define zzip_savefile 0 +#define zzip_savefile_is_null +#endif + +#ifdef _ZZIP_NO_INLINE +#define zzip_mkdir(_name_,_mode_) \ + zzip_file_mkdir((zzip_savefile),(_name_),(_mode_)) +#define zzip_creat(_name_,_mode_) \ + zzip_file_creat((zzip_savefile),(_name_),(_mode_)) +#define zzip_sync() \ + { zzip_closedir((zzip_savefile)); (zzip_savefile) = 0; } +#define zzip_start(_name_,_mode_,_ext_) \ + { if ((zzip_savefile)) zzip_closedir((zzip_savefile)); + zzip_savefile = zzip_dir_creat(_name_, _mode_,_ext_); } + +#else + +_zzip_inline static int zzip_mkdir(zzip_char_t* name, int o_mode) +{ return zzip_file_mkdir(zzip_savefile, name, o_mode); } +_zzip_inline static ZZIP_FILE* zzip_creat(zzip_char_t* name, int o_mode) +{ return zzip_file_creat(zzip_savefile, name, o_mode); } + +#ifndef zzip_savefile_is_null +_zzip_inline static void zzip_sync(void) +{ zzip_closedir(zzip_savefile); zzip_savefile = 0; } +_zzip_inline static void zzip_mkfifo(zzip_char_t* name, int o_mode) +{ if ((zzip_savefile)) zzip_closedir (zzip_savefile); + zzip_savefile = zzip_createdir(_name_,_mode_); } +#else +_zzip_inline static void zzip_sync(void) {} +_zzip_inline static void zzip_mkfifo(zzip_char_t* name, int o_mode) {} +#endif +#endif /* _ZZIP_NO_INLINE */ +#endif /* _ZZIP_WRITE_H */ diff --git a/project/jni/zzip/include/zzip/zzip.h b/project/jni/zzip/include/zzip/zzip.h new file mode 100644 index 000000000..f00a06865 --- /dev/null +++ b/project/jni/zzip/include/zzip/zzip.h @@ -0,0 +1,270 @@ +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002,2003,2004 Guido Draheim + * All rights reserved, + * usage allowed under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * if you see "unknown symbol" errors, check first that `-I ..` is part of + * your compiler options - a special hint to VC/IDE users who tend to make up + * their own workspace files. All includes look like #include , so + * you need to add an include path to the dir containing (!!) the ./zzip/ dir + */ + +#ifndef _ZZIP_ZZIP_H /* zziplib.h */ +#define _ZZIP_ZZIP_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* the zzip_error_t is also used to pass back ZLIB errors... */ +#define ZZIP_ERROR -4096 + +typedef enum +{ + ZZIP_NO_ERROR = 0, /* no error, may be used if user sets it. */ + ZZIP_OUTOFMEM = ZZIP_ERROR-20, /* out of memory */ + ZZIP_DIR_OPEN = ZZIP_ERROR-21, /* failed to open zipfile, see errno for details */ + ZZIP_DIR_STAT = ZZIP_ERROR-22, /* failed to fstat zipfile, see errno for details */ + ZZIP_DIR_SEEK = ZZIP_ERROR-23, /* failed to lseek zipfile, see errno for details */ + ZZIP_DIR_READ = ZZIP_ERROR-24, /* failed to read zipfile, see errno for details */ + ZZIP_DIR_TOO_SHORT = ZZIP_ERROR-25, + ZZIP_DIR_EDH_MISSING = ZZIP_ERROR-26, + ZZIP_DIRSIZE = ZZIP_ERROR-27, + ZZIP_ENOENT = ZZIP_ERROR-28, + ZZIP_UNSUPP_COMPR = ZZIP_ERROR-29, + ZZIP_CORRUPTED = ZZIP_ERROR-31, + ZZIP_UNDEF = ZZIP_ERROR-32, + ZZIP_DIR_LARGEFILE = ZZIP_ERROR-33 +} zzip_error_t; + +/* + * zzip_open flags. + */ +#define ZZIP_CASEINSENSITIVE O_APPEND /* do not use anymore. use CASLESS */ +#define ZZIP_IGNOREPATH O_TRUNC /* do not use anymore. use NOPATHS */ +#define ZZIP_EXTRAFLAGS (ZZIP_CASEINSENSITIVE|ZZIP_IGNOREPATH) + +/* zzip_open_ext_io o_modes flags : new style. use these from now on! */ +#define ZZIP_CASELESS (1<<12) /* ignore filename case inside zips */ +#define ZZIP_NOPATHS (1<<13) /* ignore subdir paths, just filename*/ +#define ZZIP_PREFERZIP (1<<14) /* try first zipped file, then real*/ +#define ZZIP_ONLYZIP (1<<16) /* try _only_ zipped file, skip real*/ +#define ZZIP_FACTORY (1<<17) /* old file handle is not closed */ +#define ZZIP_ALLOWREAL (1<<18) /* real files use default_io (magic) */ +#define ZZIP_THREADED (1<<19) /* try to be safe for multithreading */ + +/* + * zzip largefile renames + */ +#ifdef ZZIP_LARGEFILE_RENAME +#define zzip_telldir zzip_telldir64 +#define zzip_seekdir zzip_seekdir64 +#endif + +/* + * zzip typedefs + */ +/* zzip_strings_t ext[] = { ".zip", ".jar", ".pk3", 0 } */ +typedef char _zzip_const * _zzip_const zzip_strings_t; +typedef char _zzip_const zzip_char_t; +typedef struct zzip_dir ZZIP_DIR; +typedef struct zzip_file ZZIP_FILE; +typedef struct zzip_dirent ZZIP_DIRENT; +typedef struct zzip_dirent ZZIP_STAT; + +struct zzip_dirent +{ + int d_compr; /* compression method */ + int d_csize; /* compressed size */ + int st_size; /* file size / decompressed size */ + char * d_name; /* file name / strdupped name */ +}; + +/* + * Getting error strings + * zzip/err.c + */ +_zzip_export /* error in _opendir : */ +zzip_char_t* zzip_strerror(int errcode); +_zzip_export /* error in other functions : */ +zzip_char_t* zzip_strerror_of(ZZIP_DIR * dir); +_zzip_export /* error mapped to errno.h defines : */ +int zzip_errno(int errcode); + + +/* + * Functions to grab information from ZZIP_DIR/ZZIP_FILE structure + * (if ever needed) + * zzip/info.c + */ +_zzip_export +int zzip_error(ZZIP_DIR * dir); +_zzip_export +void zzip_seterror(ZZIP_DIR * dir, int errcode); +_zzip_export +zzip_char_t* zzip_compr_str(int compr); + +_zzip_export +ZZIP_DIR * zzip_dirhandle(ZZIP_FILE * fp); +_zzip_export +int zzip_dirfd(ZZIP_DIR * dir); +_zzip_export +int zzip_dir_real(ZZIP_DIR * dir); +_zzip_export +int zzip_file_real(ZZIP_FILE * fp); +_zzip_export +void* zzip_realdir(ZZIP_DIR * dir); +_zzip_export +int zzip_realfd(ZZIP_FILE * fp); + +/* + * zip handle management + * zzip/zip.c + */ +_zzip_export +ZZIP_DIR * zzip_dir_alloc(zzip_strings_t* fileext); +_zzip_export +int zzip_dir_free(ZZIP_DIR *); + +/* + * Opening/closing a zip archive + * zzip-zip.c + */ +_zzip_export +ZZIP_DIR * zzip_dir_fdopen(int fd, zzip_error_t * errcode_p); +_zzip_export +ZZIP_DIR * zzip_dir_open(zzip_char_t* filename, zzip_error_t * errcode_p); +_zzip_export +int zzip_dir_close(ZZIP_DIR * dir); +_zzip_export +int zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * dirent); + + +/* + * Scanning files in zip archive + * zzip/dir.c + * zzip/zip.c + */ +_zzip_export +ZZIP_DIR * zzip_opendir(zzip_char_t* filename); +_zzip_export +int zzip_closedir(ZZIP_DIR * dir); +_zzip_export +ZZIP_DIRENT * zzip_readdir(ZZIP_DIR * dir); +_zzip_export +void zzip_rewinddir(ZZIP_DIR * dir); +#ifndef ANDROID +_zzip_export +zzip_off_t zzip_telldir(ZZIP_DIR * dir); +_zzip_export +void zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset); +#endif + +/* + * 'opening', 'closing' and reading invidual files in zip archive. + * zzip/file.c + */ +_zzip_export +ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int flags); +_zzip_export +int zzip_file_close(ZZIP_FILE * fp); +_zzip_export +zzip_ssize_t zzip_file_read(ZZIP_FILE * fp, void* buf, zzip_size_t len); + +_zzip_export +ZZIP_FILE * zzip_open(zzip_char_t* name, int flags); +_zzip_export +int zzip_close(ZZIP_FILE * fp); +_zzip_export +zzip_ssize_t zzip_read(ZZIP_FILE * fp, void * buf, zzip_size_t len); + +/* + * the stdc variant to open/read/close files. - Take note of the freopen() + * call as it may reuse an existing preparsed copy of a zip central directory + */ +_zzip_export +ZZIP_FILE* zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*); +_zzip_export +ZZIP_FILE* zzip_fopen(zzip_char_t* name, zzip_char_t* mode); +_zzip_export +zzip_size_t zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, + ZZIP_FILE * file); +_zzip_export +int zzip_fclose(ZZIP_FILE * fp); + +/* + * seek and tell functions + */ +_zzip_export +int zzip_rewind(ZZIP_FILE *fp); +_zzip_export +zzip_off_t zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence); +_zzip_export +zzip_off_t zzip_tell(ZZIP_FILE * fp); + +/* + * reading info of a single file + * zzip/stat.c + */ +_zzip_export +int zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name, + ZZIP_STAT * zs, int flags); +_zzip_export +int zzip_file_stat(ZZIP_FILE * fp, ZZIP_STAT * zs); +_zzip_export +int zzip_fstat(ZZIP_FILE * fp, ZZIP_STAT * zs); + +#ifdef ZZIP_LARGEFILE_RENAME +#define zzip_open_shared_io zzip_open_shared_io64 +#define zzip_open_ext_io zzip_open_ext_io64 +#define zzip_opendir_ext_io zzip_opendir_ext_io64 +#define zzip_dir_open_ext_io zzip_dir_open_ext_io64 +#define zzip_plugin_io_t zzip_plugin_io64_t +#endif + +/* + * all ext_io functions can be called with a default of ext/io == zero/zero + * which will default to a ".zip" extension and posix io of the system. + */ +typedef union _zzip_plugin_io _zzip_const * zzip_plugin_io_t; + +_zzip_export +ZZIP_FILE * zzip_open_shared_io(ZZIP_FILE* stream, + zzip_char_t* name, int o_flags, int o_modes, + zzip_strings_t* ext, zzip_plugin_io_t io); + +_zzip_export +ZZIP_FILE * zzip_open_ext_io(zzip_char_t* name, int o_flags, int o_modes, + zzip_strings_t* ext, zzip_plugin_io_t io); + +_zzip_export +ZZIP_DIR * zzip_opendir_ext_io(zzip_char_t* name, int o_modes, + zzip_strings_t* ext, zzip_plugin_io_t io); + +_zzip_export +ZZIP_DIR * zzip_dir_open_ext_io(zzip_char_t* filename, + zzip_error_t* errcode_p, + zzip_strings_t* ext, zzip_plugin_io_t io); + +/* zzip_file_open_ext_io => zzip_dir_open_ext_io + zzip_file_open */ + +#ifdef __cplusplus +}; +#endif + +#endif /* _ZZIPLIB_H */ + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/include/zzip/zzip32.h b/project/jni/zzip/include/zzip/zzip32.h new file mode 100644 index 000000000..e63df2e26 --- /dev/null +++ b/project/jni/zzip/include/zzip/zzip32.h @@ -0,0 +1,53 @@ +/* + * Author: + * Guido Draheim + * + * Copyright (c) 2010 Guido Draheim + * All rights reserved, + * usage allowed under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * The compat32 headers is targeted towards those poor souls who can + * not compile their application or library with _LARGEFILE_SOURCE but + * they may still need to access a libzzip compiled in largefile mode. + * In that case they can change back to calling these suffix32 functions + * which are ensured to use "long" as the parameter type - just as it used + * to be before off_t was defined as an alias for it. + */ + +#ifndef _ZZIP_ZZIP32_H +#define _ZZIP_ZZIP32_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Scanning files in zip archive. + * Implemented in zzip/dir.c + */ +#ifndef ANDROID +_zzip_export +long zzip_telldir32(ZZIP_DIR * dir); +_zzip_export +void zzip_seekdir32(ZZIP_DIR * dir, long offset); + +/* + * seek and tell functions. + * Implemented in zzip/file.c + */ +_zzip_export +long zzip_seek32(ZZIP_FILE * fp, long offset, int whence); +_zzip_export +long zzip_tell32(ZZIP_FILE * fp); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/project/jni/zzip/zzip/SDL_rwops_zzip.c b/project/jni/zzip/zzip/SDL_rwops_zzip.c new file mode 100644 index 000000000..43a86491c --- /dev/null +++ b/project/jni/zzip/zzip/SDL_rwops_zzip.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001 Guido Draheim + * Use freely under the restrictions of the ZLIB License + * + * (this example uses errno which might not be multithreaded everywhere) + */ + +#include +#include +#include /* strchr */ + +/* MSVC can not take a casted variable as an lvalue ! */ +#define SDL_RWOPS_ZZIP_DATA(_context) \ + ((_context)->hidden.unknown.data1) +#define SDL_RWOPS_ZZIP_FILE(_context) (ZZIP_FILE*) \ + ((_context)->hidden.unknown.data1) + +static int __zzip_seek(SDL_RWops *context, int offset, int whence) +{ + return zzip_seek(SDL_RWOPS_ZZIP_FILE(context), offset, whence); +} + +static int __zzip_read(SDL_RWops *context, void *ptr, int size, int maxnum) +{ + return zzip_read(SDL_RWOPS_ZZIP_FILE(context), ptr, size*maxnum) / size; +} + +static int __zzip_write(SDL_RWops *context, const void *ptr, int size, int num) +{ + return 0; /* ignored */ +} + +static int __zzip_close(SDL_RWops *context) +{ + if (! context) return 0; /* may be SDL_RWclose is called by atexit */ + + zzip_close (SDL_RWOPS_ZZIP_FILE(context)); + SDL_FreeRW (context); + return 0; +} + +SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode) +{ + register SDL_RWops* rwops; + register ZZIP_FILE* zzip_file; + + if (! strchr (mode, 'r')) + return SDL_RWFromFile(file, mode); + + zzip_file = zzip_fopen (file, mode); + if (! zzip_file) return 0; + + rwops = SDL_AllocRW (); + if (! rwops) { errno=ENOMEM; zzip_close (zzip_file); return 0; } + + SDL_RWOPS_ZZIP_DATA(rwops) = zzip_file; + rwops->read = __zzip_read; + rwops->write = __zzip_write; + rwops->seek = __zzip_seek; + rwops->close = __zzip_close; + return rwops; +} diff --git a/project/jni/zzip/zzip/dir.c b/project/jni/zzip/zzip/dir.c new file mode 100644 index 000000000..4543801e9 --- /dev/null +++ b/project/jni/zzip/zzip/dir.c @@ -0,0 +1,334 @@ + +/* + * Author: + * Guido Draheim + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include /* exported... */ +#include +#include /*offsetof */ +#include +#include +#include + +#ifdef ZZIP_HAVE_SYS_STAT_H +#include +#else +#include +#endif + +#include + +#ifndef offsetof +#pragma warning had to DEFINE offsetof as it was not in stddef.h +#define offsetof(T,M) ((unsigned)(& ((T*)0)->M)) +#endif + +#ifdef ZZIP_HAVE_SYS_STAT_H + +/* MSVC does have IFbitmask but not the corresponding IStests */ +# if ! defined S_ISDIR && defined S_IFDIR +# define S_ISDIR(_X_) ((_X_) & S_IFDIR) +# endif +# if ! defined S_ISREG && defined S_IFREG +# define S_ISREG(_X_) ((_X_) & S_IFREG) +# endif +#endif + +/** + * This function is the equivalent of a => rewinddir(2) for a realdir or + * the zipfile in place of a directory. The ZZIP_DIR handle returned from + * => zzip_opendir has a flag saying realdir or zipfile. As for a zipfile, + * the filenames will include the filesubpath, so take care. + */ +void +zzip_rewinddir(ZZIP_DIR * dir) +{ + if (! dir) + return; + + if (USE_DIRENT && dir->realdir) + { + _zzip_rewinddir(dir->realdir); + return; + } + + if (dir->hdr0) + dir->hdr = dir->hdr0; + else + dir->hdr = 0; +} + +#if ! USE_DIRENT +#define real_readdir(_X_) 1 +#else +static int +real_readdir(ZZIP_DIR * dir) +{ + struct stat st = { 0 }; + char filename[PATH_MAX]; + struct dirent *dirent = _zzip_readdir(dir->realdir); + + if (! dirent) + return 0; + + dir->dirent.d_name = dirent->d_name; + strcpy(filename, dir->realname); + strcat(filename, "/"); + strcat(filename, dirent->d_name); + + if (stat(filename, &st) == -1) + return -1; + + dir->dirent.d_csize = dir->dirent.st_size = st.st_size; + + if (st.st_mode) + { + if (! S_ISREG(st.st_mode)) + { + dir->dirent.d_compr = st.st_mode; + dir->dirent.d_compr |= 0x80000000; + /* makes it effectively negative, + * but can still be fed to S_ISXXX(x) */ + } else + { + dir->dirent.d_compr = 0; /* stored */ + } + } else + { + dir->dirent.d_compr = 0; /* stored */ + } + + return 1; +} +#endif + +/** + * This function is the equivalent of a => readdir(2) for a realdir + * or a zipfile referenced by the ZZIP_DIR returned from => zzip_opendir. + * + * The ZZIP_DIR handle (as returned by => zzip_opendir) contains a few more + * entries than being copied into the ZZIP_DIRENT. The only valid fields in + * a ZZIP_DIRENT are d_name (the file name), d_compr (compression), d_csize + * (compressed size), st_size (uncompressed size). + */ +ZZIP_DIRENT * +zzip_readdir(ZZIP_DIR * dir) +{ + if (! dir) + { errno=EBADF; return 0; } + + if (USE_DIRENT && dir->realdir) + { + if (! real_readdir(dir)) + return 0; + } else + { + if (! dir->hdr) + return 0; + + dir->dirent.d_name = dir->hdr->d_name; + dir->dirent.d_compr = dir->hdr->d_compr; + + dir->dirent.d_csize = dir->hdr->d_csize; + dir->dirent.st_size = dir->hdr->d_usize; + + if (! dir->hdr->d_reclen) + dir->hdr = 0; + else + dir->hdr = (struct zzip_dir_hdr *) + ((char *) dir->hdr + dir->hdr->d_reclen); + } + return &dir->dirent; +} + +/** => zzip_rewinddir + * This function is the equivalent of => telldir(2) for a realdir or zipfile. + */ +#ifndef ANDROID +zzip_off_t +zzip_telldir(ZZIP_DIR * dir) +{ + if (! dir) + { errno=EBADF; return -1; } + + if (USE_DIRENT && dir->realdir) + { + return _zzip_telldir(dir->realdir); + } else + { + return ((zzip_off_t) ((char *) dir->hdr - (char *) dir->hdr0)); + } +} + +/** => zzip_rewinddir + * This function is the equivalent of => seekdir(2) for a realdir or zipfile. + */ +void +zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset) +{ + if (! dir) + return; + + if (USE_DIRENT && dir->realdir) + { + _zzip_seekdir(dir->realdir, offset); + } else + { + dir->hdr = (struct zzip_dir_hdr *) + (dir->hdr0 ? (char *) dir->hdr0 + (size_t) offset : 0); + } +} + +#ifndef EOVERFLOW +#define EOVERFLOW EFBIG +#endif + +/** => zzip_rewinddir + * This function is provided for users who can not use any largefile-mode. + */ +long +zzip_telldir32(ZZIP_DIR * dir) +{ + if (sizeof(zzip_off_t) == sizeof(long)) + { + return zzip_telldir(dir); + } else + { + off_t off = zzip_telldir(dir); + if (off >= 0) { + register long off32 = off; + if (off32 == off) return off32; + errno = EOVERFLOW; + } + return -1; + } +} + +/** => zzip_rewinddir + * This function is provided for users who can not use any largefile-mode. + */ +void +zzip_seekdir32(ZZIP_DIR * dir, long offset) +{ + zzip_seekdir(dir, offset); +} +#endif + +#if defined ZZIP_LARGEFILE_RENAME && defined EOVERFLOW && defined PIC +#undef zzip_seekdir /* zzip_seekdir64 */ +#undef zzip_telldir /* zzip_telldir64 */ + +/* DLL compatibility layer - so that 32bit code can link with a 64on32 too */ +long zzip_telldir(ZZIP_DIR * dir) { return zzip_telldir32(dir); } +void zzip_seekdir(ZZIP_DIR * dir, long offset) { zzip_seekdir32(dir, offset); } +#endif + +/** + * This function is the equivalent of => opendir(3) for a realdir or zipfile. + * + * This function has some magic - if the given argument-path + * is a directory, it will wrap a real => opendir(3) into the ZZIP_DIR + * structure. Otherwise it will divert to => zzip_dir_open which + * can also attach a ".zip" extension if needed to find the archive. + * + * the error-code is mapped to => errno(3). + */ +ZZIP_DIR * +zzip_opendir(zzip_char_t * filename) +{ + return zzip_opendir_ext_io(filename, 0, 0, 0); +} + +/** => zzip_opendir + * This function uses explicit ext and io instead of the internal + * defaults, setting them to zero is equivalent to => zzip_opendir + */ +ZZIP_DIR * +zzip_opendir_ext_io(zzip_char_t * filename, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + zzip_error_t e; + ZZIP_DIR *dir; + +# ifdef ZZIP_HAVE_SYS_STAT_H + struct stat st; +# endif + + if (o_modes & (ZZIP_PREFERZIP | ZZIP_ONLYZIP)) + goto try_zzip; + try_real: + +# ifdef ZZIP_HAVE_SYS_STAT_H + if (stat(filename, &st) >= 0 && S_ISDIR(st.st_mode)) + { + if (USE_DIRENT) + { + _zzip_DIR *realdir = _zzip_opendir(filename); + + if (realdir) + { + if (! (dir = (ZZIP_DIR *) calloc(1, sizeof(*dir)))) + { + _zzip_closedir(realdir); + return 0; + } else + { + dir->realdir = realdir; + dir->realname = strdup(filename); + return dir; + } + } + } + return 0; + } +# endif /* HAVE_SYS_STAT_H */ + + try_zzip: + dir = zzip_dir_open_ext_io(filename, &e, ext, io); + if (! dir && (o_modes & ZZIP_PREFERZIP)) + goto try_real; + if (e) + errno = zzip_errno(e); + return dir; +} + +/** + * This function is the equivalent of => closedir(3) for a realdir or zipfile. + * + * This function is magic - if the given arg-ZZIP_DIR + * is a real directory, it will call the real => closedir(3) and then + * free the wrapping ZZIP_DIR structure. Otherwise it will divert + * to => zzip_dir_close which will free the ZZIP_DIR structure. + */ +int +zzip_closedir(ZZIP_DIR * dir) +{ + if (! dir) + { errno = EBADF; return -1; } + + if (USE_DIRENT && dir->realdir) + { + _zzip_closedir(dir->realdir); + free(dir->realname); + free(dir); + return 0; + } else + { + zzip_dir_close(dir); + return 0; + } +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/err.c b/project/jni/zzip/zzip/err.c new file mode 100644 index 000000000..1ba869bd9 --- /dev/null +++ b/project/jni/zzip/zzip/err.c @@ -0,0 +1,168 @@ + +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include /* exported... */ +#include + +#include +#include + +#include + +/* *INDENT-OFF* */ +static struct errlistentry { int code; const char* mesg; } +errlist[] = +{ + { ZZIP_NO_ERROR, "No error" }, + { ZZIP_OUTOFMEM, + "could not get temporary memory for internal structures" }, + { ZZIP_DIR_OPEN, "Failed to open zip-file %s" }, + { ZZIP_DIR_STAT, "Failed to fstat zip-file %s" }, + { ZZIP_DIR_SEEK, "Failed to lseek zip-file %s" }, + { ZZIP_DIR_READ, "Failed to read zip-file %s"}, + { ZZIP_DIR_TOO_SHORT, "zip-file %s too short" }, + { ZZIP_DIR_EDH_MISSING, "zip-file central directory not found" }, + { ZZIP_DIRSIZE, "Directory size too big..." }, + { ZZIP_ENOENT, "No such file found in zip-file %s" }, + { ZZIP_UNSUPP_COMPR, "Unsupported compression format" }, + { ZZIP_CORRUPTED, "Zipfile corrupted" }, + { ZZIP_UNDEF, "Some undefined error occurred" }, + { ZZIP_DIR_LARGEFILE, "Directory is largefile variant" }, + { 0, 0 }, +}; +/* *INDENT-ON* */ + + +#define errlistSIZE (sizeof(errlist)/sizeof(*errlist)) + +/** + * returns the static string for the given error code. The + * error code can be either a normal system error (a + * positive error code will flag this), it can be => libz + * error code (a small negative error code will flag this) + * or it can be an error code from => libzzip, which is an + * negative value lower than => ZZIP_ERROR + */ +zzip_char_t * +zzip_strerror(int errcode) +{ + if (errcode < ZZIP_ERROR && errcode > ZZIP_ERROR - 32) + { + struct errlistentry *err = errlist; + + for (; err->mesg; err++) + { + if (err->code == errcode) + return err->mesg; + } + errcode = EINVAL; + } + + if (errcode < 0) + { + if (errcode == -1) + return strerror(errcode); + else + return zError(errcode); + } + + return strerror(errcode); +} + +/** => zzip_strerror + * This function fetches the errorcode from the => DIR-handle and + * runs it through => zzip_strerror to obtain the static string + * describing the error. + */ +zzip_char_t * +zzip_strerror_of(ZZIP_DIR * dir) +{ + if (! dir) + return strerror(errno); + return zzip_strerror(dir->errcode); +} + +/* *INDENT-OFF* */ +static struct errnolistentry { int code; int e_no; } +errnolist[] = +{ + { Z_STREAM_ERROR, EPIPE }, + { Z_DATA_ERROR, ESPIPE }, + { Z_MEM_ERROR, ENOMEM }, + { Z_BUF_ERROR, EMFILE }, + { Z_VERSION_ERROR, ENOEXEC }, + + { ZZIP_DIR_OPEN, ENOTDIR }, + { ZZIP_DIR_STAT, EREMOTE }, + { ZZIP_DIR_SEEK, ESPIPE }, +# ifdef ESTRPIPE + { ZZIP_DIR_READ, ESTRPIPE}, +# else + { ZZIP_DIR_READ, EPIPE}, +# endif + { ZZIP_DIR_TOO_SHORT, ENOEXEC }, +# ifdef ENOMEDIUM + { ZZIP_DIR_EDH_MISSING, ENOMEDIUM }, +# else + { ZZIP_DIR_EDH_MISSING, EIO }, +# endif + { ZZIP_DIRSIZE, EFBIG }, + { ZZIP_OUTOFMEM, ENOMEM }, + { ZZIP_ENOENT, ENOENT }, +# ifdef EPFNOSUPPORT + { ZZIP_UNSUPP_COMPR, EPFNOSUPPORT }, +# else + { ZZIP_UNSUPP_COMPR, EACCES }, +# endif +# ifdef EILSEQ + { ZZIP_CORRUPTED, EILSEQ }, +# else + { ZZIP_CORRUPTED, ELOOP }, +# endif + { ZZIP_UNDEF, EINVAL }, + { 0, 0 }, +}; +/* *INDENT-ON* */ + +/** + * map the error code to a system error code. This is used + * for the drop-in replacement functions to return a value + * that can be interpreted correctly by code sections that + * are unaware of the fact they their => open(2) call had been + * diverted to a file inside a zip-archive. + */ +int +zzip_errno(int errcode) +{ + if (errcode >= -1) + { + return errno; + } else + { + struct errnolistentry *err = errnolist; + + for (; err->code; err++) + { + if (err->code == errcode) + return err->e_no; + } + return EINVAL; + } +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/fetch.c b/project/jni/zzip/zzip/fetch.c new file mode 100644 index 000000000..bd1958483 --- /dev/null +++ b/project/jni/zzip/zzip/fetch.c @@ -0,0 +1,126 @@ + +/* + * These routines are helpers - note that this file gets linked into all the + * zip-access variants that refer to . On the x86 platform the + * actual definitions will be empty - fetching is done on native machine-level + * + * Author: + * Guido Draheim + * + * Copyright (c) 2004,2005,2006 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include + +/* ------------------------- fetch helpers --------------------------------- */ + +/** + * Make 32 bit value in host byteorder from little-endian mapped octet-data + * (works also on machines which SIGBUS on misaligned data access (eg. 68000)) + */ +uint32_t +__zzip_get32(unsigned char *s) +{ +#if defined __ZZIP_GET32 + return __ZZIP_GET32(s); +#else + return ((uint32_t) s[3] << 24) | ((uint32_t) s[2] << 16) + | ((uint32_t) s[1] << 8) | ((uint32_t) s[0]); +#endif +} + +/** => __zzip_get32 + * This function does the same for a 16 bit value. + */ +uint16_t +__zzip_get16(unsigned char *s) +{ +#if defined __ZZIP_GET16 + return __ZZIP_GET16(s); +#else + return ((uint16_t) s[1] << 8) | ((uint16_t) s[0]); +#endif +} + +/** => __zzip_get32 + * This function does the same for an off64_t value. + */ +uint64_t +__zzip_get64(unsigned char *s) +{ +#ifdef __GNUC__ + /* *INDENT-OFF* */ + register uint64_t v + = s[7]; v <<= 8; + v |= s[6]; v <<= 8; + v |= s[5]; v <<= 8; + v |= s[4]; v <<= 8; + v |= s[3]; v <<= 8; + v |= s[2]; v <<= 8; + v |= s[1]; v <<= 8; + v |= s[0]; return v; + /* *INDENT-ON* */ +#else + return ((uint64_t) s[7] << 56) | ((uint64_t) s[6] << 48) + | ((uint64_t) s[5] << 40) | ((uint64_t) s[4] << 32) + | ((uint64_t) s[3] << 24) | ((uint64_t) s[2] << 16) + | ((uint64_t) s[1] << 8) | ((uint64_t) s[0]); +#endif +} + +/** => __zzip_get32 + * This function pushes a 32bit value at the specified address + */ +void +__zzip_set32(unsigned char *s, uint32_t v) +{ +#if defined __ZZIP_SET32 + return __ZZIP_SET32(s, v); +#else + /* *INDENT-OFF* */ + s[0] = (unsigned char) (v); v >>= 8; + s[1] = (unsigned char) (v); v >>= 8; + s[2] = (unsigned char) (v); v >>= 8; + s[3] = (unsigned char) (v); + /* *INDENT-ON* */ +#endif +} + +/** => __zzip_get32 + * This function does the same for a 16 bit value. + */ +void +__zzip_set16(unsigned char *s, uint16_t v) +{ +#if defined __ZZIP_SET16 + return __ZZIP_SET16(s, v); +#else + /* *INDENT-OFF* */ + s[0] = (unsigned char) (v); v >>= 8; + s[1] = (unsigned char) (v); + /* *INDENT-ON* */ +#endif +} + +/** => __zzip_get32 + * This function pushes a off64_t value at the specified address + */ +void +__zzip_set64(unsigned char *s, uint64_t v) +{ + /* *INDENT-OFF* */ + s[0] = (unsigned char) (v); v >>= 8; + s[1] = (unsigned char) (v); v >>= 8; + s[2] = (unsigned char) (v); v >>= 8; + s[3] = (unsigned char) (v); v >>= 8; + s[4] = (unsigned char) (v); v >>= 8; + s[5] = (unsigned char) (v); v >>= 8; + s[6] = (unsigned char) (v); v >>= 8; + s[7] = (unsigned char) (v); + /* *INDENT-ON* */ +} diff --git a/project/jni/zzip/zzip/file.c b/project/jni/zzip/zzip/file.c new file mode 100644 index 000000000..37d72ed14 --- /dev/null +++ b/project/jni/zzip/zzip/file.c @@ -0,0 +1,1177 @@ + +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include /* exported... */ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#if 0 +# if defined ZZIP_HAVE_IO_H +# include /* tell */ +# else +# define tell(fd) lseek(fd,0,SEEK_CUR) +# endif +#else +#define tells(fd) seeks(fd,0,SEEK_CUR) +#endif + +/** + * the direct function of => zzip_close(fp). it will cleanup the + * inflate-portion of => zlib and free the structure given. + * + * it is called quite from the error-cleanup parts + * of the various => _open functions. + * + * the .refcount is decreased and if zero the fp->dir is closed just as well. + */ +int +zzip_file_close(ZZIP_FILE * fp) +{ + auto int self; + ZZIP_DIR *dir = fp->dir; + + if (fp->method) + inflateEnd(&fp->d_stream); /* inflateEnd() can be called many times */ + + if (dir->cache.locked == NULL) + dir->cache.locked = &self; + + if (fp->buf32k) + { + if (dir->cache.locked == &self && dir->cache.buf32k == NULL) + dir->cache.buf32k = fp->buf32k; + else + free(fp->buf32k); + } + + if (dir->currentfp == fp) + dir->currentfp = NULL; + + dir->refcount--; + /* ease to notice possible dangling reference errors */ + memset(fp, 0, sizeof(*fp)); + + if (dir->cache.locked == &self && dir->cache.fp == NULL) + dir->cache.fp = fp; + else + free(fp); + + if (dir->cache.locked == &self) + dir->cache.locked = NULL; + + if (! dir->refcount) + return zzip_dir_close(dir); + else + return 0; +} + + +static int +zzip_file_saveoffset(ZZIP_FILE * fp) +{ + if (fp) + { + int fd = fp->dir->fd; + zzip_off_t off = fp->io->fd.seeks(fd, 0, SEEK_CUR); + + if (off < 0) + return -1; + + fp->offset = off; + } + return 0; +} + + +/* user-definition */ +#ifndef ZZIP_BACKSLASH_DIRSEP +#if defined HAVE_WINDOWS_H || defined ZZIP_HAVE_WINDOWS_H || defined _WIN32 +#define ZZIP_BACKSLASH_DIRSEP 1 +#elif defined ZZIP_CHECK_BACKSLASH_DIRSEPARATOR +#define ZZIP_BACKSLASH_DIRSEP 1 +#else +#define ZZIP_BACKSLASH_DIRSEP 0 +#endif +#endif + +static zzip_char_t* +strrchr_basename(zzip_char_t* name) +{ + register zzip_char_t *n = strrchr(name, '/'); + if (n) return n + 1; + return name; +} + +static zzip_char_t* +dirsep_basename(zzip_char_t* name) +{ + register zzip_char_t *n = strrchr(name, '/'); + + if (ZZIP_BACKSLASH_DIRSEP) + { + register zzip_char_t *m = strrchr(name, '\\'); + if (!n || (m && n < m)) + n = m; + } + + if (n) return n + 1; + return name; +} + +#if defined strcasecmp +#define dirsep_strcasecmp strcasecmp +#else +static int +dirsep_strcasecmp(zzip_char_t * s1, zzip_char_t * s2) +{ + /* ASCII tolower - including mapping of backslash in normal slash */ + static const char mapping[] = "@abcdefghijklmnopqrstuvwxyz[/]^_"; + int c1, c2; + + while (*s1 && *s2) + { + c1 = (int) (unsigned char) *s1; + c2 = (int) (unsigned char) *s2; + if ((c1 & 0xE0) == 0x40) + c1 = mapping[c1 & 0x1f]; + if ((c2 & 0xE0) == 0x40) + c2 = mapping[c2 & 0x1f]; + if (c1 != c2) + return (c1 - c2); + s1++; + s2++; + } + + return (((int) (unsigned char) *s1) - ((int) (unsigned char) *s2)); +} +#endif + +static int zzip_inflate_init(ZZIP_FILE *, struct zzip_dir_hdr *); + +/** + * open an => ZZIP_FILE from an already open => ZZIP_DIR handle. Since + * we have a chance to reuse a cached => buf32k and => ZZIP_FILE memchunk + * this is the best choice to unpack multiple files. + * + * Note: the zlib supports 2..15 bit windowsize, hence we provide a 32k + * memchunk here... just to be safe. + * + * On error it returns null and sets errcode in the ZZIP_DIR. + */ +ZZIP_FILE * +zzip_file_open(ZZIP_DIR * dir, zzip_char_t * name, int o_mode) +{ + auto int self; + zzip_error_t err = 0; + struct zzip_file *fp = 0; + struct zzip_dir_hdr *hdr = dir->hdr0; + int (*filename_strcmp) (zzip_char_t *, zzip_char_t *); + zzip_char_t* (*filename_basename)(zzip_char_t*); + + filename_strcmp = (o_mode & ZZIP_CASELESS) ? dirsep_strcasecmp : strcmp; + filename_basename = (o_mode & ZZIP_CASELESS) ? dirsep_basename : strrchr_basename; + + if (! dir) + return NULL; + if (! dir->fd || dir->fd == -1) + { dir->errcode = EBADF; return NULL; } + if (! hdr) + { dir->errcode = ENOENT; return NULL; } + + if (o_mode & ZZIP_NOPATHS) + name = filename_basename(name); + + while (1) + { + register zzip_char_t *hdr_name = hdr->d_name; + + if (o_mode & ZZIP_NOPATHS) + hdr_name = filename_basename(hdr_name); + + HINT4("name='%s', compr=%d, size=%d\n", + hdr->d_name, hdr->d_compr, hdr->d_usize); + + if (! filename_strcmp(hdr_name, name)) + { + switch (hdr->d_compr) + { + case 0: /* store */ + case 8: /* inflate */ + break; + default: + { err = ZZIP_UNSUPP_COMPR; goto error; } + } + + if (dir->cache.locked == NULL) + dir->cache.locked = &self; + + if (dir->cache.locked == &self && dir->cache.fp) + { + fp = dir->cache.fp; + dir->cache.fp = NULL; + /* memset(zfp, 0, sizeof *fp); cleared in zzip_file_close() */ + } else + { + if (! (fp = (ZZIP_FILE *) calloc(1, sizeof(*fp)))) + { err = ZZIP_OUTOFMEM; goto error; } + } + + fp->dir = dir; + fp->io = dir->io; + dir->refcount++; + + if (dir->cache.locked == &self && dir->cache.buf32k) + { + fp->buf32k = dir->cache.buf32k; + dir->cache.buf32k = NULL; + } else + { + if (! (fp->buf32k = (char *) malloc(ZZIP_32K))) + { err = ZZIP_OUTOFMEM; goto error; } + } + + if (dir->cache.locked == &self) + dir->cache.locked = NULL; + /* + * In order to support simultaneous open files in one zip archive + * we'll fix the fd offset when opening new file/changing which + * file to read... + */ + + if (zzip_file_saveoffset(dir->currentfp) < 0) + { err = ZZIP_DIR_SEEK; goto error; } + + fp->offset = hdr->d_off; + dir->currentfp = fp; + + if (dir->io->fd.seeks(dir->fd, hdr->d_off, SEEK_SET) < 0) + { err = ZZIP_DIR_SEEK; goto error; } + + { + /* skip local header - should test tons of other info, + * but trust that those are correct */ + zzip_ssize_t dataoff; + struct zzip_file_header *p = (void *) fp->buf32k; + + dataoff = dir->io->fd.read(dir->fd, (void *) p, sizeof(*p)); + if (dataoff < (zzip_ssize_t) sizeof(*p)) + { err = ZZIP_DIR_READ; goto error; } + if (! zzip_file_header_check_magic(p)) /* PK\3\4 */ + { err = ZZIP_CORRUPTED; goto error; } + + dataoff = zzip_file_header_sizeof_tail(p); + + if (dir->io->fd.seeks(dir->fd, dataoff, SEEK_CUR) < 0) + { err = ZZIP_DIR_SEEK; goto error; } + + fp->dataoffset = dir->io->fd.tells(dir->fd); + fp->usize = hdr->d_usize; + fp->csize = hdr->d_csize; + } + + err = zzip_inflate_init(fp, hdr); + if (err) + goto error; + + return fp; + } else + { + if (hdr->d_reclen == 0) + break; + hdr = (struct zzip_dir_hdr *) ((char *) hdr + hdr->d_reclen); + } /*filename_strcmp */ + } /*forever */ + dir->errcode = ZZIP_ENOENT; + return NULL; + error: + if (fp) + zzip_file_close(fp); + dir->errcode = err; + return NULL; +} + +/** + * call => inflateInit and setup fp's iterator variables, + * used by lowlevel => _open functions. + */ +static int +zzip_inflate_init(ZZIP_FILE * fp, struct zzip_dir_hdr *hdr) +{ + int err; + + fp->method = hdr->d_compr; + fp->restlen = hdr->d_usize; + + if (fp->method) + { + memset(&fp->d_stream, 0, sizeof(fp->d_stream)); + + err = inflateInit2(&fp->d_stream, -MAX_WBITS); + if (err != Z_OK) + goto error; + + fp->crestlen = hdr->d_csize; + } + return 0; + error: + if (fp) + zzip_file_close(fp); + return err; +} + +/** + * This function closes the given ZZIP_FILE handle. + * + * If the ZZIP_FILE wraps a normal stat'fd then it is just that int'fd + * that is being closed and the otherwise empty ZZIP_FILE gets freed. + */ +int +zzip_fclose(ZZIP_FILE * fp) +{ + if (! fp) + return 0; + if (! fp->dir) /* stat fd */ + { int r = fp->io->fd.close(fp->fd); free(fp); return r; } + else + return zzip_file_close(fp); +} + +/** => zzip_fclose + */ +int +zzip_close(ZZIP_FILE * fp) +{ + return zzip_fclose(fp); +} + +/** + * This functions read data from zip-contained file. + * + * It works like => read(2) and will fill the given buffer with bytes from + * the opened file. It will return the number of bytes read, so if the => EOF + * is encountered you will be prompted with the number of bytes actually read. + * + * This is the routines that needs the => buf32k buffer, and it would have + * need for much more polishing but it does already work quite well. + * + * Note: the 32K buffer is rather big. The original inflate-algorithm + * required just that but the latest zlib would work just fine with + * a smaller buffer. + */ +zzip_ssize_t +zzip_file_read(ZZIP_FILE * fp, void *buf, zzip_size_t len) +{ + ZZIP_DIR *dir; + zzip_size_t l; + zzip_ssize_t rv; + + if (! fp || ! fp->dir) + return 0; + + dir = fp->dir; + l = fp->restlen > len ? len : fp->restlen; + if (fp->restlen == 0) + return 0; + + /* + * If this is other handle than previous, save current seek pointer + * and read the file position of `this' handle. + */ + if (dir->currentfp != fp) + { + if (zzip_file_saveoffset(dir->currentfp) < 0 + || fp->io->fd.seeks(dir->fd, fp->offset, SEEK_SET) < 0) + { dir->errcode = ZZIP_DIR_SEEK; return -1; } + else + { dir->currentfp = fp; } + } + + /* if more methods is to be supported, change this to `switch ()' */ + if (fp->method) /* method != 0 == 8, inflate */ + { + fp->d_stream.avail_out = l; + fp->d_stream.next_out = (unsigned char *) buf; + + do + { + int err; + zzip_size_t startlen; + + if (fp->crestlen > 0 && fp->d_stream.avail_in == 0) + { + zzip_size_t cl = (fp->crestlen < ZZIP_32K ? + fp->crestlen : ZZIP_32K); + /* zzip_size_t cl = + * fp->crestlen > 128 ? 128 : fp->crestlen; + */ + zzip_ssize_t i = fp->io->fd.read(dir->fd, fp->buf32k, cl); + + if (i <= 0) + { + dir->errcode = ZZIP_DIR_READ; + /* or ZZIP_DIR_READ_EOF ? */ + return -1; + } + fp->crestlen -= i; + fp->d_stream.avail_in = i; + fp->d_stream.next_in = (unsigned char *) fp->buf32k; + } + + startlen = fp->d_stream.total_out; + err = inflate(&fp->d_stream, Z_NO_FLUSH); + + if (err == Z_STREAM_END) + { fp->restlen = 0; } + else if (err == Z_OK) + { fp->restlen -= (fp->d_stream.total_out - startlen); } + else + { dir->errcode = err; return -1; } + } + while (fp->restlen && fp->d_stream.avail_out); + + return l - fp->d_stream.avail_out; + } else + { /* method == 0 -- unstore */ + rv = fp->io->fd.read(dir->fd, buf, l); + if (rv > 0) + { fp->restlen-= rv; } + else if (rv < 0) + { dir->errcode = ZZIP_DIR_READ; } + return rv; + } +} + +/** + * This function will read(2) data from a real/zipped file. + * + * the replacement for => read(2) will fill the given buffer with bytes from + * the opened file. It will return the number of bytes read, so if the EOF + * is encountered you will be prompted with the number of bytes actually read. + * + * If the file-handle is wrapping a stat'able file then it will actually just + * perform a normal => read(2)-call, otherwise => zzip_file_read is called + * to decompress the data stream and any error is mapped to => errno(3). + */ +zzip_ssize_t +zzip_read(ZZIP_FILE * fp, void *buf, zzip_size_t len) +{ + if (! fp) + return 0; + if (! fp->dir) + { return fp->io->fd.read(fp->fd, buf, len); } /* stat fd */ + else + { + register zzip_ssize_t v; + + v = zzip_file_read(fp, buf, len); + if (v == -1) + { errno = zzip_errno(fp->dir->errcode); } + return v; + } +} + +/** => zzip_read + */ +zzip_size_t +zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, ZZIP_FILE * file) +{ + if (! size) + size = 1; + return zzip_read(file, ptr, size * nmemb) / size; +} + + +#define ZZIP_WRONLY O_WRONLY +#define ZZIP_EXCL O_EXCL + +#if defined O_SYNC +#define ZZIP_SYNC O_SYNC +#else +#define ZZIP_SYNC 0 +#endif + +#if defined O_NONBLOCK +#define ZZIP_NONBLOCK O_NONBLOCK +#elif defined O_NDELAY +#define ZZIP_NOCTTY O_NDELAY +#else +#define ZZIP_NOCTTY 0 +#endif + +/* ------------------------------------------------------------------- */ + +/** also: fopen(2) + * This function will => fopen(3) a real/zipped file. + * + * It has some magic functionality builtin - it will first try to open + * the given filename as a normal file. If it does not + * exist, the given path to the filename (if any) is split into + * its directory-part and the file-part. A ".zip" extension is + * then added to the directory-part to create the name of a + * zip-archive. That zip-archive (if it exists) is being searched + * for the file-part, and if found a zzip-handle is returned. + * + * Note that if the file is found in the normal fs-directory the + * returned structure is mostly empty and the => zzip_read call will + * use the libc => read(2) to obtain data. Otherwise a => zzip_file_open + * is performed and any error mapped to => errno(3). + * + * unlike the posix-wrapper => zzip_open the mode-argument is + * a string which allows for more freedom to support the extra + * zzip modes called ZZIP_CASEINSENSITIVE and ZZIP_IGNOREPATH. + * Currently, this => zzip_fopen call will convert the following + * characters in the mode-string into their corrsponding mode-bits: + * * "r" : O_RDONLY : read-only + * * "b" : O_BINARY : binary (win32 specific) + * * "f" : O_NOCTTY : no char device (unix) + * * "i" : ZZIP_CASELESS : inside zip file + * * "*" : ZZIP_NOPATHS : inside zip file only + * all other modes will be ignored for zip-contained entries + * but they are transferred for compatibility and portability, + * including these extra sugar bits: + * * "x" : O_EXCL : fail if file did exist + * * "s" : O_SYNC : synchronized access + * * "n" : O_NONBLOCK : nonblocking access + * * "z#" : compression level : for zlib + * * "g#" : group access : unix access bits + * * "u#" : owner access : unix access bits + * * "o#" : world access : unix access bits + * ... the access bits are in traditional unix bit format + * with 7 = read/write/execute, 6 = read/write, 4 = read-only. + * + * The default access mode is 0664, and the compression level + * is ignored since the lib can not yet write zip files, otherwise + * it would be the initialisation value for the zlib deflateInit + * where 0 = no-compression, 1 = best-speed, 9 = best-compression. + * + * This function returns a new zzip-handle (use => zzip_close to return + * it). On error this function will return null setting => errno(3). + */ +ZZIP_FILE * +zzip_fopen(zzip_char_t * filename, zzip_char_t * mode) +{ + return zzip_freopen(filename, mode, 0); +} + +/** => zzip_fopen + * + * This function receives an additional argument pointing to + * a ZZIP_FILE* being already in use. If this extra argument is + * null then this function is identical with calling => zzip_fopen + * + * Per default, the old file stream is closed and only the internal + * structures associated with it are kept. These internal structures + * may be reused for the return value, and this is a lot quicker when + * the filename matches a zipped file that is incidently in the very + * same zip arch as the old filename wrapped in the stream struct. + * + * That's simply because the zip arch's central directory does not + * need to be read again. As an extension for this function, if the + * mode-string contains a "q" then the old stream is not closed but + * left untouched, instead it is only given as a hint that a new + * file handle may share/copy the zip arch structures of the old file + * handle if that is possible, i.e when they are in the same zip arch. + * + * This function returns a new zzip-handle (use => zzip_close to return + * it). On error this function will return null setting => errno(3). + */ +ZZIP_FILE * +zzip_freopen(zzip_char_t * filename, zzip_char_t * mode, ZZIP_FILE * stream) +{ + int o_flags = 0; + int o_modes = 0664; + + if (! mode) + mode = "rb"; + +# ifndef O_BINARY +# define O_BINARY 0 +# endif +# ifndef O_NOCTTY +# define O_NOCTTY 0 +# endif +# ifndef O_SYNC +# define O_SYNC 0 +# endif +# ifndef O_NONBLOCK +# define O_NONBLOCK 0 +# endif + + for (; *mode; mode++) + { + switch (*mode) + { + /* *INDENT-OFF* */ + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; /* ignore if not attached to other info */ + case 'r': o_flags |= mode[1] == '+' ? O_RDWR : O_RDONLY; break; + case 'w': o_flags |= mode[1] == '+' ? O_RDWR : O_WRONLY; + o_flags |= O_TRUNC; break; + case 'b': o_flags |= O_BINARY; break; + case 'f': o_flags |= O_NOCTTY; break; + case 'i': o_modes |= ZZIP_CASELESS; break; + case '*': o_modes |= ZZIP_NOPATHS; break; + case 'x': o_flags |= O_EXCL; break; + case 's': o_flags |= O_SYNC; break; + case 'n': o_flags |= O_NONBLOCK; break; + case 'o': o_modes &=~ 07; + o_modes |= ((mode[1] - '0')) & 07; continue; + case 'g': o_modes &=~ 070; + o_modes |= ((mode[1] - '0') << 3) & 070; continue; + case 'u': o_modes &=~ 0700; + o_modes |= ((mode[1] - '0') << 6) & 0700; continue; + case 'q': o_modes |= ZZIP_FACTORY; break; + case 'z': /* compression level */ + continue; /* currently ignored, just for write mode */ + /* *INDENT-ON* */ + } + } + + { + ZZIP_FILE *fp = + zzip_open_shared_io(stream, filename, o_flags, o_modes, 0, 0); + + if (! (o_modes & ZZIP_FACTORY) && stream) + zzip_file_close(stream); + + return fp; + } +} + +/** + * This function will => open(2) a real/zipped file + * + * It has some magic functionality builtin - it will first try to open + * the given filename as a normal file. If it does not + * exist, the given path to the filename (if any) is split into + * its directory-part and the file-part. A ".zip" extension is + * then added to the directory-part to create the name of a + * zip-archive. That zip-archive (if it exists) is being searched + * for the file-part, and if found a zzip-handle is returned. + * + * Note that if the file is found in the normal fs-directory the + * returned structure is mostly empty and the => zzip_read call will + * use the libc => read(2) to obtain data. Otherwise a => zzip_file_open + * is performed and any error mapped to => errno(3). + * + * There was a possibility to transfer zziplib-specific openmodes + * through o_flags but you should please not use them anymore and + * look into => zzip_open_ext_io to submit them down. This function + * is shallow in that it just extracts the zzipflags and calls + * * zzip_open_ext_io(filename, o_flags, zzipflags|0664, 0, 0) + * you must stop using this extra functionality (not well known anyway) + * since zzip_open might be later usable to open files for writing + * in which case the _EXTRAFLAGS will get in conflict. + * + * compare with => open(2) and => zzip_fopen + */ +ZZIP_FILE * +zzip_open(zzip_char_t * filename, int o_flags) +{ + /* backward compatibility */ + int o_modes = 0664; + + if (o_flags & ZZIP_CASEINSENSITIVE) + { o_flags ^= ZZIP_CASEINSENSITIVE; o_modes |= ZZIP_CASELESS; } + if (o_flags & ZZIP_IGNOREPATH) + { o_flags ^= ZZIP_IGNOREPATH; o_modes |= ZZIP_NOPATHS; } + return zzip_open_ext_io(filename, o_flags, o_modes, 0, 0); +} + +/* ZZIP_ONLYZIP won't work on platforms with sizeof(int) == 16bit */ +#if ZZIP_SIZEOF_INT+0 == 2 +#undef ZZIP_ONLYZIP +#endif + +/** => zzip_open + * + * This function uses explicit ext and io instead of the internal + * defaults, setting them to zero is equivalent to => zzip_open + * + * note that the two flag types have been split into an o_flags + * (for fcntl-like openflags) and o_modes where the latter shall + * carry the zzip_flags and possibly accessmodes for unix filesystems. + * Since this version of zziplib can not write zipfiles, it is not + * yet used for anything else than zzip-specific modeflags. + * + * This function returns a new zzip-handle (use => zzip_close to return + * it). On error this function will return null setting => errno(3). + */ +ZZIP_FILE * +zzip_open_ext_io(zzip_char_t * filename, int o_flags, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + return zzip_open_shared_io(0, filename, o_flags, o_modes, ext, io); +} + +/** => zzip_open + * + * This function takes an extra stream argument - if a handle has been + * then ext/io can be left null and the new stream handle will pick up + * the ext/io. This should be used only in specific environment however + * since => zzip_file_real does not store any ext-sequence. + * + * The benefit for this function comes in when the old file handle + * was openened from a file within a zip archive. When the new file + * is in the same zip archive then the internal zzip_dir structures + * will be shared. It is even quicker, as no check needs to be done + * anymore trying to guess the zip archive place in the filesystem, + * here we just check whether the zip archive's filepath is a prefix + * part of the filename to be opened. + * + * Note that this function is also used by => zzip_freopen that + * will unshare the old handle, thereby possibly closing the handle. + * + * This function returns a new zzip-handle (use => zzip_close to return + * it). On error this function will return null setting => errno(3). + */ +ZZIP_FILE * +zzip_open_shared_io(ZZIP_FILE * stream, + zzip_char_t * filename, int o_flags, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + if (stream && stream->dir) + { + if (! ext) + ext = stream->dir->fileext; + if (! io) + io = stream->dir->io; + } + if (! io) + io = zzip_get_default_io(); + + if (o_modes & (ZZIP_PREFERZIP | ZZIP_ONLYZIP)) + goto try_zzip; + try_real: + /* prefer an existing real file */ + { + zzip_plugin_io_t os = (o_modes & ZZIP_ALLOWREAL) + ? zzip_get_default_io() : io; + int fd = os->fd.open(filename, o_flags); /* io->fd.open */ + + if (fd != -1) + { + ZZIP_FILE *fp = calloc(1, sizeof(ZZIP_FILE)); + + if (! fp) + { os->fd.close(fd); return 0; } /* io->fd.close */ + + fp->fd = fd; + fp->io = os; + return fp; + } + if (o_modes & ZZIP_PREFERZIP) + return 0; + } + try_zzip: + + /* if the user had it in place of a normal xopen, then + * we better defend this lib against illegal usage */ + if (o_flags & (O_CREAT | O_WRONLY)) + { errno = EINVAL; return 0; } + if (o_flags & (O_RDWR)) + { o_flags ^= O_RDWR; o_flags |= O_RDONLY; } + + /* this is just for backward compatibility -and strictly needed to + * prepare ourselves for more options and more options later on... */ + /*# if (o_modes & ZZIP_CASELESS) { o_flags |= ZZIP_CASEINSENSITIVE; } */ + /*# if (o_modes & ZZIP_NOPATHS) { o_flags |= ZZIP_IGNOREPATH; } */ + + /* see if we can open a file that is a zip file */ + { + char basename[PATH_MAX]; + char *p; + int filename_len = strlen(filename); + + if (filename_len >= PATH_MAX) + { errno = ENAMETOOLONG; return 0; } + memcpy(basename, filename, filename_len + 1); + + /* see if we can share the same zip directory */ + if (stream && stream->dir && stream->dir->realname) + { + zzip_size_t len = strlen(stream->dir->realname); + + if (! memcmp(filename, stream->dir->realname, len) && + filename[len] == '/' && filename[len + 1]) + { + ZZIP_FILE *fp = + zzip_file_open(stream->dir, filename + len + 1, o_modes); + if (! fp) + { errno = zzip_errno (stream->dir->errcode); } + return fp; + } + } + + /* per each slash in filename, check if it there is a zzip around */ + while ((p = strrchr(basename, '/'))) + { + zzip_error_t e = 0; + ZZIP_DIR *dir; + ZZIP_FILE *fp; + int fd; + + *p = '\0'; + /* i.e. cut at path separator == possible zipfile basename */ + fd = __zzip_try_open(basename, o_flags | O_RDONLY | O_BINARY, + ext, io); + if (fd == -1) + { continue; } + + /* found zip-file .... now try to parse it */ + dir = zzip_dir_fdopen_ext_io(fd, &e, ext, io); + if (e) + { errno = zzip_errno(e); io->fd.close(fd); return 0; } + + /* (p - basename) is the lenghtof zzip_dir part of the filename */ + fp = zzip_file_open(dir, filename + (p - basename) + 1, o_modes); + if (! fp) + { errno = zzip_errno(dir->errcode); } + else + { if (! dir->realname) dir->realname = strdup (basename); } + + zzip_dir_close(dir); + /* note: since (fp) is attached that (dir) will survive */ + /* but (dir) is implicitly closed on next zzip_close(fp) */ + + return fp; + } + + if (o_modes & ZZIP_PREFERZIP) + goto try_real; + else + { errno = ENOENT; return 0; } + } +} + +#if defined ZZIP_LARGEFILE_RENAME && defined EOVERFLOW && defined PIC +#undef zzip_open_shared_io /* zzip_open_shared_io64 */ +#undef zzip_open_ext_io /* zzip_open_ext_io64 */ +#undef zzip_opendir_ext_io /* zzip_opendir_ext_io64 */ + +ZZIP_FILE *zzip_open_shared_io(ZZIP_FILE * stream, + zzip_char_t * name, int o_flags, + int o_modes, zzip_strings_t * ext, + zzip_plugin_io_t io); +ZZIP_FILE *zzip_open_ext_io(zzip_char_t * name, int o_flags, + int o_modes, zzip_strings_t * ext, + zzip_plugin_io_t io); +ZZIP_DIR *zzip_opendir_ext_io(zzip_char_t * name, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io); + +/* DLL compatibility layer - so that 32bit code can link with this lib too */ + +ZZIP_FILE * +zzip_open_shared_io(ZZIP_FILE * stream, + zzip_char_t * name, int o_flags, + int o_modes, zzip_strings_t * ext, zzip_plugin_io_t io) +{ + if (! io) + return zzip_open_shared_io64(stream, name, o_flags, o_modes, ext, io); + errno = EOVERFLOW; + return NULL; +} + +ZZIP_FILE * +zzip_open_ext_io(zzip_char_t * name, int o_flags, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + if (! io) + return zzip_open_ext_io64(name, o_flags, o_modes, ext, io); + errno = EOVERFLOW; + return NULL; +} + +ZZIP_DIR * +zzip_opendir_ext_io(zzip_char_t * name, int o_modes, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + if (! io) + return zzip_opendir_ext_io64(name, o_modes, ext, io); + else + { errno = EOVERFLOW; return NULL; } +} + +#endif /* ZZIP_LARGEFILE_RENAME && EOVERFLOW && PIC */ + +/* ------------------------------------------------------------------- */ + +/** + * This function will rewind a real/zipped file. + * + * It seeks to the beginning of this file's data in the zip, + * or the beginning of the file for a stat'fd. + */ +int +zzip_rewind(ZZIP_FILE * fp) +{ + ZZIP_DIR *dir; + int err; + + if (! fp) + return -1; + + if (! fp->dir) + { /* stat fd */ + fp->io->fd.seeks(fp->fd, 0, SEEK_SET); + return 0; + } + + dir = fp->dir; + /* + * If this is other handle than previous, save current seek pointer + */ + if (dir->currentfp != fp) + { + if (zzip_file_saveoffset(dir->currentfp) < 0) + { dir->errcode = ZZIP_DIR_SEEK; return -1; } + else + { dir->currentfp = fp; } + } + + /* seek to beginning of this file */ + if (fp->io->fd.seeks(dir->fd, fp->dataoffset, SEEK_SET) < 0) + return -1; + + /* reset the inflate init stuff */ + fp->restlen = fp->usize; + fp->offset = fp->dataoffset; + + if (fp->method) + { /* method == 8, deflate */ + err = inflateReset(&fp->d_stream); + if (err != Z_OK) + goto error; + + /* start over at next inflate with a fresh read() */ + fp->d_stream.avail_in = 0; + fp->crestlen = fp->csize; + } + + return 0; + + error: + if (fp) + zzip_file_close(fp); + return err; +} + +/** + * This function will perform a => lseek(2) operation on a real/zipped file + * + * It will try to seek to the offset specified by offset, relative to whence, + * which is one of SEEK_SET, SEEK_CUR or SEEK_END. + * + * If the file-handle is wrapping a stat'able file then it will actually just + * perform a normal => lseek(2)-call. Otherwise the relative offset + * is calculated, negative offsets are transformed into positive ones + * by rewinding the file, and then data is read until the offset is + * reached. This can make the function terribly slow, but this is + * how gzio implements it, so I'm not sure there is a better way + * without using the internals of the algorithm. + */ +zzip_off_t +zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) +{ + zzip_off_t cur_pos, rel_ofs, read_size, ofs; + ZZIP_DIR *dir; + + if (! fp) + return -1; + + if (! fp->dir) + { /* stat fd */ + return fp->io->fd.seeks(fp->fd, offset, whence); + } + + cur_pos = zzip_tell(fp); + + /* calculate relative offset */ + switch (whence) + { + case SEEK_SET: /* from beginning */ + rel_ofs = offset - cur_pos; + break; + case SEEK_CUR: /* from current */ + rel_ofs = offset; + break; + case SEEK_END: /* from end */ + rel_ofs = fp->usize + offset - cur_pos; + break; + default: /* something wrong */ + return -1; + } + + if (rel_ofs == 0) + return cur_pos; /* don't have to move */ + + if (rel_ofs < 0) + { /* convert backward into forward */ + if (zzip_rewind(fp) == -1) + return -1; + + read_size = cur_pos + rel_ofs; + cur_pos = 0; + } else + { /* amount to read is positive relative offset */ + read_size = rel_ofs; + } + + if (read_size < 0) /* bad offset, before beginning of file */ + return -1; + + if (read_size + cur_pos > (zzip_off_t) fp->usize) /* bad offset, past EOF */ + return -1; + + if (read_size == 0) /* nothing to read */ + return cur_pos; + + dir = fp->dir; + /* + * If this is other handle than previous, save current seek pointer + * and read the file position of `this' handle. + */ + if (dir->currentfp != fp) + { + if (zzip_file_saveoffset(dir->currentfp) < 0 + || fp->io->fd.seeks(dir->fd, fp->offset, SEEK_SET) < 0) + { dir->errcode = ZZIP_DIR_SEEK; return -1; } + else + { dir->currentfp = fp; } + } + + if (fp->method == 0) + { /* unstore, just lseek relatively */ + ofs = fp->io->fd.tells(dir->fd); + ofs = fp->io->fd.seeks(dir->fd, read_size, SEEK_CUR); + if (ofs > 0) + { /* readjust from beginning of file */ + ofs -= fp->dataoffset; + fp->restlen = fp->usize - ofs; + } + return ofs; + } else + { /* method == 8, inflate */ + char *buf; + + /*FIXME: use a static buffer! */ + buf = (char *) malloc(ZZIP_32K); + if (! buf) + return -1; + + while (read_size > 0) + { + zzip_off_t size = ZZIP_32K; + + if (read_size < size /*32K */ ) + size = read_size; + + size = zzip_file_read(fp, buf, (zzip_size_t) size); + if (size <= 0) + { free(buf); return -1; } + + read_size -= size; + } + + free(buf); + } + + return zzip_tell(fp); +} + +/** + * This function will => tell(2) the current position in a real/zipped file + * + * It will return the current offset within the real/zipped file, + * measured in uncompressed bytes for the zipped-file case. + * + * If the file-handle is wrapping a stat'able file then it will actually just + * perform a normal => tell(2)-call, otherwise the offset is + * calculated from the amount of data left and the total uncompressed + * size; + */ +zzip_off_t +zzip_tell(ZZIP_FILE * fp) +{ + if (! fp) + return -1; + + if (! fp->dir) /* stat fd */ + return fp->io->fd.tells(fp->fd); + + /* current uncompressed offset is uncompressed size - data left */ + return (fp->usize - fp->restlen); +} + +#ifndef EOVERFLOW +#define EOVERFLOW EFBIG +#endif + +/** => zzip_tell + * This function is provided for users who can not use any largefile-mode. + */ +long +zzip_tell32(ZZIP_FILE * fp) +{ + if (sizeof(zzip_off_t) == sizeof(long)) + { + return zzip_tell(fp); + } else + { + off_t off = zzip_tell(fp); + if (off >= 0) { + register long off32 = off; + if (off32 == off) return off32; + errno = EOVERFLOW; + } + return -1; + } +} + +/** => zzip_seek + * This function is provided for users who can not use any largefile-mode. + */ +long +zzip_seek32(ZZIP_FILE * fp, long offset, int whence) +{ + if (sizeof(zzip_off_t) == sizeof(long)) + { + return zzip_seek(fp, offset, whence); + } else + { + off_t off = zzip_seek(fp, offset, whence); + if (off >= 0) { + register long off32 = off; + if (off32 == off) return off32; + errno = EOVERFLOW; + } + return -1; + } +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/fseeko.c b/project/jni/zzip/zzip/fseeko.c new file mode 100644 index 000000000..d99067a0b --- /dev/null +++ b/project/jni/zzip/zzip/fseeko.c @@ -0,0 +1,685 @@ + +/* + * NOTE: this is part of libzzipfseeko (i.e. it is not libzzip). + * ================== + * + * These routines are fully independent from the traditional zzip + * implementation. They assume a readonly seekable stdio handle + * representing a complete zip file. The functions show how to + * parse the structure, find files and return a decoded bytestream. + * + * These routines are a bit simple and really here for documenting + * the way to access a zip file. The complexity of zip access comes + * from staggered reading of bytes and reposition of a filepointer in + * a big archive with lots of files and long compressed datastreams. + * Plus varaints of drop-in stdio replacements, obfuscation routines, + * auto fileextensions, drop-in dirent replacements, and so on... + * + * btw, we can _not_ use fgetpos/fsetpos since an fpos_t has no asserted + * relation to a linear seek value as specified in zip info headers. In + * general it is not a problem if your system has no fseeko/ftello pair + * since we can fallback to fseek/ftell which limits the zip disk size + * to 2MiBs but the zip-storable seek values are 32bit limited anyway. + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003,2004 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#define _LARGEFILE_SOURCE 1 +#define _ZZIP_ENTRY_STRUCT 1 + +#include + +#include +#include +#include + +#include +#include +#include + +#if defined ZZIP_HAVE_STRING_H +#include +#elif defined ZZIP_HAVE_STRINGS_H +#include +#endif + +#if defined ZZIP_HAVE_STDINT_H +#include +#endif + +#if __STDC_VERSION__+0 > 199900L +#define ___ +#define ____ +#else +#define ___ { +#define ____ } +#endif + +#ifndef ZZIP_HAVE_FSEEKO +#define fseeko fseek +#define ftello ftell +#endif + +/* note that the struct zzip_entry inherits the zzip_disk_entry values + * and usually carries a copy of its values (in disk format!). To make the + * following code more readable, we use a shorthand notation for the + * upcast needed in C (not needed in C++) as "disk_(entry)". + */ +#ifdef __zzip_entry_extends_zzip_disk_entry +#define disk_(_entry_) _entry_ +#else +#define disk_(_entry_) (& (_entry_)->head) +#endif + +/* we try to round all seeks to the pagesize - since we do not use + * the sys/mmap interface we have to guess a good value here: */ +#define PAGESIZE 8192 + +/* ====================================================================== */ + +/* helper functions */ + +/** => zzip_entry_data_offset + * This functions read the correspoding struct zzip_file_header from + * the zip disk of the given "entry". The returned off_t points to the + * end of the file_header where the current fseek pointer has stopped. + * This is used to immediatly parse out any filename/extras block following + * the file_header. The return value is null on error. + */ +static zzip_off_t +zzip_entry_fread_file_header(ZZIP_ENTRY * entry, + struct zzip_file_header *file_header) +{ + if (! entry || ! file_header) + return 0; + ___ zzip_off_t offset = zzip_disk_entry_fileoffset(disk_(entry)); + if (0 > offset || offset >= entry->disksize) + return 0; + + if (fseeko(entry->diskfile, offset, SEEK_SET) == -1) return 0; + return (fread(file_header, sizeof(*file_header), 1, entry->diskfile) + ? offset + sizeof(*file_header) : 0); + ____; +} + +/** helper functions for (fseeko) zip access api + * + * This functions returns the seekval offset of the data portion of the + * file referenced by the given zzip_entry. It requires an intermediate + * check of the file_header structure (i.e. it reads it from disk). After + * this call, the contained diskfile readposition is already set to the + * data_offset returned here. On error -1 is returned. + */ +zzip_off_t +zzip_entry_data_offset(ZZIP_ENTRY * entry) +{ + struct zzip_file_header file_header; + if (! entry) + return -1; + ___ zzip_off_t offset = zzip_entry_fread_file_header(entry, &file_header); + if (! offset) + return -1; + offset += zzip_file_header_sizeof_tails(&file_header); + if (fseeko(entry->diskfile, offset, SEEK_SET) == -1) + return -1; + return offset; + ____; +} + +/** => zzip_entry_data_offset + * This function is a big helper despite its little name: in a zip file the + * encoded filenames are usually NOT zero-terminated but for common usage + * with libc we need it that way. Secondly, the filename SHOULD be present + * in the zip central directory but if not then we fallback to the filename + * given in the file_header of each compressed data portion. + */ +zzip__new__ char * +zzip_entry_strdup_name(ZZIP_ENTRY * entry) +{ + if (! entry) + return 0; + + ___ zzip_size_t len; + if ((len = zzip_disk_entry_namlen(disk_(entry)))) + { + char *name = malloc(len + 1); + if (! name) + return 0; + memcpy(name, entry->tail, len); + name[len] = '\0'; + return name; + } + ___ auto struct zzip_file_header header; + if (zzip_entry_fread_file_header(entry, &header) + && (len = zzip_file_header_namlen(&header))) + { + char *name = malloc(len + 1); + if (! name) { + return 0; + } else { + zzip_size_t n = fread(name, 1, len, entry->diskfile); + if (n != len) { + free (name); + return 0; + } + name[n] = '\0'; + return name; + } + } + return 0; + ____; + ____; +} + +static int +prescan_entry(ZZIP_ENTRY * entry) +{ + assert(entry); + ___ zzip_off_t tailsize = zzip_disk_entry_sizeof_tails(disk_(entry)); + if (tailsize + 1 > entry->tailalloc) + { + char *newtail = realloc(entry->tail, tailsize + 1); + if (! newtail) + return ENOMEM; + entry->tail = newtail; + entry->tailalloc = tailsize + 1; + } +# ifdef SIZE_MAX /* from stdint.h */ + if (tailsize > (zzip_off_t)(SIZE_MAX)) { return EFBIG; } +# endif + ___ zzip_size_t readsize = fread(entry->tail, 1, tailsize, entry->diskfile); + /* name + comment + extras */ + if ((zzip_off_t)readsize != tailsize) { + return errno; + } else { + return 0; + } ____; ____; +} + +static void +prescan_clear(ZZIP_ENTRY * entry) +{ + assert(entry); + if (entry->tail) + free(entry->tail); + entry->tail = 0; + entry->tailalloc = 0; +} + +/* ====================================================================== */ + +/** => zzip_entry_findfile + * + * This function is the first call of all the zip access functions here. + * It contains the code to find the first entry of the zip central directory. + * Here we require the stdio handle to represent a real zip file where the + * disk_trailer is _last_ in the file area, so that its position would be at + * a fixed offset from the end of the file area if not for the comment field + * allowed to be of variable length (which needs us to do a little search + * for the disk_tailer). However, in this simple implementation we disregard + * any disk_trailer info telling about multidisk archives, so we just return + * a pointer to the first entry in the zip central directory of that file. + * + * For an actual means, we are going to search backwards from the end + * of the mmaped block looking for the PK-magic signature of a + * disk_trailer. If we see one then we check the rootseek value to + * find the first disk_entry of the root central directory. If we find + * the correct PK-magic signature of a disk_entry over there then we + * assume we are done and we are going to return a pointer to that label. + * + * The return value is a pointer to the first zzip_disk_entry being checked + * to be within the bounds of the file area specified by the arguments. If + * no disk_trailer was found then null is returned, and likewise we only + * accept a disk_trailer with a seekvalue that points to a disk_entry and + * both parts have valid PK-magic parts. Beyond some sanity check we try to + * catch a common brokeness with zip archives that still allows us to find + * the start of the zip central directory. + */ +zzip__new__ ZZIP_ENTRY * +zzip_entry_findfirst(FILE * disk) +{ + if (! disk) + return 0; + if (fseeko(disk, 0, SEEK_END) == -1) + return 0; + ___ zzip_off_t disksize = ftello(disk); + if (disksize < (zzip_off_t) sizeof(struct zzip_disk_trailer)) + return 0; + /* we read out chunks of 8 KiB in the hope to match disk granularity */ + ___ zzip_off_t pagesize = PAGESIZE; /* getpagesize() */ + ___ ZZIP_ENTRY *entry = malloc(sizeof(*entry)); + if (! entry) + return 0; + ___ unsigned char *buffer = malloc(pagesize); + if (! buffer) + goto nomem; + + assert(pagesize / 2 > (zzip_off_t) sizeof(struct zzip_disk_trailer)); + /* at each step, we will fread a pagesize block which overlaps with the + * previous read by means of pagesize/2 step at the end of the while(1) */ + ___ zzip_off_t mapoffs = disksize & ~(pagesize - 1); + ___ zzip_off_t mapsize = disksize - mapoffs; + if (mapoffs && mapsize < pagesize / 2) + { + mapoffs -= pagesize / 2; + mapsize += pagesize / 2; + } + assert(mapsize < 3*8192); + while (1) + { + if (fseeko(disk, mapoffs, SEEK_SET) == -1) + goto error; + if (fread(buffer, 1, mapsize, disk) != (zzip_size_t)mapsize) + goto error; + ___ unsigned char *p = + buffer + mapsize - sizeof(struct zzip_disk_trailer); + for (; p >= buffer; p--) + { + zzip_off_t root; /* (struct zzip_disk_entry*) */ + if (zzip_disk_trailer_check_magic(p)) + { + root = zzip_disk_trailer_rootseek((struct zzip_disk_trailer *) + p); + if (root > disksize - (long) sizeof(struct zzip_disk_trailer)) + { + /* first disk_entry is after the disk_trailer? can't be! */ + struct zzip_disk_trailer *trailer = + (struct zzip_disk_trailer *) p; + zzip_off_t rootsize = zzip_disk_trailer_rootsize(trailer); + if (rootsize > mapoffs) + continue; + /* a common brokeness that can be fixed: we just assume the + * central directory was written directly before : */ + root = mapoffs - rootsize; + } + } else if (zzip_disk64_trailer_check_magic(p)) + { + struct zzip_disk64_trailer *trailer = + (struct zzip_disk64_trailer *) p; + if (sizeof(zzip_off_t) < 8) + return 0; + root = zzip_disk64_trailer_rootseek(trailer); + } else + continue; + + assert(0 <= root && root < mapsize); + if (fseeko(disk, root, SEEK_SET) == -1) + goto error; + if (fread(disk_(entry), 1, sizeof(*disk_(entry)), disk) + != sizeof(*disk_(entry))) goto error; + if (zzip_disk_entry_check_magic(entry)) + { + free(buffer); + entry->headseek = root; + entry->diskfile = disk; + entry->disksize = disksize; + if (prescan_entry(entry)) + goto nomem; + return entry; + } + } + ____; + if (! mapoffs) + break; + assert(mapsize >= pagesize / 2); + mapoffs -= pagesize / 2; /* mapsize += pagesize/2; */ + mapsize = pagesize; /* if (mapsize > pagesize) ... */ + if (disksize - mapoffs > 64 * 1024) + break; + } + error: + free(buffer); + nomem: + free(entry); + ____; + ____; + ____; + ____; + ____; + ____; + return 0; +} + +/** => zzip_entry_findfile + * + * This function takes an existing "entry" in the central root directory + * (e.g. from zzip_entry_findfirst) and moves it to point to the next entry. + * On error it returns 0, otherwise the old entry. If no further match is + * found then null is returned and the entry already free()d. If you want + * to stop searching for matches before that case then please call + * => zzip_entry_free on the cursor struct ZZIP_ENTRY. + */ +zzip__new__ ZZIP_ENTRY * +zzip_entry_findnext(ZZIP_ENTRY * _zzip_restrict entry) +{ + if (! entry) + return entry; + if (! zzip_disk_entry_check_magic(entry)) + goto err; + ___ zzip_off_t seek = + entry->headseek + zzip_disk_entry_sizeto_end(disk_(entry)); + if (seek + (zzip_off_t) sizeof(*disk_(entry)) > entry->disksize) + goto err; + + if (fseeko(entry->diskfile, seek, SEEK_SET) == -1) + goto err; + if (fread(disk_(entry), 1, sizeof(*disk_(entry)), entry->diskfile) + != sizeof(*disk_(entry))) goto err; + entry->headseek = seek; + if (! zzip_disk_entry_check_magic(entry)) + goto err; + if (prescan_entry(entry)) + goto err; + return entry; + err: + zzip_entry_free(entry); + return 0; + ____; +} + +/** => zzip_entry_findfile + * this function releases the malloc()ed areas needed for zzip_entry, the + * pointer is invalid afterwards. This function has #define synonyms of + * zzip_entry_findlast(), zzip_entry_findlastfile(), zzip_entry_findlastmatch() + */ +int +zzip_entry_free(ZZIP_ENTRY * entry) +{ + if (! entry) + return 0; + prescan_clear(entry); + free(entry); + return 1; +} + +/** search for files in the (fseeko) zip central directory + * + * This function is given a filename as an additional argument, to find the + * disk_entry matching a given filename. The compare-function is usually + * strcmp or strcasecmp or perhaps strcoll, if null then strcmp is used. + * - use null as argument for "old"-entry when searching the first + * matching entry, otherwise the last returned value if you look for other + * entries with a special "compare" function (if null then a doubled search + * is rather useless with this variant of _findfile). If no further entry is + * found then null is returned and any "old"-entry gets already free()d. + */ +zzip__new__ ZZIP_ENTRY * +zzip_entry_findfile(FILE * disk, char *filename, + ZZIP_ENTRY * _zzip_restrict entry, zzip_strcmp_fn_t compare) +{ + if (! filename || ! disk) + return 0; + if (! entry) + entry = zzip_entry_findfirst(disk); + else + entry = zzip_entry_findnext(entry); + + if (! compare) + compare = (zzip_strcmp_fn_t) (strcmp); + + for (; entry; entry = zzip_entry_findnext(entry)) + { + /* filenames within zip files are often not null-terminated! */ + char *realname = zzip_entry_strdup_name(entry); + if (! realname) + continue; + if (! compare(filename, realname)) + { + free(realname); + return entry; + } else + { + free(realname); + continue; + } + } + return 0; +} + +/** => zzip_entry_findfile + * + * This function uses a compare-function with an additional argument + * and it is called just like fnmatch(3) from POSIX.2 AD:1993), i.e. + * the argument filespec first and the ziplocal filename second with + * the integer-flags put in as third to the indirect call. If the + * platform has fnmatch available then null-compare will use that one + * and otherwise we fall back to mere strcmp, so if you need fnmatch + * searching then please provide an implementation somewhere else. + * - use null as argument for "after"-entry when searching the first + * matching entry, or the last disk_entry return-value to find the + * next entry matching the given filespec. If no further entry is + * found then null is returned and any "old"-entry gets already free()d. + */ +zzip__new__ ZZIP_ENTRY * +zzip_entry_findmatch(FILE * disk, char *filespec, + ZZIP_ENTRY * _zzip_restrict entry, + zzip_fnmatch_fn_t compare, int flags) +{ + if (! filespec || ! disk) + return 0; + if (! entry) + entry = zzip_entry_findfirst(disk); + else + entry = zzip_entry_findnext(entry); + + if (! compare) + compare = (zzip_fnmatch_fn_t) _zzip_fnmatch; + + for (; entry; entry = zzip_entry_findnext(entry)) + { + /* filenames within zip files are often not null-terminated! */ + char *realname = zzip_entry_strdup_name(entry); + if (! realname) + continue; + if (! compare(filespec, realname, flags)) + { + free(realname); + return entry; + } else + { + free(realname); + continue; + } + } + return 0; +} + +/* ====================================================================== */ + +/** + * typedef struct zzip_disk_file ZZIP_ENTRY_FILE; + */ +struct zzip_entry_file /* : zzip_file_header */ +{ + struct zzip_file_header header; /* fopen detected header */ + ZZIP_ENTRY *entry; /* fopen entry */ + zzip_off_t data; /* for stored blocks */ + zzip_size_t avail; /* memorized for checks on EOF */ + zzip_size_t compressed; /* compressed flag and datasize */ + zzip_size_t dataoff; /* offset from data start */ + z_stream zlib; /* for inflated blocks */ + unsigned char buffer[PAGESIZE]; /* work buffer for inflate algorithm */ +}; + +/** open a file within a zip disk for reading + * + * This function does take an "entry" argument and copies it (or just takes + * it over as owner) to a new ZZIP_ENTRY_FILE handle structure. That + * structure contains also a zlib buffer for decoding. This function does + * seek to the file_header of the given "entry" and validates it for the + * data buffer following it. We do also prefetch some data from the data + * buffer thereby trying to match the disk pagesize for faster access later. + * The => zzip_entry_fread will then read in chunks of pagesizes which is + * the size of the internal readahead buffer. If an error occurs then null + * is returned. + */ +zzip__new__ ZZIP_ENTRY_FILE * +zzip_entry_fopen(ZZIP_ENTRY * entry, int takeover) +{ + if (! entry) + return 0; + if (! takeover) + { + ZZIP_ENTRY *found = malloc(sizeof(*entry)); + if (! found) + return 0; + memcpy(found, entry, sizeof(*entry)); /* prescan_copy */ + found->tail = malloc(found->tailalloc); + if (! found->tail) + { free (found); return 0; } + memcpy(found->tail, entry->tail, entry->tailalloc); + entry = found; + } + ___ ZZIP_ENTRY_FILE *file = malloc(sizeof(*file)); + if (! file) + goto fail1; + file->entry = entry; + if (! zzip_entry_fread_file_header(entry, &file->header)) + goto fail2; + file->avail = zzip_file_header_usize(&file->header); + file->data = zzip_entry_data_offset(entry); + file->dataoff = 0; + + if (! file->avail || zzip_file_header_data_stored(&file->header)) + { file->compressed = 0; return file; } + + file->compressed = zzip_file_header_csize(&file->header); + file->zlib.opaque = 0; + file->zlib.zalloc = Z_NULL; + file->zlib.zfree = Z_NULL; + + ___ zzip_off_t seek = file->data; + seek += sizeof(file->buffer); + seek -= seek & (sizeof(file->buffer) - 1); + assert(file->data < seek); /* pre-read to next PAGESIZE boundary... */ + if (fseeko(file->entry->diskfile, file->data + file->dataoff, SEEK_SET) == -1) + goto fail2; + file->zlib.next_in = file->buffer; + file->zlib.avail_in = fread(file->buffer, 1, seek - file->data, + file->entry->diskfile); + file->dataoff += file->zlib.avail_in; + ____; + + if (! zzip_file_header_data_deflated(&file->header) + || inflateInit2(&file->zlib, -MAX_WBITS) != Z_OK) + goto fail2; + + return file; + fail2: + free(file); + fail1: + zzip_entry_free(entry); + return 0; + ____; +} + +/** => zzip_entry_fopen + * + * This function opens a file found by name, so it does a search into + * the zip central directory with => zzip_entry_findfile and whatever + * is found first is given to => zzip_entry_fopen + */ +zzip__new__ ZZIP_ENTRY_FILE * +zzip_entry_ffile(FILE * disk, char *filename) +{ + ZZIP_ENTRY *entry = zzip_entry_findfile(disk, filename, 0, 0); + if (! entry) + return 0; + return zzip_entry_fopen(entry, 1); +} + + +/** => zzip_entry_fopen + * + * This function reads more bytes into the output buffer specified as + * arguments. The return value is null on eof or error, the stdio-like + * interface can not distinguish between these so you need to check + * with => zzip_entry_feof for the difference. + */ +zzip_size_t +zzip_entry_fread(void *ptr, zzip_size_t sized, zzip_size_t nmemb, + ZZIP_ENTRY_FILE * file) +{ + if (! file) + return 0; + ___ zzip_size_t size = sized * nmemb; + if (! file->compressed) + { + if (size > file->avail) + size = file->avail; + if (fread(ptr, 1, size, file->entry->diskfile) != size) return 0; + file->dataoff += size; + file->avail -= size; + return size; + } + + file->zlib.avail_out = size; + file->zlib.next_out = ptr; + ___ zzip_size_t total_old = file->zlib.total_out; + while (1) + { + if (! file->zlib.avail_in) + { + size = file->compressed - file->dataoff; + if (size > sizeof(file->buffer)) + size = sizeof(file->buffer); + /* fseek (file->data + file->dataoff, file->entry->diskfile); */ + file->zlib.avail_in = fread(file->buffer, 1, size, + file->entry->diskfile); + file->zlib.next_in = file->buffer; + file->dataoff += file->zlib.avail_in; + } + if (! file->zlib.avail_in) + return 0; + + ___ int err = inflate(&file->zlib, Z_NO_FLUSH); + if (err == Z_STREAM_END) + file->avail = 0; + else if (err == Z_OK) + file->avail -= file->zlib.total_out - total_old; + else + return 0; + ____; + if (file->zlib.avail_out && ! file->zlib.avail_in) + continue; + return file->zlib.total_out - total_old; + } + ____; + ____; +} + +/** => zzip_entry_fopen + * This function releases any zlib decoder info needed for decompression + * and dumps the ZZIP_ENTRY_FILE struct then. + */ +int +zzip_entry_fclose(ZZIP_ENTRY_FILE * file) +{ + if (! file) + return 0; + if (file->compressed) + inflateEnd(&file->zlib); + zzip_entry_free(file->entry); + free(file); + return 0; +} + +/** => zzip_entry_fopen + * + * This function allows to distinguish an error from an eof condition. + * Actually, if we found an error but we did already reach eof then we + * just keep on saying that it was an eof, so the app can just continue. + */ +int +zzip_entry_feof(ZZIP_ENTRY_FILE * file) +{ + return ! file || ! file->avail; +} diff --git a/project/jni/zzip/zzip/info.c b/project/jni/zzip/zzip/info.c new file mode 100644 index 000000000..0c50600ff --- /dev/null +++ b/project/jni/zzip/zzip/info.c @@ -0,0 +1,163 @@ + +/* + * Author: + * Guido Draheim + * + * Copyright (c) 2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include /* exported... */ +#include +#include + +#ifdef ZZIP_HAVE_SYS_STAT_H +#include +#else +#include +#include +#endif + +/** + * just returns dir->errcode of the ZZIP_DIR handle + * see: => zzip_dir_open, => zzip_dir_open, => zzip_readdir, => zzip_dir_read + */ +int +zzip_error(ZZIP_DIR * dir) +{ + return dir->errcode; +} + +/** => zzip_error + * This function just does dir->errcode = errcode + */ +void +zzip_seterror(ZZIP_DIR * dir, int errcode) { dir->errcode = errcode; } + +/** + * This function will just return fp->dir + * + * If a ZZIP_FILE is contained within a zip-file that one will be a valid + * pointer, otherwise a NULL is returned and the ZZIP_FILE wraps a real file. + */ +ZZIP_DIR * +zzip_dirhandle(ZZIP_FILE * fp) +{ + return fp->dir; +} + +/** => zzip_dirhandle + * This function will just return dir->fd + * + * If a ZZIP_DIR does point to a zipfile then the file-descriptor of that + * zipfile is returned, otherwise a NULL is returned and the ZZIP_DIR wraps + * a real directory DIR (if you have dirent on your system). + */ +int +zzip_dirfd(ZZIP_DIR * dir) +{ + return dir->fd; +} + +/** + * return static const string of the known compression methods, + * otherwise just "zipped" is returned + */ +zzip_char_t * +zzip_compr_str(int compr) +{ + switch (compr) + { + /* *INDENT-OFF* */ + case ZZIP_IS_STORED: return "stored"; + case ZZIP_IS_SHRUNK: return "shrunk"; + case ZZIP_IS_REDUCEDx1: + case ZZIP_IS_REDUCEDx2: + case ZZIP_IS_REDUCEDx3: + case ZZIP_IS_REDUCEDx4: return "reduced"; + case ZZIP_IS_IMPLODED: return "imploded"; + case ZZIP_IS_TOKENIZED: return "tokenized"; + case ZZIP_IS_DEFLATED: return "deflated"; + case ZZIP_IS_DEFLATED_BETTER: return "deflatedX"; + case ZZIP_IS_IMPLODED_BETTER: return "implodedX"; + default: + if (0 < compr && compr < 256) return "zipped"; + else + { +# ifdef S_ISDIR + if (S_ISDIR(compr)) return "directory"; +# endif +# ifdef S_ISCHR + if (S_ISCHR(compr)) return "is/chr"; +# endif +# ifdef S_ISBLK + if (S_ISBLK(compr)) return "is/blk"; +# endif +# ifdef S_ISFIFO + if (S_ISFIFO(compr)) return "is/fifo"; +# endif +# ifdef S_ISSOCK + if (S_ISSOCK(compr)) return "is/sock"; +# endif +# ifdef S_ISLNK + if (S_ISLNK(compr)) return "is/lnk"; +# endif + return "special"; + } + /* *INDENT-ON* */ + } /*switch */ +} + +/** => zzip_file_real + * This function checks if the ZZIP_DIR-handle is wrapping + * a real directory or a zip-archive. + * Returns 1 for a stat'able directory, and 0 for a handle to zip-archive. + */ +int +zzip_dir_real(ZZIP_DIR * dir) +{ + return dir->realdir != 0; +} + +/** + * This function checks if the ZZIP_FILE-handle is wrapping + * a real file or a zip-contained file. + * Returns 1 for a stat'able file, and 0 for a file inside a zip-archive. + */ +int +zzip_file_real(ZZIP_FILE * fp) +{ + return fp->dir == 0; /* ie. not dependent on a zip-arch-dir */ +} + +/** => zzip_file_real + * This function returns the posix DIR* handle (if one exists). + * Check before with => zzip_dir_real if the + * the ZZIP_DIR points to a real directory. + */ +void * +zzip_realdir(ZZIP_DIR * dir) +{ + return dir->realdir; +} + +/** => zzip_file_real + * This function returns the posix file descriptor (if one exists). + * Check before with => zzip_file_real if the + * the ZZIP_FILE points to a real file. + */ +int +zzip_realfd(ZZIP_FILE * fp) +{ + return fp->fd; +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/memdisk.c b/project/jni/zzip/zzip/memdisk.c new file mode 100644 index 000000000..dc00ea865 --- /dev/null +++ b/project/jni/zzip/zzip/memdisk.c @@ -0,0 +1,466 @@ + +/* + * NOTE: this is part of libzzipmmapped (i.e. it is not libzzip). + * ================== + * + * The mem_disk cache will parse the central information of a zip archive + * and store it internally. One the one hand it allows to find files + * faster - no disk access is required and endian conversion is not + * needed. If zzip is compiled with zip extensions then it is about + * the only way to build maintainable code around the zip format. + * + * Note that 64bit support is almost entirely living in extension + * blocks as well as different character encodings and file access + * control bits that are mostly platform specific. + * + * Author: + * Guido Draheim + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ +#define _ZZIP_DISK_FILE_STRUCT 1 + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define ___ { +#define ____ } + +static const char *error[] = { + "Ok", +# define _zzip_mem_disk_open_fail 1 + "zzip_mem_disk_open: zzip_disk_open did fail", +# define _zzip_mem_disk_fdopen_fail 2 + "zzip_mem_disk_fdopen: zzip_disk_mmap did fail" +# define _zzip_mem_disk_buffer_fail 3 + "zzip_mem_disk_buffer: zzip_disk_buffer did fail", + 0 +}; + +#define ZZIP_EXTRA_zip64 0x0001 +typedef struct _zzip_extra_zip64 +{ /* ZIP64 extended information extra field */ + zzip_byte_t z_datatype[2]; /* Tag for this "extra" block type */ + zzip_byte_t z_datasize[2]; /* Size of this "extra" block */ + zzip_byte_t z_usize[8]; /* Original uncompressed file size */ + zzip_byte_t z_csize[8]; /* Size of compressed data */ + zzip_byte_t z_offset[8]; /* Offset of local header record */ + zzip_byte_t z_diskstart[4]; /* Number of the disk for file start */ +} zzip_extra_zip64; + +/*forward*/ + +static zzip__new__ ZZIP_MEM_ENTRY * +zzip_mem_entry_new(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry); +static void +zzip_mem_entry_free(ZZIP_MEM_ENTRY * _zzip_restrict item); + +zzip__new__ ZZIP_MEM_DISK * +zzip_mem_disk_new(void) +{ + return calloc(1, sizeof(ZZIP_MEM_DISK)); +} + +/** create new diskdir handle. + * wraps underlying zzip_disk_open. */ +zzip__new__ ZZIP_MEM_DISK * +zzip_mem_disk_open(char *filename) +{ + ZZIP_DISK *disk = zzip_disk_open(filename); + if (! disk) + { perror(error[_zzip_mem_disk_open_fail]); return 0; } + ___ ZZIP_MEM_DISK *dir = zzip_mem_disk_new(); + zzip_mem_disk_load(dir, disk); + return dir; + ____; +} + +/** create new diskdir handle. + * wraps underlying zzip_disk_open. */ +zzip__new__ ZZIP_MEM_DISK * +zzip_mem_disk_fdopen(int fd) +{ + ZZIP_DISK *disk = zzip_disk_mmap(fd); + if (! disk) + { perror(error[_zzip_mem_disk_fdopen_fail]); return 0; } + ___ ZZIP_MEM_DISK *dir = zzip_mem_disk_new(); + zzip_mem_disk_load(dir, disk); + return dir; + ____; +} + +/** create new diskdir handle. + * wraps underlying zzip_disk_buffer. */ +zzip__new__ ZZIP_MEM_DISK * +zzip_mem_disk_buffer(char *buffer, size_t buflen) +{ + ZZIP_DISK *disk = zzip_disk_buffer(buffer, buflen); + if (! disk) + { perror(error[_zzip_mem_disk_buffer_fail]); return 0; } + ___ ZZIP_MEM_DISK *dir = zzip_mem_disk_new(); + zzip_mem_disk_load(dir, disk); + return dir; + ____; +} + +/** parse central dir. + * creates an internal copy of each entry converted to the local platform. + * returns: number of entries, or -1 on error (setting errno) + */ +long +zzip_mem_disk_load(ZZIP_MEM_DISK * dir, ZZIP_DISK * disk) +{ + if (! dir || ! disk) + { errno=EINVAL; return -1; } + if (dir->list) + zzip_mem_disk_unload(dir); + ___ long count = 0; + ___ struct zzip_disk_entry *entry = zzip_disk_findfirst(disk); + for (; entry; entry = zzip_disk_findnext(disk, entry)) + { + ZZIP_MEM_ENTRY *item = zzip_mem_entry_new(disk, entry); + if (! item) + goto error; + if (dir->last) + { + dir->last->zz_next = item; /* chain last */ + } else + { + dir->list = item; + } + dir->last = item; /* to earlier */ + count++; + } + ____; + dir->disk = disk; + return count; + ____; + error: + zzip_mem_disk_unload(dir); + return -1; +} + +/** convert a zip disk entry to internal format. + * creates a new item parsing the information out of the various places + * in the zip archive. This is a good place to extend functionality if + * you have a project with extra requirements as you can push more bits + * right into the diskdir_entry for later usage in higher layers. + * returns: new item, or null on error (setting errno) + */ +zzip__new__ ZZIP_MEM_ENTRY * +zzip_mem_entry_new(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry) +{ + if (! disk || ! entry) + { errno=EINVAL; return 0; } + ___ ZZIP_MEM_ENTRY *item = calloc(1, sizeof(*item)); + if (! item) + return 0; /* errno=ENOMEM; */ + ___ struct zzip_file_header *header = + zzip_disk_entry_to_file_header(disk, entry); + /* there is a number of duplicated information in the file header + * or the disk entry block. Theoretically some part may be missing + * that exists in the other, ... but we will prefer the disk entry. + */ + item->zz_comment = zzip_disk_entry_strdup_comment(disk, entry); + item->zz_name = zzip_disk_entry_strdup_name(disk, entry); + item->zz_data = zzip_file_header_to_data(header); + item->zz_flags = zzip_disk_entry_get_flags(entry); + item->zz_compr = zzip_disk_entry_get_compr(entry); + item->zz_mktime = zzip_disk_entry_get_mktime(entry); + item->zz_crc32 = zzip_disk_entry_get_crc32(entry); + item->zz_csize = zzip_disk_entry_get_csize(entry); + item->zz_usize = zzip_disk_entry_get_usize(entry); + item->zz_diskstart = zzip_disk_entry_get_diskstart(entry); + item->zz_filetype = zzip_disk_entry_get_filetype(entry); + + { /* copy the extra blocks to memory as well */ + int /* */ ext1 = zzip_disk_entry_get_extras(entry); + char *_zzip_restrict ptr1 = zzip_disk_entry_to_extras(entry); + int /* */ ext2 = zzip_file_header_get_extras(header); + char *_zzip_restrict ptr2 = zzip_file_header_to_extras(header); + + if (ext1) + { + void *mem = malloc(ext1 + 2); + item->zz_ext[1] = mem; + memcpy(mem, ptr1, ext1); + ((char *) (mem))[ext1 + 0] = 0; + ((char *) (mem))[ext1 + 1] = 0; + } + if (ext2) + { + void *mem = malloc(ext2 + 2); + item->zz_ext[2] = mem; + memcpy(mem, ptr2, ext2); + ((char *) (mem))[ext2 + 0] = 0; + ((char *) (mem))[ext2 + 1] = 0; + } + } + { + /* override sizes/offsets with zip64 values for largefile support */ + zzip_extra_zip64 *block = (zzip_extra_zip64 *) + zzip_mem_entry_extra_block(item, ZZIP_EXTRA_zip64); + if (block) + { + item->zz_usize = __zzip_get64(block->z_usize); + item->zz_csize = __zzip_get64(block->z_csize); + item->zz_offset = __zzip_get64(block->z_offset); + item->zz_diskstart = __zzip_get32(block->z_diskstart); + } + } + /* NOTE: + * All information from the central directory entry is now in memory. + * Effectivly that allows us to modify it and write it back to disk. + */ + return item; + ____; + ____; +} + +/* find an extra block for the given datatype code. + * We assume that the central directory has been preparsed to memory. + */ +ZZIP_EXTRA_BLOCK * +zzip_mem_entry_extra_block(ZZIP_MEM_ENTRY * entry, short datatype) +{ + int i = 2; + while (1) + { + ZZIP_EXTRA_BLOCK *ext = entry->zz_ext[i]; + if (ext) + { + while (*(short *) (ext->z_datatype)) + { + if (datatype == zzip_extra_block_get_datatype(ext)) + { + return ext; + } + ___ char *e = (char *) ext; + e += zzip_extra_block_headerlength; + e += zzip_extra_block_get_datasize(ext); + ext = (void *) e; + ____; + } + } + if (! i) + return 0; + i--; + } +} + +void +zzip_mem_entry_free(ZZIP_MEM_ENTRY * _zzip_restrict item) +{ + if (item) + { + /* *INDENT-OFF* */ + if (item->zz_ext[0]) free (item->zz_ext[0]); + if (item->zz_ext[1]) free (item->zz_ext[1]); + if (item->zz_ext[2]) free (item->zz_ext[2]); + if (item->zz_comment) free (item->zz_comment); + if (item->zz_name) free (item->zz_name); + free (item); + /* *INDENT-ON* */ + } +} + +void +zzip_mem_disk_unload(ZZIP_MEM_DISK * dir) +{ + ZZIP_MEM_ENTRY *item = dir->list; + while (item) + { + ZZIP_MEM_ENTRY *next = item->zz_next; + zzip_mem_entry_free(item); + item = next; + } + dir->list = dir->last = 0; + zzip_disk_close(dir->disk); + dir->disk = 0; +} + +void +zzip_mem_disk_close(ZZIP_MEM_DISK * _zzip_restrict dir) +{ + if (dir) + { + zzip_mem_disk_unload(dir); + zzip_disk_close(dir->disk); + free(dir); + } +} + +#if 0 +static void +foo(short zz_datatype) +{ + switch (zz_datatype) + { + /* *INDENT-OFF* */ + case 0x0001: /* ZIP64 extended information extra field */ + case 0x0007: /* AV Info */ + case 0x0008: /* Reserved for future Unicode file name data (PFS) */ + case 0x0009: /* OS/2 */ + case 0x000a: /* NTFS */ + case 0x000c: /* OpenVMS */ + case 0x000d: /* Unix */ + case 0x000e: /* Reserved for file stream and fork descriptors */ + case 0x000f: /* Patch Descriptor */ + case 0x0014: /* PKCS#7 Store for X.509 Certificates */ + case 0x0015: /* X.509 Certificate ID and Signature for file */ + case 0x0016: /* X.509 Certificate ID for Central Directory */ + case 0x0017: /* Strong Encryption Header */ + case 0x0018: /* Record Management Controls */ + case 0x0019: /* PKCS#7 Encryption Recipient Certificate List */ + case 0x0065: /* IBM S/390, AS/400 attributes - uncompressed */ + case 0x0066: /* Reserved for IBM S/390, AS/400 attr - compressed */ + case 0x07c8: /* Macintosh */ + case 0x2605: /* ZipIt Macintosh */ + case 0x2705: /* ZipIt Macintosh 1.3.5+ */ + case 0x2805: /* ZipIt Macintosh 1.3.5+ */ + case 0x334d: /* Info-ZIP Macintosh */ + case 0x4341: /* Acorn/SparkFS */ + case 0x4453: /* Windows NT security descriptor (binary ACL) */ + case 0x4704: /* VM/CMS */ + case 0x470f: /* MVS */ + case 0x4b46: /* FWKCS MD5 (see below) */ + case 0x4c41: /* OS/2 access control list (text ACL) */ + case 0x4d49: /* Info-ZIP OpenVMS */ + case 0x4f4c: /* Xceed original location extra field */ + case 0x5356: /* AOS/VS (ACL) */ + case 0x5455: /* extended timestamp */ + case 0x554e: /* Xceed unicode extra field */ + case 0x5855: /* Info-ZIP Unix (original, also OS/2, NT, etc) */ + case 0x6542: /* BeOS/BeBox */ + case 0x756e: /* ASi Unix */ + case 0x7855: /* Info-ZIP Unix (new) */ + case 0xfd4a: /* SMS/QDOS */ + /* *INDENT-ON* */ + } +} +#endif + +ZZIP_MEM_ENTRY * +zzip_mem_disk_findfile(ZZIP_MEM_DISK * dir, + char *filename, ZZIP_MEM_ENTRY * after, + zzip_strcmp_fn_t compare) +{ + ZZIP_MEM_ENTRY *entry = (! after ? dir->list : after->zz_next); + if (! compare) + compare = (zzip_strcmp_fn_t) (strcmp); + for (; entry; entry = entry->zz_next) + { + if (! compare(filename, entry->zz_name)) + { + return entry; + } + } + return 0; +} + +ZZIP_MEM_ENTRY * +zzip_mem_disk_findmatch(ZZIP_MEM_DISK * dir, + char *filespec, ZZIP_MEM_ENTRY * after, + zzip_fnmatch_fn_t compare, int flags) +{ + ZZIP_MEM_ENTRY *entry = (! after ? dir->list : after->zz_next); + if (! compare) + compare = (zzip_fnmatch_fn_t) _zzip_fnmatch; + for (; entry; entry = entry->zz_next) + { + if (! compare(filespec, entry->zz_name, flags)) + { + return entry; + } + } + return 0; +} + +zzip__new__ ZZIP_MEM_DISK_FILE * +zzip_mem_entry_fopen(ZZIP_MEM_DISK * dir, ZZIP_MEM_ENTRY * entry) +{ + /* keep this in sync with zzip_disk_entry_fopen */ + ZZIP_DISK_FILE *file = malloc(sizeof(ZZIP_MEM_DISK_FILE)); + if (! file) + return file; + file->buffer = dir->disk->buffer; + file->endbuf = dir->disk->endbuf; + file->avail = zzip_mem_entry_usize(entry); + + if (! file->avail || zzip_mem_entry_data_stored(entry)) + { file->stored = zzip_mem_entry_to_data (entry); return file; } + + file->stored = 0; + file->zlib.opaque = 0; + file->zlib.zalloc = Z_NULL; + file->zlib.zfree = Z_NULL; + file->zlib.avail_in = zzip_mem_entry_csize(entry); + file->zlib.next_in = zzip_mem_entry_to_data(entry); + + if (! zzip_mem_entry_data_deflated(entry) || + inflateInit2(&file->zlib, -MAX_WBITS) != Z_OK) + { free (file); return 0; } + + return file; +} + +zzip__new__ ZZIP_MEM_DISK_FILE * +zzip_mem_disk_fopen(ZZIP_MEM_DISK * dir, char *filename) +{ + ZZIP_MEM_ENTRY *entry = zzip_mem_disk_findfile(dir, filename, 0, 0); + if (! entry) + return 0; + else + return zzip_mem_entry_fopen(dir, entry); +} + +_zzip_size_t +zzip_mem_disk_fread(void *ptr, _zzip_size_t size, _zzip_size_t nmemb, + ZZIP_MEM_DISK_FILE * file) +{ + return zzip_disk_fread(ptr, size, nmemb, file); +} + +int +zzip_mem_disk_fclose(ZZIP_MEM_DISK_FILE * file) +{ + return zzip_disk_fclose(file); +} + +int +zzip_mem_disk_feof(ZZIP_MEM_DISK_FILE * file) +{ + return zzip_disk_feof(file); +} + +/* convert dostime of entry to unix time_t */ +long +zzip_disk_entry_get_mktime(ZZIP_DISK_ENTRY * entry) +{ + uint16_t dostime = ZZIP_GET16(entry->z_dostime.time); + uint16_t dosdate = ZZIP_GET16(entry->z_dostime.date); + struct tm date; + date.tm_sec = (dostime) & 0x1F; /* bits 0..4 */ + date.tm_min = (dostime >> 5) & 0x3F; /* bits 5..10 */ + date.tm_hour = (dostime >> 11); /* bits 11..15 */ + date.tm_mday = (dosdate) & 0x1F; /* bits 16..20 */ + date.tm_mon = (dosdate >> 5) & 0xF; /* bits 21..24 */ + date.tm_year = (dosdate >> 9) + 80; /* bits 25..31 */ + return mktime(&date); /* well, unix has that function... */ +} diff --git a/project/jni/zzip/zzip/mmapped.c b/project/jni/zzip/zzip/mmapped.c new file mode 100644 index 000000000..6fafc1163 --- /dev/null +++ b/project/jni/zzip/zzip/mmapped.c @@ -0,0 +1,646 @@ + +/* + * NOTE: this is part of libzzipmmapped (i.e. it is not libzzip). + * ================== + * + * These routines are fully independent from the traditional zzip + * implementation. They assume a readonly mmapped sharedmem block + * representing a complete zip file. The functions show how to + * parse the structure, find files and return a decoded bytestream. + * + * These routines are a bit simple and really here for documenting + * the way to access a zip file. The complexity of zip access comes + * from staggered reading of bytes and reposition of a filepointer in + * a big archive with lots of files and long compressed datastreams. + * Plus varaints of drop-in stdio replacements, obfuscation routines, + * auto fileextensions, drop-in dirent replacements, and so on... + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003,2004,2006 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#define _ZZIP_DISK_FILE_STRUCT 1 + +#ifdef __linux__ +#define _GNU_SOURCE _glibc_developers_are_idiots_to_call_strndup_gnu_specific_ +#endif + +#include +#include +#include +#include +#include + +#include +#include + +#if defined ZZIP_HAVE_UNISTD_H +#include +#elif defined ZZIP_HAVE_IO_H +#include +#endif + +#if defined ZZIP_HAVE_STRING_H +#include +#elif defined ZZIP_HAVE_STRINGS_H +#include +#endif + + +#if __STDC_VERSION__+0 > 199900L +#define ___ +#define ____ +#else +#define ___ { +#define ____ } +#endif + +/** => zzip_disk_mmap + * This function does primary initialization of a disk-buffer struct. + */ +int +zzip_disk_init(ZZIP_DISK * disk, void *buffer, zzip_size_t buflen) +{ + disk->buffer = (zzip_byte_t *) buffer; + disk->endbuf = (zzip_byte_t *) buffer + buflen; + disk->reserved = 0; + disk->flags = 0; + disk->mapped = 0; + /* do not touch disk->user */ + /* do not touch disk->code */ + return 0; +} + +/** => zzip_disk_mmap + * This function allocates a new disk-buffer with => malloc(3) + */ +zzip__new__ ZZIP_DISK * +zzip_disk_new(void) +{ + ZZIP_DISK *disk = malloc(sizeof(ZZIP_DISK)); + if (! disk) + return disk; + zzip_disk_init(disk, 0, 0); + return disk; +} + +/** turn a filehandle into a mmapped zip disk archive handle + * + * This function uses the given file-descriptor to detect the length of the + * file and calls the system => mmap(2) to put it in main memory. If it is + * successful then a newly allocated ZZIP_DISK* is returned with + * disk->buffer pointing to the mapview of the zipdisk content. + */ +zzip__new__ ZZIP_DISK * +zzip_disk_mmap(int fd) +{ + struct stat st; + if (fstat(fd, &st) || ! st.st_size) + return 0; + ___ ZZIP_DISK *disk = zzip_disk_new(); + if (! disk) + return 0; + disk->buffer = _zzip_mmap(disk->mapped, fd, 0, st.st_size); + if (disk->buffer == MAP_FAILED) + { free (disk); return 0; } + disk->endbuf = disk->buffer + st.st_size; + return disk; + ____; +} + +/** => zzip_disk_mmap + * This function is the inverse of => zzip_disk_mmap and using the system + * munmap(2) on the buffer area and => free(3) on the ZZIP_DISK structure. + */ +int +zzip_disk_munmap(ZZIP_DISK * disk) +{ + if (! disk) + return 0; + _zzip_munmap(disk->mapped, disk->buffer, disk->endbuf - disk->buffer); + free(disk); + return 0; +} + +/** => zzip_disk_mmap + * + * This function opens the given archive by name and turn the filehandle + * to => zzip_disk_mmap for bringing it to main memory. If it can not + * be => mmap(2)'ed then we slurp the whole file into a newly => malloc(2)'ed + * memory block. Only if that fails too then we return null. Since handling + * of disk->buffer is ambigous it should not be snatched away please. + */ +zzip__new__ ZZIP_DISK * +zzip_disk_open(char *filename) +{ +# ifndef O_BINARY +# define O_BINARY 0 +# endif + struct stat st; + if (stat(filename, &st) || ! st.st_size) + return 0; + ___ int fd = open(filename, O_RDONLY | O_BINARY); + if (fd <= 0) + return 0; + ___ ZZIP_DISK *disk = zzip_disk_mmap(fd); + if (disk) + return disk; + ___ zzip_byte_t *buffer = malloc(st.st_size); + if (! buffer) + return 0; + if ((st.st_size == read(fd, buffer, st.st_size)) && + (disk = zzip_disk_new())) + { + disk->buffer = buffer; + disk->endbuf = buffer + st.st_size; + disk->mapped = -1; + disk->flags |= ZZIP_DISK_FLAGS_OWNED_BUFFER; + } else { + free(buffer); + } + return disk; + ____; + ____; + ____; +} + +/** => zzip_disk_mmap + * This function will attach a buffer with a zip image + * that was acquired from another source than a file. + * Note that if zzip_disk_mmap fails then zzip_disk_open + * will fall back and try to read the full file to memory + * wrapping a ZZIP_DISK around the memory buffer just as + * this function will do. Note that this function will not + * own the buffer, it will neither be written nor free()d. + */ +zzip__new__ ZZIP_DISK * +zzip_disk_buffer(void *buffer, size_t buflen) { + ZZIP_DISK *disk = zzip_disk_new(); + if (disk) + { + disk->buffer = (zzip_byte_t *) buffer; + disk->endbuf = (zzip_byte_t *) buffer + buflen; + disk->mapped = -1; + } + return disk; +} + +/** => zzip_disk_mmap + * + * This function will release all data needed to access a (mmapped) + * zip archive, including any malloc()ed blocks, sharedmem mappings + * and it dumps the handle struct as well. + */ +int +zzip_disk_close(ZZIP_DISK * disk) +{ + if (! disk) + return 0; + if (disk->mapped != -1) + return zzip_disk_munmap(disk); + if (disk->flags & ZZIP_DISK_FLAGS_OWNED_BUFFER) + free(disk->buffer); + free(disk); + return 0; +} + +/* ====================================================================== */ + +/* helper functions */ + +#ifdef ZZIP_HAVE_STRNDUP +#define _zzip_strndup strndup +#else + +/* if your system does not have strndup: */ +zzip__new__ static char * +_zzip_strndup(char *p, size_t maxlen) +{ + if (! p) + return 0; + ___ zzip_byte_t *r = malloc(maxlen + 1); + if (! r) + return r; + strncpy(r, p, maxlen); + r[maxlen] = '\0'; + return r; + ____; +} +#endif + +#if defined ZZIP_HAVE_STRCASECMP || defined strcasecmp +#define _zzip_strcasecmp strcasecmp +#else + +/* if your system does not have strcasecmp: */ +static int +_zzip_strcasecmp(char *__zzip_restrict a, char *_zzip_restrict b) +{ + if (! a) + return (b) ? 1 : 0; + if (! b) + return -1; + while (1) + { + int v = tolower(*a) - tolower(*b); + if (v) + return v; + if (! *a) + return 1; + if (! *b) + return -1; + a++; + b++; + } +} +#endif + +/** helper functions for (mmapped) zip access api + * + * This function augments the other zzip_disk_entry_* helpers: here we move + * a disk_entry pointer (as returned by _find* functions) into a pointer to + * the data block right after the file_header. Only disk->buffer would be + * needed to perform the seek but we check the mmapped range end as well. + */ +zzip_byte_t * +zzip_disk_entry_to_data(ZZIP_DISK * disk, struct zzip_disk_entry * entry) +{ + struct zzip_file_header *file = zzip_disk_entry_to_file_header(disk, entry); + if (file) + return zzip_file_header_to_data(file); + return 0; +} + +/** => zzip_disk_entry_to_data + * This function does half the job of => zzip_disk_entry_to_data where it + * can augment with => zzip_file_header_to_data helper from format/fetch.h + */ +struct zzip_file_header * +zzip_disk_entry_to_file_header(ZZIP_DISK * disk, struct zzip_disk_entry *entry) +{ + zzip_byte_t *file_header = /* (struct zzip_file_header*) */ + (disk->buffer + zzip_disk_entry_fileoffset(entry)); + if (disk->buffer > file_header || file_header >= disk->endbuf) + return 0; + return (struct zzip_file_header *) file_header; +} + +/** => zzip_disk_entry_to_data + * This function is a big helper despite its little name: in a zip file the + * encoded filenames are usually NOT zero-terminated but for common usage + * with libc we need it that way. Secondly, the filename SHOULD be present + * in the zip central directory but if not then we fallback to the filename + * given in the file_header of each compressed data portion. + */ +zzip__new__ char * +zzip_disk_entry_strdup_name(ZZIP_DISK * disk, struct zzip_disk_entry *entry) +{ + if (! disk || ! entry) + return 0; + + ___ char *name; + zzip_size_t len; + struct zzip_file_header *file; + if ((len = zzip_disk_entry_namlen(entry))) + name = zzip_disk_entry_to_filename(entry); + else if ((file = zzip_disk_entry_to_file_header(disk, entry)) && + (len = zzip_file_header_namlen(file))) + name = zzip_file_header_to_filename(file); + else + return 0; + + if ((zzip_byte_t *) name < disk->buffer || + (zzip_byte_t *) name + len > disk->endbuf) + return 0; + + return _zzip_strndup(name, len); + ____; +} + +/** => zzip_disk_entry_to_data + * This function is similar creating a reference to a zero terminated + * string but it can only exist in the zip central directory entry. + */ +zzip__new__ char * +zzip_disk_entry_strdup_comment(ZZIP_DISK * disk, struct zzip_disk_entry *entry) +{ + if (! disk || ! entry) + return 0; + + ___ char *text; + zzip_size_t len; + if ((len = zzip_disk_entry_comment(entry))) + text = zzip_disk_entry_to_comment(entry); + else + return 0; + + if ((zzip_byte_t *) text < disk->buffer || + (zzip_byte_t *) text + len > disk->endbuf) + return 0; + + return _zzip_strndup(text, len); + ____; +} + +/* ====================================================================== */ + +/** => zzip_disk_findfile + * + * This function is the first call of all the zip access functions here. + * It contains the code to find the first entry of the zip central directory. + * Here we require the mmapped block to represent a real zip file where the + * disk_trailer is _last_ in the file area, so that its position would be at + * a fixed offset from the end of the file area if not for the comment field + * allowed to be of variable length (which needs us to do a little search + * for the disk_tailer). However, in this simple implementation we disregard + * any disk_trailer info telling about multidisk archives, so we just return + * a pointer to the zip central directory. + * + * For an actual means, we are going to search backwards from the end + * of the mmaped block looking for the PK-magic signature of a + * disk_trailer. If we see one then we check the rootseek value to + * find the first disk_entry of the root central directory. If we find + * the correct PK-magic signature of a disk_entry over there then we + * assume we are done and we are going to return a pointer to that label. + * + * The return value is a pointer to the first zzip_disk_entry being checked + * to be within the bounds of the file area specified by the arguments. If + * no disk_trailer was found then null is returned, and likewise we only + * accept a disk_trailer with a seekvalue that points to a disk_entry and + * both parts have valid PK-magic parts. Beyond some sanity check we try to + * catch a common brokeness with zip archives that still allows us to find + * the start of the zip central directory. + */ +struct zzip_disk_entry * +zzip_disk_findfirst(ZZIP_DISK * disk) +{ + if (disk->buffer > disk->endbuf - sizeof(struct zzip_disk_trailer)) + return 0; + ___ zzip_byte_t *p = disk->endbuf - sizeof(struct zzip_disk_trailer); + for (; p >= disk->buffer; p--) + { + zzip_byte_t *root; /* (struct zzip_disk_entry*) */ + if (zzip_disk_trailer_check_magic(p)) + { + struct zzip_disk_trailer *trailer = (struct zzip_disk_trailer *) p; + root = disk->buffer + zzip_disk_trailer_get_rootseek(trailer); + if (root > p) + { + /* the first disk_entry is after the disk_trailer? can't be! */ + zzip_size_t rootsize = zzip_disk_trailer_get_rootsize(trailer); + if (disk->buffer + rootsize > p) + continue; + /* a common brokeness that can be fixed: we just assume the + * central directory was written directly before the trailer:*/ + root = p - rootsize; + } + } else if (zzip_disk64_trailer_check_magic(p)) + { + struct zzip_disk64_trailer *trailer = + (struct zzip_disk64_trailer *) p; + if (sizeof(void *) < 8) + return 0; /* EOVERFLOW */ + root = disk->buffer + zzip_disk64_trailer_get_rootseek(trailer); + if (root > p) + continue; + } else + { + continue; + } + + if (root < disk->buffer) + continue; + if (zzip_disk_entry_check_magic(root)) + return (struct zzip_disk_entry *) root; + } ____; + return 0; +} + +/** => zzip_disk_findfile + * + * This function takes an existing disk_entry in the central root directory + * (e.g. from zzip_disk_findfirst) and returns the next entry within in + * the given bounds of the mmapped file area. + */ +struct zzip_disk_entry * +zzip_disk_findnext(ZZIP_DISK * disk, struct zzip_disk_entry *entry) +{ + if ((zzip_byte_t *) entry < disk->buffer || + (zzip_byte_t *) entry > disk->endbuf - sizeof(entry) || + ! zzip_disk_entry_check_magic(entry) || + zzip_disk_entry_sizeto_end(entry) > 64 * 1024) + return 0; + entry = zzip_disk_entry_to_next_entry(entry); + if ((zzip_byte_t *) entry > disk->endbuf - sizeof(entry) || + ! zzip_disk_entry_check_magic(entry) || + zzip_disk_entry_sizeto_end(entry) > 64 * 1024 || + zzip_disk_entry_skipto_end(entry) + sizeof(entry) > disk->endbuf) + return 0; + else + return entry; +} + +/** search for files in the (mmapped) zip central directory + * + * This function is given a filename as an additional argument, to find the + * disk_entry matching a given filename. The compare-function is usually + * strcmp or strcasecmp or perhaps strcoll, if null then strcmp is used. + * - use null as argument for "after"-entry when searching the first + * matching entry, otherwise the last returned value if you look for other + * entries with a special "compare" function (if null then a doubled search + * is rather useless with this variant of _findfile). + */ +struct zzip_disk_entry * +zzip_disk_findfile(ZZIP_DISK * disk, char *filename, + struct zzip_disk_entry *after, zzip_strcmp_fn_t compare) +{ + struct zzip_disk_entry *entry = (! after ? zzip_disk_findfirst(disk) + : zzip_disk_findnext(disk, after)); + if (! compare) + compare = (zzip_strcmp_fn_t) ((disk->flags & ZZIP_DISK_FLAGS_MATCH_NOCASE) ? + (_zzip_strcasecmp) : (strcmp)); + for (; entry; entry = zzip_disk_findnext(disk, entry)) + { + /* filenames within zip files are often not null-terminated! */ + char *realname = zzip_disk_entry_strdup_name(disk, entry); + if (realname && ! compare(filename, realname)) + { + free(realname); + return entry; + } + free(realname); + } + return 0; +} + +/** => zzip_disk_findfile + * + * This function uses a compare-function with an additional argument + * and it is called just like fnmatch(3) from POSIX.2 AD:1993), i.e. + * the argument filespec first and the ziplocal filename second with + * the integer-flags put in as third to the indirect call. If the + * platform has fnmatch available then null-compare will use that one + * and otherwise we fall back to mere strcmp, so if you need fnmatch + * searching then please provide an implementation somewhere else. + * - use null as argument for "after"-entry when searching the first + * matching entry, or the last disk_entry return-value to find the + * next entry matching the given filespec. + */ +struct zzip_disk_entry * +zzip_disk_findmatch(ZZIP_DISK * disk, char *filespec, + struct zzip_disk_entry *after, + zzip_fnmatch_fn_t compare, int flags) +{ + struct zzip_disk_entry *entry = (! after ? zzip_disk_findfirst(disk) + : zzip_disk_findnext(disk, after)); + if (! compare) + { + compare = (zzip_fnmatch_fn_t) _zzip_fnmatch; + if (disk->flags & ZZIP_DISK_FLAGS_MATCH_NOCASE) + flags |= _zzip_fnmatch_CASEFOLD; + } + for (; entry; entry = zzip_disk_findnext(disk, entry)) + { + /* filenames within zip files are often not null-terminated! */ + char *realname = zzip_disk_entry_strdup_name(disk, entry); + if (realname && ! compare(filespec, realname, flags)) + { + free(realname); + return entry; + } + free(realname); + } + return 0; +} + +/* ====================================================================== */ + +/** => zzip_disk_fopen + * + * the ZZIP_DISK_FILE* is rather simple in just encapsulating the + * arguments given to this function plus a zlib deflate buffer. + * Note that the ZZIP_DISK pointer does already contain the full + * mmapped file area of a zip disk, so open()ing a file part within + * that area happens to be a lookup of its bounds and encoding. That + * information is memorized on the ZZIP_DISK_FILE so that subsequent + * _read() operations will be able to get the next data portion or + * return an eof condition for that file part wrapped in the zip archive. + */ +zzip__new__ ZZIP_DISK_FILE * +zzip_disk_entry_fopen(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry) +{ + /* keep this in sync with zzip_mem_entry_fopen */ + struct zzip_file_header *header = + zzip_disk_entry_to_file_header(disk, entry); + if (! header) + return 0; + ___ ZZIP_DISK_FILE *file = malloc(sizeof(ZZIP_DISK_FILE)); + if (! file) + return file; + file->buffer = disk->buffer; + file->endbuf = disk->endbuf; + file->avail = zzip_file_header_usize(header); + + if (! file->avail || zzip_file_header_data_stored(header)) + { file->stored = zzip_file_header_to_data (header); return file; } + + file->stored = 0; + file->zlib.opaque = 0; + file->zlib.zalloc = Z_NULL; + file->zlib.zfree = Z_NULL; + file->zlib.avail_in = zzip_file_header_csize(header); + file->zlib.next_in = zzip_file_header_to_data(header); + + if (! zzip_file_header_data_deflated(header) || + inflateInit2(&file->zlib, -MAX_WBITS) != Z_OK) + { free (file); return 0; } + + return file; + ____; +} + +/** openening a file part wrapped within a (mmapped) zip archive + * + * This function opens a file found by name, so it does a search into + * the zip central directory with => zzip_disk_findfile and whatever + * is found first is given to => zzip_disk_entry_fopen + */ +zzip__new__ ZZIP_DISK_FILE * +zzip_disk_fopen(ZZIP_DISK * disk, char *filename) +{ + ZZIP_DISK_ENTRY *entry = zzip_disk_findfile(disk, filename, 0, 0); + if (! entry) + return 0; + else + return zzip_disk_entry_fopen(disk, entry); +} + + +/** => zzip_disk_fopen + * + * This function reads more bytes into the output buffer specified as + * arguments. The return value is null on eof or error, the stdio-like + * interface can not distinguish between these so you need to check + * with => zzip_disk_feof for the difference. + */ +zzip_size_t +zzip_disk_fread(void *ptr, zzip_size_t sized, zzip_size_t nmemb, + ZZIP_DISK_FILE * file) +{ + zzip_size_t size = sized * nmemb; + if (size > file->avail) + size = file->avail; + if (file->stored) + { + memcpy(ptr, file->stored, size); + file->stored += size; + file->avail -= size; + return size; + } + + file->zlib.avail_out = sized * nmemb; + file->zlib.next_out = ptr; + ___ zzip_size_t total_old = file->zlib.total_out; + ___ int err = inflate(&file->zlib, Z_NO_FLUSH); + if (err == Z_STREAM_END) + file->avail = 0; + else if (err == Z_OK) + file->avail -= file->zlib.total_out - total_old; + else + return 0; + return file->zlib.total_out - total_old; + ____; + ____; +} + +/** => zzip_disk_fopen + * This function releases any zlib decoder info needed for decompression + * and dumps the ZZIP_DISK_FILE* then. + */ +int +zzip_disk_fclose(ZZIP_DISK_FILE * file) +{ + if (! file->stored) + inflateEnd(&file->zlib); + free(file); + return 0; +} + +/** => zzip_disk_fopen + * + * This function allows to distinguish an error from an eof condition. + * Actually, if we found an error but we did already reach eof then we + * just keep on saying that it was an eof, so the app can just continue. + */ +int +zzip_disk_feof(ZZIP_DISK_FILE * file) +{ + return ! file || ! file->avail; +} diff --git a/project/jni/zzip/zzip/plugin.c b/project/jni/zzip/zzip/plugin.c new file mode 100644 index 000000000..a7d77c060 --- /dev/null +++ b/project/jni/zzip/zzip/plugin.c @@ -0,0 +1,86 @@ + +/* + * Author: + * Guido Draheim + * Mike Nordell + * + * Copyright (c) 2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include +#include + +#include +#include +#include +#include +#ifdef DEBUG +#include +#endif + +#include +#include + +zzip_off_t +zzip_filesize(int fd) +{ + struct stat st; + + if (fstat(fd, &st) < 0) + return -1; + +# if defined DEBUG && ! defined _WIN32 + if (! st.st_size && st.st_blocks > 1) /* seen on some darwin 10.1 machines */ + fprintf(stderr, "broken fstat(2) ?? st_size=%ld st_blocks=%ld\n", + (long) st.st_size, (long) st.st_blocks); +# endif + + return st.st_size; +} + +static const struct zzip_plugin_io default_io = { + &open, + &close, + &_zzip_read, + &_zzip_lseek, + &zzip_filesize, + 1, 1, + &_zzip_write +}; + +/** => zzip_init_io + * This function returns a zzip_plugin_io_t handle to static defaults + * wrapping the posix io file functions for actual file access. + */ +zzip_plugin_io_t +zzip_get_default_io(void) +{ + return (zzip_plugin_io_t) & default_io; +} + +/** + * This function initializes the users handler struct to default values + * being the posix io functions in default configured environments. + */ +int +zzip_init_io(zzip_plugin_io_handlers_t io, int flags) +{ + if (! io) + { + return ZZIP_ERROR; + } + memcpy(io, &default_io, sizeof(default_io)); + io->fd.sys = flags; + return 0; +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/stat.c b/project/jni/zzip/zzip/stat.c new file mode 100644 index 000000000..1c9428357 --- /dev/null +++ b/project/jni/zzip/zzip/stat.c @@ -0,0 +1,132 @@ + +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + * + * Description: + * although this file is defining a function called zzip_stat it + * will not need a real stat(2) exported by the Operating System. + * It will just try to fill the fields of the ZZIP_STAT structure + * of + */ + +#include /* exported... */ +#include +#include +#include + +#define ZZIP_USE_INTERNAL +#include + +/** + * obtain information about a filename in an opened zip-archive without + * opening that file first. Mostly used to obtain the uncompressed + * size of a file inside a zip-archive. see => zzip_dir_open. + */ +int +zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t * name, ZZIP_STAT * zs, int flags) +{ + struct zzip_dir_hdr *hdr = dir->hdr0; + int (*cmp) (zzip_char_t *, zzip_char_t *); + + cmp = (flags & ZZIP_CASEINSENSITIVE) ? strcasecmp : strcmp; + + if (! hdr) + { + dir->errcode = ZZIP_ENOENT; + return -1; + } + + if (flags & ZZIP_IGNOREPATH) + { + char *n = strrchr(name, '/'); + if (n) + name = n + 1; + } + + while (1) + { + register char *hdr_name = hdr->d_name; + if (flags & ZZIP_IGNOREPATH) + { + register char *n = strrchr(hdr_name, '/'); + if (n) + hdr_name = n + 1; + } + + if (! cmp(hdr_name, name)) + break; + + if (! hdr->d_reclen) + { + dir->errcode = ZZIP_ENOENT; + return -1; + } + + hdr = (struct zzip_dir_hdr *) ((char *) hdr + hdr->d_reclen); + } + + zs->d_compr = hdr->d_compr; + zs->d_csize = hdr->d_csize; + zs->st_size = hdr->d_usize; + zs->d_name = hdr->d_name; + + return 0; +} + +/** => zzip_dir_stat + * This function will obtain information about a opened file _within_ a + * zip-archive. The file is supposed to be open (otherwise -1 is returned). + * The st_size stat-member contains the uncompressed size. The optional + * d_name is never set here. + */ +int +zzip_file_stat(ZZIP_FILE * file, ZZIP_STAT * zs) +{ + if (! file) + return -1; + zs->d_compr = file->method; + zs->d_csize = file->csize; + zs->st_size = file->usize; + zs->d_name = 0; + return 0; +} + +/** => zzip_dir_stat + * This function will obtain information about a opened file which may be + * either real/zipped. The file is supposed to be open (otherwise -1 is + * returned). The st_size stat-member contains the uncompressed size. + * The optional d_name is never set here. For a real file, we do set the + * d_csize := st_size and d_compr := 0 for meaningful defaults. + */ +int +zzip_fstat(ZZIP_FILE * file, ZZIP_STAT * zs) +{ + if (ZZIP_file_real(file)) + { + struct stat st; + if (fstat(file->fd, &st) < 0) + return -1; + zs->st_size = st.st_size; + zs->d_csize = st.st_size; + zs->d_compr = 0; + return 0; + } else + { + return zzip_file_stat(file, zs); + } +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/write.c b/project/jni/zzip/zzip/write.c new file mode 100644 index 000000000..d862fe21d --- /dev/null +++ b/project/jni/zzip/zzip/write.c @@ -0,0 +1,493 @@ + +/* + * The write-support in zziplib is not a full-flegded interface to the + * internals that zip file-header or zip archive an contain. It's + * primary use goes for savegames or transfer `pack-n-go` archives + * where time-stamps are rather unimportant. Here we can create an + * archive with filenames and their data portions, possibly obfuscated. + * + * DONT USE THIS + * + * The write support is supposed to be added directly into the main + * zziplib but it has not been implemented so far. It does however + * export the relevant call entries which will return EROFS (read-only + * filesystem) in case they are being called. That allows later programs + * to start up with earlier versions of zziplib that can only read ZIPs. + * + * Author: + * Guido Draheim + * + * Copyright (c) 2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#define _ZZIP_WRITE_SOURCE + +#if defined DDDD || defined DDDDD || defined DDDDDD || defined DDDDDDD +#define _ZZIP_ENABLE_WRITE +#else /* per default, we add support for passthrough to posix write */ +#define _ZZIP_POSIX_WRITE +#endif + +#include /* #includes */ +#include + +#include +#include +#include +#include +#include + +#ifdef ZZIP_HAVE_DIRECT_H +#include +#endif + +#include +#include +#include + +#define ___ { +#define ____ } + +#ifndef EROFS +# ifdef ENOSYS +#define EROFS ENOSYS +# else +#define EROFS EPERM +#endif +#endif + +/* try real zlib routines for writing ? very experimental, very very ex... */ +#ifndef _ZZIP_ENABLE_WRITE +#define _ZZIP_TRY 0 +#else +#define _ZZIP_TRY 1 +#endif + +/* btw, is there any system that did define those different ? get away.. */ +# ifndef S_IWGRP +# define S_IWGRP 00020 +# endif +# ifndef S_IRWXO +# define S_IRWXO 00007 +# endif + +# ifdef ZZIP_HAVE_DIRECT_H +# define _mkdir(a,b) mkdir(a) +# else +# define _mkdir mkdir +# endif + +/** create a new zip archive for writing + * + * This function will create a new zip archive. The returned parameter + * is a new "zzip dir" handle that should be saved to a variable so it + * can be used a base argument for => zzip_mkdir and => zzip_creat calls. + * The returned handle represents a zip central directory that must be + * saved to disk using => zzip_closedir. + * + * Returns null on error and sets errno. Remember, according to posix + * the => creat(2) call is equivalent to + open (path, O_WRONLY | O_CREAT | O_TRUNC, o_mode) + * so any previous zip-archive will be overwritten unconditionally and + * EEXIST errors from => mkdir(2) are suppressed. (fixme: delete the + * given subtree? like suggested by O_TRUNC? not done so far!) + */ +ZZIP_DIR * +zzip_dir_creat(zzip_char_t * name, int o_mode) +{ + return zzip_dir_creat_ext_io(name, o_mode, 0, 0); +} + +/** => zzip_dir_creat + * + * If the third argument "ext" has another special meaning here, as it + * is used to ensure that a given zip-file is created with the first entry + * of the ext-list appended as an extension unless the file-path already + * ends with a file-extension registered in the list. Therefore {"",0} + * matches all files and creates them as zip-archives under the given + * nonmodified name. (Some magic here? If the path ends in the path + * separator then make a real directory even in the presence of ext-list?) + * + * This function is not yet implemented, check for #def ZZIP_NO_CREAT + * Write-support will extend => zzip_closedir with semantics to finalize the + * zip-archive by writing the zip-trailer and closing the archive file. + */ +ZZIP_DIR * +zzip_dir_creat_ext_io(zzip_char_t * name, int o_mode, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + if (! io) + io = zzip_get_default_io(); + + if (io != zzip_get_default_io()) + { + /* the current io-structure does not contain a "write" entry, + * and therefore this parameter is useless. Anyone to expect + * some behavior should be warned, so here we let the function + * fail bluntly - and leaving the recovery to the application + */ + errno = EINVAL; + return 0; + } + + + if (! _ZZIP_TRY) + { + /* not implemented - however, we respect that a null argument to + * zzip_mkdir and zzip_creat works, so we silently still do the mkdir + */ + if (! _mkdir(name, o_mode) || errno == EEXIST) + errno = EROFS; + return 0; + } else + { +# define MAX_EXT_LEN 10 + ZZIP_DIR *dir = zzip_dir_alloc(ext); + int name_len = strlen(name); + dir->realname = malloc(name_len + MAX_EXT_LEN); + if (! dir->realname) + goto error; + + memcpy(dir->realname, name, name_len + 1); + ___ int fd = + __zzip_try_open(dir->realname, O_EXCL | O_TRUNC | O_WRONLY, ext, + io); + if (fd != -1) + { dir->fd = fd; return dir; } + + ___ zzip_strings_t *exx = ext; + int exx_len; + for (; *exx; exx++) + { + if ((exx_len = strlen(*exx) + 1) <= name_len && + ! memcmp(dir->realname + (name_len - exx_len), *exx, exx_len)) + break; /* keep unmodified */ + exx++; + if (*exx) + continue; + + if (! (exx_len = strlen(*exx)) || exx_len >= MAX_EXT_LEN) + break; + memcpy(dir->realname + name_len, exx, exx_len); /* append! */ + } + ____; + fd = io->fd.open(dir->realname, O_CREAT | O_TRUNC | O_WRONLY, o_mode); + dir->realname[name_len] = '\0'; /* keep ummodified */ + if (fd != -1) + { dir->fd = fd; return dir; } + error: + zzip_dir_free(dir); + return 0; + ____; + } +} + +/** create a new archive area for writing + * + * This function will create a new archive area. This may either be a + * a new zip archive or a new directory in the filesystem. The returned + * parameter is a new "zzip dir" handle that should be saved to a variable + * so it can be used a base argument for => zzip_file_mkdir and + * => zzip_file_creat calls. The returned handle wraps both possibilities, + * it can be representing a zip central directory that must be + * saved to disk using => zzip_closedir or it is just a handle for the + * name of the real directory that still must be run through + * => zzip_closedir to release the wrapper around the directory name. + * + * The magic is pushed through the o_mode argument. Using a mode that + * has no group-write bit set (S_IWGRP = 0040) then the file is + * created as a zip directory. Note that this is unabridged of any + * umask value in the system where the argument to this function could + * be 0775 but with an umask of 0755 it turns out as 0755 for a real + * directory. Using 0755 directly would not create it as a real directory + * but as a zip archive handle. + * + * This function is not yet implemented, check for #def ZZIP_NO_CREAT + * Write-support will extend => zzip_closedir with semantics to finalize the + * zip-archive by writing the zip-trailer and closing the archive file. + * + * Returns null on error and sets errno. Remember, according to posix + * the => creat(2) call is equivalent to + open (path, O_WRONLY | O_CREAT | O_TRUNC, o_mode) + * so any previous zip-archive will be overwritten unconditionally and + * EEXIST errors from => mkdir(2) are suppressed. (fixme: delete the + * given subtree? like suggested by O_TRUNC? not done so far!) + */ +ZZIP_DIR * +zzip_createdir(zzip_char_t * name, int o_mode) +{ + if (o_mode & S_IWGRP) + { + if (-1 == _mkdir(name, o_mode) && errno != EEXIST) /* fail */ + return 0; + return zzip_opendir(name); + } else + return zzip_dir_creat(name, o_mode); +} + +/** => zzip_file_creat also: mkdir(2), creat(2), zzip_dir_creat + * + * This function has an additional primary argument over the posix + * mkdir(2) - if it is null then this function behaves just like + * posix mkdir(2). The zzip_dir argument can be set to the result + * of a => zzip_createdir which allows for some magic that the + * given directory name is created as an entry in the zip archive. + * + * If the given dir name argument is not within the basepath of + * the zip central directory then a real directory is created. + * Any EEXIST errors are not suppressed unlike with => zzip_createdir + * + * Standard usage accepts a global/threaded/modular ZZIP_DIR pointer + * for all zip archive operations like in: + ZZIP_DIR* zip = zzip_createdir (sysconfpath, 0755, zip); + zzip_file_mkdir (zip, filepath[i], 0755); + ZZIP_FILE* file = zzip_file_creat (zip, filename[i], 0644); + zzip_write (file, buf, len); + zzip_close (file); file = 0; + zzip_closedir (zip); zip = 0; + * + * compare with => zzip_mkdir inline macro which allows to + * collapse the examples script to + #define zzip_savefile myproject_saveconfig + #include + ZZIP_DIR* zzip_savefile = zzip_createdir (sysconfpath, 0755); + zzip_mkdir (filepath[i], 0755); + ZZIP_FILE* file = zzip_creat(filepath[i], 0644); + zzip_write (file, buf, len); + zzip_close (file); file = 0; + zzip_closedir (zip_savefile); + */ +int +zzip_file_mkdir(ZZIP_DIR * dir, zzip_char_t * name, int o_mode) +{ + if (! dir) + return _mkdir(name, o_mode); + + if (! _ZZIP_TRY) + { /* not implemented */ + errno = EROFS; + return -1; + } else + { + errno = EROFS; + return -1; + } +} + +/** start next file entry in a zip archive + * + * This function will create a new file within a zzip archive, the + * one given as the primary argument and additionally to the posix + * creat(2) - just like zzip_mkdir has an additional argument over + * the posix mkdir(2) spec. For this function the primary parameter + * can be null as well thereby creating a real file instead of a new + * one inside the zip-archive otherwise given. If the primary parameter is + * not null but wraps a real directory then all new files are also real. + * + * This function is not yet implemented, check for #def ZZIP_NO_CREAT + * + * Returns NULL on an error setting errno, and opening a file _within_ + * a zip archive using O_RDONLY (and similar stuff) will surely lead to + * an error. + */ +ZZIP_FILE * +zzip_file_creat(ZZIP_DIR * dir, zzip_char_t * name, int o_mode) +{ + if (! dir) + return zzip_open(name, o_mode); + + if (! _ZZIP_TRY) + { /* not implemented */ + errno = EROFS; + return 0; + } else + { + errno = EROFS; + return 0; + } +} + +/** write to zzip storage also: write(2), zlib(3) + * + * This function will write data to a file descriptor. If the file + * descriptor represents a real file then it will be forwarded to + * call posix => write(2) directly. If it is a descriptor for a + * file within a zip directory then the data will be "deflated" + * using => zlib(3) and appended to the zip archive file. + */ +zzip_ssize_t +zzip_write(ZZIP_FILE * file, const void *ptr, zzip_size_t len) +{ + if (zzip_file_real(file)) + return write(zzip_realfd(file), ptr, len); + else + return zzip_file_write(file, ptr, len); +} + +/** => zzip_write also: zzip_file_creat + * + * This function will write data to a file descriptor inside a zip + * archive. The data will be "deflated" using => zlib(3) compression + * and appended to the end of the zip archive file. Only one file + * descriptor may be open per zzip_dir archive handle (fifo-like). + * + * This function is not yet implemented, check for #def ZZIP_NO_CREAT + * It returns immediately -1 and sets errno=EROFS for indication. + */ +zzip_ssize_t +zzip_file_write(ZZIP_FILE * file, const void *ptr, zzip_size_t len) +{ + if (! _ZZIP_TRY) + { /* not implemented */ + errno = EROFS; + return -1; + } else + { + /* add calls to zlib here... */ + errno = EROFS; + return -1; + } +} + +/** => zzip_write + * This function is the stdc variant for writing and the arguments + * are forwarded to => zzip_write - the return value is floored to + * null as for STDC spec but there is no zzip_ferror call so far + * for the zziplib (later? is it actually needed?). + * + * This function is not yet implemented, check for #def ZZIP_NO_CREAT + * Write-support extends => zzip_close with semantics to write out a + * file-trailer to the zip-archive leaving a name/offset marker in + * the (still-open) ZZIP_DIR handle. + */ +zzip_size_t +zzip_fwrite(const void *ptr, zzip_size_t len, zzip_size_t multiply, + ZZIP_FILE * file) +{ + zzip_ssize_t value = zzip_write(file, ptr, len * multiply); + if (value == -1) + value = 0; + return (zzip_size_t) value; +} + +#if 0 /* pure documentation */ + +/** create a zipped file/directory also: zzip_dir_creat, mkdir(2) + * + * This function creates a directory entry in the default zip-archive. + * If you did not specify a "#define zzip_savefile somevar" + * then the default zip-archive is null and all directories are + * created as real directories in the filesystem. This function is + * really a preprocessor macro or preferably an inline function + * around => zzip_file_mkdir, there is no such symbol generated + * into the library. The prototype is modelled after the posix + * => mkdir(2) call. + #ifndef zzip_savefile + #define zzip_savefile 0 + #endif + #define zzip_mkdir(name,mode) \ - + zzip_file_mkdir(zzip_savefile,name,mode) + * + */ +int inline +zzip_mkdir(zzip_char_t * name, int o_mode) +{ + return zzip_file_creat(zzip_savefile, name, mode); +} +#endif + +#if 0 /* pure documentation */ + +/** => zzip_mkdir also: creat(2), zzip_start + * + * This function creates a file in the default zip-archive. + * If you did not specify a "#define zzip_savefile somevar" + * then the default zip-archive is null and all files are created + * as real files. This function is really a preprocessor macro + * or preferably an inline function around => zzip_file_creat, + * there is no such symbol generated into the library. The prototype + * is modelled after the posix => creat(2) call. + #ifndef zzip_savefile + #define zzip_savefile 0 + #endif + #define zzip_creat(name,mode) \ - + zzip_file_creat(zzip_savefile,name,mode) + */ +ZZIP_FILE *inline +zzip_creat(zzip_char_t * name, int o_mode) +{ + return zzip_file_creat(zzip_savefile, name, mode); +} +#endif + + +#if 0 /* pure documentation */ + +/** start writing to the magic zzip_savefile also: zzip_creat, zzip_write + * + * open a zip archive for writing via the magic zzip_savefile macro + * variable. The name and mode are given to => zzip_createdir and + * the result is stored into => zzip_savefile - if the => zzip_savefile + * did already have a zzip_dir handle then it is automatically + * finalized with => zzip_sync and the handle closed and the + * zzip_savefile variable reused for the new zip archive just started + * with this call. - This function is really a preprocessor macro + * or preferably an inline function around => zzip_dir_create, there + * is no such symbol generated into the library. + #ifndef zzip_savefile + #define zzip_savefile 0 + #endif + #define zzip_start(name,mode,ext) \ - + { if (zzip_savefile) zzip_closedir(zzip_savefile); \ - + zzip_savefile = zzip_createdir(name,mode,ext); } + * This function returns null on error or a zzip_dir handle on + * success. It is perfectly okay to continue with a null in the + * zzip_savefile variable since it makes subsequent calls to + * => zzip_creat and => zzip_mkdir to run as => creat(2) / => mkdir(2) + * on the real filesystem. + */ +void inline +zzip_mkfifo(zzip_char_t * name, int o_mode) +{ + if (zzip_savefile) + zzip_closedir(zzip_savefile); + zzip_savefile = zzip_createdir(name, o_mode); +} +#endif + +#if 0 /* pure documentation */ + +/** => zzip_mkfifo also: zzip_closedir, sync(2) + * + * finalize a zip archive thereby writing the central directory to + * the end of the file. If it was a real directory then we do just + * nothing - even that the prototype of the call itself is modelled + * to be similar to the posix => sync(2) call. This function is + * really a preprocessor macro or preferably an inline function + * around => zzip_closedir, there is no such symbol generated + * into the library. + #ifndef zzip_savefile + #define zzip_savefile 0 + #endif + #define zzip_sync(name,mode) \ - + { zzip_closedir(zzip_savefile); zzip_savefile = 0; } + * + */ +void inline +zzip_sync(void) +{ + zzip_closedir(zzip_savefile); + zzip_savefile = 0; +} +#endif + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ diff --git a/project/jni/zzip/zzip/zip.c b/project/jni/zzip/zzip/zip.c new file mode 100644 index 000000000..eacd689ca --- /dev/null +++ b/project/jni/zzip/zzip/zip.c @@ -0,0 +1,863 @@ + +/* + * Author: + * Guido Draheim + * Tomi Ollila + * + * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#include /* archive handling */ +#include +#include +#include + +#include +#include +#include +#include +#include +#ifdef ZZIP_HAVE_SYS_STAT_H +#include +#endif + +#include +#include + +#define __sizeof(X) ((zzip_ssize_t)(sizeof(X))) + +#ifndef ZZIP_EASY +/* per default, we use a little hack to correct bad z_rootseek parts */ +#define ZZIP_CORRECT_ROOTSEEK 1 +#endif + +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ >= 4) +# ifdef DEBUG +# warning suppress a warning where the compiler should have optimized instead. +# endif +#define _255 254 +#else +#define _255 255 +#endif + +#define ZZIP_DISK64_TRAILER 1 + +#ifdef ZZIP_DISK64_TRAILER +struct _disk_trailer +{ + void *zz_tail; + void *zz_for_correct_rootseek; // ZZIP_CORRECT_ROOTSEEK + zzip_off64_t zz_entries; + zzip_off64_t zz_finalentries; + zzip_off64_t zz_rootseek; + zzip_off64_t zz_rootsize; +}; +#define _disk_trailer_entries(__p) ((__p)->zz_entries) +#define _disk_trailer_localentries(__p) ((__p)->zz_entries) +#define _disk_trailer_finalentries(__p) ((__p)->zz_entries) +#define _disk_trailer_rootseek(__p) ((__p)->zz_rootseek) +#define _disk_trailer_rootsize(__p) ((__p)->zz_rootsize) +#define _disk_trailer_set_rootseek(__p,__v) ((__p)->rootseek = (__v)) + +#else +#define _disk_trailer zzip_disk_trailer +#define _disk_trailer_entries zzip_disk_trailer_entries +#define _disk_trailer_localentries zzip_disk_trailer_localentries +#define _disk_trailer_finalentries zzip_disk_trailer_finalentries +#define _disk_trailer_rootseek zzip_disk_trailer_rootseek +#define _disk_trailer_rootsize zzip_disk_trailer_rootsize +#define _disk_trailer_set_rootseek zzip_disk_trailer_set_rootseek +#define __zzip_fetch_disk_trailer __zzip_find_disk_trailer +#endif + +/* --------------------------- internals -------------------------------- */ + +/* internal functions of zziplib, avoid at all cost, changes w/o warning. + * we do export them for debugging purpose and special external tools + * which know what they do and which can adapt from version to version + */ + +int __zzip_fetch_disk_trailer(int fd, zzip_off_t filesize, + struct _disk_trailer *_zzip_restrict trailer, + zzip_plugin_io_t io); +int __zzip_parse_root_directory(int fd, + struct _disk_trailer *trailer, + struct zzip_dir_hdr **hdr_return, + zzip_plugin_io_t io); + +_zzip_inline char *__zzip_aligned4(char *p); + +/* ------------------------ harden routines ------------------------------ */ + +#ifdef ZZIP_HARDEN + +/* + * check for inconsistent values in trailer and prefer lower seek value + * - we fix values assuming the root directory was written at the end + * and it is just before the zip trailer. Therefore, ... + */ +_zzip_inline static void +__fixup_rootseek(zzip_off_t offset_of_trailer, struct _disk_trailer *trailer) +{ + if (_disk_trailer_rootseek(trailer) > + offset_of_trailer - _disk_trailer_rootsize(trailer) && + offset_of_trailer > _disk_trailer_rootsize(trailer)) + { + register zzip_off_t offset; + offset = offset_of_trailer - _disk_trailer_rootsize(trailer); + _disk_trailer_set_rootseek(trailer, offset); + HINT2("new rootseek=%li", (long) _disk_trailer_rootseek(trailer)); + } +} + +#define __correct_rootseek(A,B,C) + +#elif defined ZZIP_CORRECT_ROOTSEEK + +/* store the seekvalue of the trailer into the "z_magic" field and with + * a 64bit off_t we overwrite z_disk/z_finaldisk as well. If you change + * anything in zziplib or dump the trailer structure then watch out that + * these are still unused, so that this code may still (ab)use those. */ +#define __fixup_rootseek(_offset_of_trailer, _trailer) \ + *(zzip_off_t*)_trailer = _offset_of_trailer; +#define __correct_rootseek( _u_rootseek, _u_rootsize, _trailer) \ + if (_u_rootseek > *(zzip_off_t*)_trailer - _u_rootsize) \ + _u_rootseek = *(zzip_off_t*)_trailer - _u_rootsize; +#else +#define __fixup_rootseek(A,B) +#define __correct_rootseek(A,B,C) +#endif + + +#ifdef DEBUG +_zzip_inline static void +__debug_dir_hdr(struct zzip_dir_hdr *hdr) +{ + if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_disk_entry)) + { WARN1("internal sizeof-mismatch may break wreakage"); } + /* the internal directory structure is never bigger than the + * external zip central directory space had been beforehand + * (as long as the following assertion holds...) + */ + + if (((zzip_off_t) hdr) & 3) + { + NOTE1("this machine's malloc(3) returns sth. not u32-aligned"); + } + /* we assume that if this machine's malloc has returned a non-aligned + * memory block, then it is actually safe to access misaligned data, and + * since it does only affect the first hdr it should not even bring about + * too much of that cpu's speed penalty + */ +} +#else +#define __debug_dir_hdr(X) +#endif + +/* -------------------------- low-level interface -------------------------- */ + +#if defined BUFSIZ +#if BUFSIZ == 1024 || BUFSIZ == 512 || BUFSIZ == 256 +#define ZZIP_BUFSIZ BUFSIZ +#endif +#endif + +#ifndef ZZIP_BUFSIZ +#define ZZIP_BUFSIZ 512 + +/* #define ZZIP_BUFSIZ 64 / * for testing */ +#endif + +/** + * This function is used by => zzip_file_open. It tries to find + * the zip's central directory info that is usually a few + * bytes off the end of the file. + */ +int +__zzip_fetch_disk_trailer(int fd, zzip_off_t filesize, + struct _disk_trailer *_zzip_restrict trailer, + zzip_plugin_io_t io) +{ +#ifdef DEBUG +#define return(val) { e=val; HINT2("%s", zzip_strerror(e)); goto cleanup; } +#else +#define return(val) { e=val; goto cleanup; } +#endif + register int e; + +#ifndef _LOWSTK + auto char buffer[2 * ZZIP_BUFSIZ]; + char *buf = buffer; +#else + char *buf = malloc(2 * ZZIP_BUFSIZ); +#endif + zzip_off_t offset = 0; + zzip_ssize_t maplen = 0; /* mmap(),read(),getpagesize() use size_t !! */ + char *fd_map = 0; + + if (! trailer) + { return(EINVAL); } + + if (filesize < __sizeof(struct zzip_disk_trailer)) + { return(ZZIP_DIR_TOO_SHORT); } + + if (! buf) + { return(ZZIP_OUTOFMEM); } + + offset = filesize; /* a.k.a. old offset */ + while (1) /* outer loop */ + { + register unsigned char *mapped; + + if (offset <= 0) + { return(ZZIP_DIR_EDH_MISSING); } + + /* trailer cannot be farther away than 64K from fileend */ + if (filesize - offset > 64 * 1024) + { return(ZZIP_DIR_EDH_MISSING); } + + /* the new offset shall overlap with the area after the old offset! */ + if (USE_MMAP && io->fd.sys) + { + zzip_off_t mapoff = offset; + { + zzip_ssize_t pagesize = _zzip_getpagesize(io->fd.sys); + if (pagesize < ZZIP_BUFSIZ) + goto non_mmap; /* an error? */ + if (mapoff == filesize && filesize > pagesize) + mapoff -= pagesize; + if (mapoff < pagesize) + { + maplen = (zzip_ssize_t) mapoff + pagesize; + mapoff = 0; + } else + { + mapoff -= pagesize; + maplen = 2 * pagesize; + if ((zzip_ssize_t) mapoff & (pagesize - 1)) + { /*only 1. run */ + pagesize -= (zzip_ssize_t) mapoff & (pagesize - 1); + mapoff += pagesize; + maplen -= pagesize; + } + } + if (mapoff + maplen > filesize) + maplen = filesize - mapoff; + } + + fd_map = _zzip_mmap(io->fd.sys, fd, mapoff, (zzip_size_t) maplen); + if (fd_map == MAP_FAILED) + goto non_mmap; + mapped = (unsigned char *) fd_map; + offset = mapoff; /* success */ + HINT3("mapped *%p len=%li", fd_map, (long) maplen); + } else + { + non_mmap: + fd_map = 0; /* have no mmap */ + { + zzip_off_t pagesize = ZZIP_BUFSIZ; + if (offset == filesize && filesize > pagesize) + offset -= pagesize; + if (offset < pagesize) + { + maplen = (zzip_ssize_t) offset + pagesize; + offset = 0; + } else + { + offset -= pagesize; + maplen = 2 * pagesize; + if ((zzip_ssize_t) offset & (pagesize - 1)) + { /*on 1st run */ + pagesize -= (zzip_ssize_t) offset & (pagesize - 1); + offset += pagesize; + maplen -= pagesize; + } + } + if (offset + maplen > filesize) + maplen = filesize - offset; + } + + if (io->fd.seeks(fd, offset, SEEK_SET) < 0) + { return(ZZIP_DIR_SEEK); } + if (io->fd.read(fd, buf, (zzip_size_t) maplen) < maplen) + { return(ZZIP_DIR_READ); } + mapped = (unsigned char *) buf; /* success */ + HINT5("offs=$%lx len=%li filesize=%li pagesize=%i", + (long) offset, (long) maplen, (long) filesize, ZZIP_BUFSIZ); + } + + { /* now, check for the trailer-magic, hopefully near the end of file */ + register unsigned char *end = mapped + maplen; + register unsigned char *tail; + for (tail = end - 1; (tail >= mapped); tail--) + { + if ((*tail == 'P') && /* quick pre-check for trailer magic */ + end - tail >= __sizeof(struct zzip_disk_trailer) - 2 && + zzip_disk_trailer_check_magic(tail)) + { +# ifndef ZZIP_DISK64_TRAILER + /* if the file-comment is not present, it happens + that the z_comment field often isn't either */ + if (end - tail >= __sizeof(*trailer)) + { + memcpy(trailer, tail, sizeof(*trailer)); + } else + { + memcpy(trailer, tail, sizeof(*trailer) - 2); + trailer->z_comment[0] = 0; + trailer->z_comment[1] = 0; + } +# else + struct zzip_disk_trailer *orig = + (struct zzip_disk_trailer *) tail; + trailer->zz_tail = tail; + trailer->zz_entries = zzip_disk_trailer_localentries(orig); + trailer->zz_finalentries = + zzip_disk_trailer_finalentries(orig); + trailer->zz_rootseek = zzip_disk_trailer_rootseek(orig); + trailer->zz_rootsize = zzip_disk_trailer_rootsize(orig); +# endif + + __fixup_rootseek(offset + tail - mapped, trailer); + { return(0); } + } else if ((*tail == 'P') && + end - tail >= + __sizeof(struct zzip_disk64_trailer) - 2 + && zzip_disk64_trailer_check_magic(tail)) + { +# ifndef ZZIP_DISK64_TRAILER + return (ZZIP_DIR_LARGEFILE); +# else + struct zzip_disk64_trailer *orig = + (struct zzip_disk64_trailer *) tail; + trailer->zz_tail = tail; + trailer->zz_entries = + zzip_disk64_trailer_localentries(orig); + trailer->zz_finalentries = + zzip_disk64_trailer_finalentries(orig); + trailer->zz_rootseek = zzip_disk64_trailer_rootseek(orig); + trailer->zz_rootsize = zzip_disk64_trailer_rootsize(orig); + { return(0); } +# endif + } + } + } + + if (USE_MMAP && fd_map) + { + HINT3("unmap *%p len=%li", fd_map, (long) maplen); + _zzip_munmap(io->fd.sys, fd_map, (zzip_size_t) maplen); + fd_map = 0; + } + } /*outer loop */ + + cleanup: + if (USE_MMAP && fd_map) + { + HINT3("unmap *%p len=%li", fd_map, (long) maplen); + _zzip_munmap(io->fd.sys, fd_map, (zzip_size_t) maplen); + } +# ifdef _LOWSTK + free(buf); +# endif +# undef return + return e; +} + +/* + * making pointer alignments to values that can be handled as structures + * is tricky. We assume here that an align(4) is sufficient even for + * 64 bit machines. Note that binary operations are not usually allowed + * to pointer types but we do need only the lower bits in this implementation, + * so we can just cast the value to a long value. + */ +_zzip_inline char * +__zzip_aligned4(char *p) +{ +#define aligned4 __zzip_aligned4 + p += ((long) p) & 1; /* warnings about truncation of a "pointer" */ + p += ((long) p) & 2; /* to a "long int" may be safely ignored :) */ + return p; +} + +/** + * This function is used by => zzip_file_open, it is usually called after + * => __zzip_find_disk_trailer. It will parse the zip's central directory + * information and create a zziplib private directory table in + * memory. + */ +int +__zzip_parse_root_directory(int fd, + struct _disk_trailer *trailer, + struct zzip_dir_hdr **hdr_return, + zzip_plugin_io_t io) +{ + auto struct zzip_disk_entry dirent; + struct zzip_dir_hdr *hdr; + struct zzip_dir_hdr *hdr0; + uint16_t *p_reclen = 0; + zzip_off64_t entries; + zzip_off64_t zz_offset; /* offset from start of root directory */ + char *fd_map = 0; + zzip_off64_t zz_fd_gap = 0; + zzip_off64_t zz_entries = _disk_trailer_localentries(trailer); + zzip_off64_t zz_rootsize = _disk_trailer_rootsize(trailer); + zzip_off64_t zz_rootseek = _disk_trailer_rootseek(trailer); + __correct_rootseek(zz_rootseek, zz_rootsize, trailer); + + hdr0 = (struct zzip_dir_hdr *) malloc(zz_rootsize); + if (! hdr0) + return ZZIP_DIRSIZE; + hdr = hdr0; + __debug_dir_hdr(hdr); + + if (USE_MMAP && io->fd.sys) + { + zz_fd_gap = zz_rootseek & (_zzip_getpagesize(io->fd.sys) - 1); + HINT4(" fd_gap=%ld, mapseek=0x%lx, maplen=%ld", (long) (zz_fd_gap), + (long) (zz_rootseek - zz_fd_gap), + (long) (zz_rootsize + zz_fd_gap)); + fd_map = + _zzip_mmap(io->fd.sys, fd, zz_rootseek - zz_fd_gap, + zz_rootsize + zz_fd_gap); + /* if mmap failed we will fallback to seek/read mode */ + if (fd_map == MAP_FAILED) + { + NOTE2("map failed: %s", strerror(errno)); + fd_map = 0; + } else + { + HINT3("mapped *%p len=%li", fd_map, + (long) (zz_rootsize + zz_fd_gap)); + } + } + + for (entries=0, zz_offset=0; ; entries++) + { + register struct zzip_disk_entry *d; + uint16_t u_extras, u_comment, u_namlen; + +# ifndef ZZIP_ALLOW_MODULO_ENTRIES + if (entries >= zz_entries) { + if (zz_offset + 256 < zz_rootsize) { + FAIL4("%li's entry is long before the end of directory - enable modulo_entries? (O:%li R:%li)", + (long) entries, (long) (zz_offset), (long) zz_rootsize); + } + break; + } +# endif + + if (fd_map) + { d = (void*)(fd_map+zz_fd_gap+zz_offset); } /* fd_map+fd_gap==u_rootseek */ + else + { + if (io->fd.seeks(fd, zz_rootseek + zz_offset, SEEK_SET) < 0) + return ZZIP_DIR_SEEK; + if (io->fd.read(fd, &dirent, sizeof(dirent)) < __sizeof(dirent)) + return ZZIP_DIR_READ; + d = &dirent; + } + + if (! zzip_disk_entry_check_magic(d)) { +# ifndef ZZIP_ALLOW_MODULO_ENTRIES + FAIL4("%li's entry has no disk_entry magic indicator (O:%li R:%li)", + (long) entries, (long) (zz_offset), (long) zz_rootsize); +# endif + break; + } + + if ((zzip_off64_t) (zz_offset + sizeof(*d)) > zz_rootsize || + (zzip_off64_t) (zz_offset + sizeof(*d)) < 0) + { + FAIL4("%li's entry stretches beyond root directory (O:%li R:%li)", + (long) entries, (long) (zz_offset), (long) zz_rootsize); + break; + } +# if 0 && defined DEBUG + zzip_debug_xbuf((unsigned char *) d, sizeof(*d) + 8); +# endif + + u_extras = zzip_disk_entry_get_extras(d); + u_comment = zzip_disk_entry_get_comment(d); + u_namlen = zzip_disk_entry_get_namlen(d); + HINT5("offset=0x%lx, size %ld, dirent *%p, hdr %p\n", + (long) (zz_offset + zz_rootseek), (long) zz_rootsize, d, hdr); + + /* writes over the read buffer, Since the structure where data is + copied is smaller than the data in buffer this can be done. + It is important that the order of setting the fields is considered + when filling the structure, so that some data is not trashed in + first structure read. + at the end the whole copied list of structures is copied into + newly allocated buffer */ + hdr->d_crc32 = zzip_disk_entry_get_crc32(d); + hdr->d_csize = zzip_disk_entry_get_csize(d); + hdr->d_usize = zzip_disk_entry_get_usize(d); + hdr->d_off = zzip_disk_entry_get_offset(d); + hdr->d_compr = zzip_disk_entry_get_compr(d); + if (hdr->d_compr > _255) + hdr->d_compr = 255; + + if ((zzip_off64_t) (zz_offset + sizeof(*d) + u_namlen) > zz_rootsize || + (zzip_off64_t) (zz_offset + sizeof(*d) + u_namlen) < 0) + { + FAIL4("%li's name stretches beyond root directory (O:%li N:%li)", + (long) entries, (long) (zz_offset), (long) (u_namlen)); + break; + } + + if (fd_map) + { memcpy(hdr->d_name, fd_map+zz_fd_gap + zz_offset+sizeof(*d), u_namlen); } + else + { io->fd.read(fd, hdr->d_name, u_namlen); } + hdr->d_name[u_namlen] = '\0'; + hdr->d_namlen = u_namlen; + + /* update offset by the total length of this entry -> next entry */ + zz_offset += sizeof(*d) + u_namlen + u_extras + u_comment; + + if (zz_offset > zz_rootsize) + { + FAIL3("%li's entry stretches beyond root directory (O:%li)", + (long) entries, (long) (zz_offset)); + entries ++; + break; + } + + HINT5("file %ld { compr=%d crc32=$%x offset=%d", + (long) entries, hdr->d_compr, hdr->d_crc32, hdr->d_off); + HINT5("csize=%d usize=%d namlen=%d extras=%d", + hdr->d_csize, hdr->d_usize, u_namlen, u_extras); + HINT5("comment=%d name='%s' %s } ", + u_comment, hdr->d_name, "", (int) sizeof(*d)); + + p_reclen = &hdr->d_reclen; + + { + register char *p = (char *) hdr; + register char *q = aligned4(p + sizeof(*hdr) + u_namlen + 1); + *p_reclen = (uint16_t) (q - p); + hdr = (struct zzip_dir_hdr *) q; + } + } /*for */ + + if (USE_MMAP && fd_map) + { + HINT3("unmap *%p len=%li", fd_map, (long) (zz_rootsize + zz_fd_gap)); + _zzip_munmap(io->fd.sys, fd_map, zz_rootsize + zz_fd_gap); + } + + if (p_reclen) + { + *p_reclen = 0; /* mark end of list */ + + if (hdr_return) + *hdr_return = hdr0; + } /* else zero (sane) entries */ +# ifndef ZZIP_ALLOW_MODULO_ENTRIES + return (entries != zz_entries ? ZZIP_CORRUPTED : 0); +# else + return ((entries & (unsigned)0xFFFF) != zz_entries ? ZZIP_CORRUPTED : 0); +# endif +} + +/* ------------------------- high-level interface ------------------------- */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +static zzip_strings_t * +zzip_get_default_ext(void) +{ + static zzip_strings_t ext[] = { + /* *INDENT-OFF* */ + ".zip", ".ZIP", /* common extension */ +# ifdef ZZIP_USE_ZIPLIKES + ".pk3", ".PK3", /* ID Software's Quake3 zipfiles */ + ".jar", ".JAR", /* Java zipfiles */ +# endif + /* *INDENT-ON* */ + 0 + }; + + return ext; +} + +/** + * allocate a new ZZIP_DIR handle and do basic + * initializations before usage by => zzip_dir_fdopen + * => zzip_dir_open => zzip_file_open or through + * => zzip_open + * (ext==null flags uses { ".zip" , ".ZIP" } ) + * (io ==null flags use of posix io defaults) + */ +ZZIP_DIR * +zzip_dir_alloc_ext_io(zzip_strings_t * ext, const zzip_plugin_io_t io) +{ + ZZIP_DIR *dir; + if ((dir = (ZZIP_DIR *) calloc(1, sizeof(*dir))) == NULL) + return 0; + + /* dir->fileext is currently unused - so what, still initialize it */ + dir->fileext = ext ? ext : zzip_get_default_ext(); + dir->io = io ? io : zzip_get_default_io(); + return dir; +} + +/** => zzip_dir_alloc_ext_io + * this function is obsolete - it was generally used for implementation + * and exported to let other code build on it. It is now advised to + * use => zzip_dir_alloc_ext_io now on explicitly, just set that second + * argument to zero to achieve the same functionality as the old style. + */ +ZZIP_DIR * +zzip_dir_alloc(zzip_strings_t * fileext) +{ + return zzip_dir_alloc_ext_io(fileext, 0); +} + +/** + * will free the zzip_dir handle unless there are still + * zzip_files attached (that may use its cache buffer). + * This is the inverse of => zzip_dir_alloc , and both + * are helper functions used implicitly in other zzipcalls + * e.g. => zzip_dir_close = zzip_close + * + * returns zero on sucess + * returns the refcount when files are attached. + */ +int +zzip_dir_free(ZZIP_DIR * dir) +{ + if (dir->refcount) + return (dir->refcount); /* still open files attached */ + + if (dir->fd >= 0) + dir->io->fd.close(dir->fd); + if (dir->hdr0) + free(dir->hdr0); + if (dir->cache.fp) + free(dir->cache.fp); + if (dir->cache.buf32k) + free(dir->cache.buf32k); + if (dir->realname) + free(dir->realname); + free(dir); + return 0; +} + +/** => zzip_dir_free + * It will also => free(2) the => ZZIP_DIR-handle given. + * the counterpart for => zzip_dir_open + * see also => zzip_dir_free + */ +int +zzip_dir_close(ZZIP_DIR * dir) +{ + dir->refcount &= ~0x10000000; /* explicit dir close */ + return zzip_dir_free(dir); +} + +/** + * used by the => zzip_dir_open and zzip_opendir(2) call. Opens the + * zip-archive as specified with the fd which points to an + * already openend file. This function then search and parse + * the zip's central directory. + * + * NOTE: refcount is zero, so an _open/_close pair will also delete + * this _dirhandle + */ +ZZIP_DIR * +zzip_dir_fdopen(int fd, zzip_error_t * errcode_p) +{ + return zzip_dir_fdopen_ext_io(fd, errcode_p, 0, 0); +} + +static zzip_error_t __zzip_dir_parse(ZZIP_DIR * dir); /* forward */ + +/** => zzip_dir_fdopen + * this function uses explicit ext and io instead of the internal + * defaults, setting these to zero is equivalent to => zzip_dir_fdopen + */ +ZZIP_DIR * +zzip_dir_fdopen_ext_io(int fd, zzip_error_t * errcode_p, + zzip_strings_t * ext, const zzip_plugin_io_t io) +{ + zzip_error_t rv; + ZZIP_DIR *dir; + + if ((dir = zzip_dir_alloc_ext_io(ext, io)) == NULL) + { rv = ZZIP_OUTOFMEM; goto error; } + + dir->fd = fd; + if ((rv = __zzip_dir_parse(dir))) + goto error; + + dir->hdr = dir->hdr0; + dir->refcount |= 0x10000000; + + if (errcode_p) + *errcode_p = rv; + return dir; + error: + if (dir) + zzip_dir_free(dir); + if (errcode_p) + *errcode_p = rv; + return NULL; +} + +static zzip_error_t +__zzip_dir_parse(ZZIP_DIR * dir) +{ + zzip_error_t rv; + zzip_off_t filesize; + struct _disk_trailer trailer; + /* if (! dir || dir->fd < 0) + * { rv = EINVAL; goto error; } + */ + + HINT2("------------------ fd=%i", (int) dir->fd); + if ((filesize = dir->io->fd.filesize(dir->fd)) < 0) + { rv = ZZIP_DIR_STAT; goto error; } + + HINT2("------------------ filesize=%ld", (long) filesize); + if ((rv = __zzip_fetch_disk_trailer(dir->fd, filesize, &trailer, + dir->io)) != 0) + { goto error; } + + HINT5("directory = { entries= %ld/%ld, size= %ld, seek= %ld } ", + (long) _disk_trailer_localentries(&trailer), + (long) _disk_trailer_finalentries(&trailer), + (long) _disk_trailer_rootsize(&trailer), + (long) _disk_trailer_rootseek(&trailer)); + + if ((rv = __zzip_parse_root_directory(dir->fd, &trailer, &dir->hdr0, + dir->io)) != 0) + { goto error; } + error: + return rv; +} + +/** + * This function will attach any of the .zip extensions then + * trying to open it the with => open(2). This is a helper + * function for => zzip_dir_open, => zzip_opendir and => zzip_open. + * + * This function returns a new system file handle or -1 on error. + * On error this function leaves the errno(3) of the underlying + * open(2) call on the last file. + */ +int +__zzip_try_open(zzip_char_t * filename, int filemode, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + auto char file[PATH_MAX]; + int fd; + zzip_size_t len = strlen(filename); + + if (len + 4 >= PATH_MAX) + { errno = ENAMETOOLONG; return -1; } + memcpy(file, filename, len + 1); + + if (! io) + io = zzip_get_default_io(); + if (! ext) + ext = zzip_get_default_ext(); + + for (; *ext; ++ext) + { + strcpy(file + len, *ext); + fd = io->fd.open(file, filemode); + if (fd != -1) + return fd; + } + return -1; +} + +/** + * Opens the zip-archive (if available). + * the two ext_io arguments will default to use posix io and + * a set of default fileext that can atleast add .zip ext itself. + */ +ZZIP_DIR * +zzip_dir_open(zzip_char_t * filename, zzip_error_t * e) +{ + return zzip_dir_open_ext_io(filename, e, 0, 0); +} + +/** => zzip_dir_open + * this function uses explicit ext and io instead of the internal + * defaults. Setting these to zero is equivalent to => zzip_dir_open + */ +ZZIP_DIR * +zzip_dir_open_ext_io(zzip_char_t * filename, zzip_error_t * e, + zzip_strings_t * ext, zzip_plugin_io_t io) +{ + int fd; + + if (! io) + io = zzip_get_default_io(); + if (! ext) + ext = zzip_get_default_ext(); + + fd = io->fd.open(filename, O_RDONLY | O_BINARY); + if (fd != -1) + { + return zzip_dir_fdopen_ext_io(fd, e, ext, io); + } else + { + fd = __zzip_try_open(filename, O_RDONLY | O_BINARY, ext, io); + if (fd != -1) + { + return zzip_dir_fdopen_ext_io(fd, e, ext, io); + } else + { + if (e) + { *e = ZZIP_DIR_OPEN; } + return 0; + } + } +} + +/** => zzip_dir_open + * fills the dirent-argument with the values and + * increments the read-pointer of the dir-argument. + * + * returns 0 if there no entry (anymore). + */ +int +zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * d) +{ + if (! dir || ! dir->hdr || ! d) + return 0; + + d->d_compr = dir->hdr->d_compr; + d->d_csize = dir->hdr->d_csize; + d->st_size = dir->hdr->d_usize; + d->d_name = dir->hdr->d_name; + + if (! dir->hdr->d_reclen) + { + dir->hdr = 0; + } else + { + dir->hdr = (struct zzip_dir_hdr *) + ((char *) dir->hdr + dir->hdr->d_reclen); + } + + return 1; +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */