DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/zip.h
00001 /* zip.h -- IO on .zip files using zlib
00002    Version 1.1, February 14h, 2010
00003    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
00004 
00005          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
00006 
00007          Modifications for Zip64 support
00008          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
00009 
00010          For more info read MiniZip_info.txt
00011 
00012          ---------------------------------------------------------------------------
00013 
00014    Condition of use and distribution are the same than zlib :
00015 
00016   This software is provided 'as-is', without any express or implied
00017   warranty.  In no event will the authors be held liable for any damages
00018   arising from the use of this software.
00019 
00020   Permission is granted to anyone to use this software for any purpose,
00021   including commercial applications, and to alter it and redistribute it
00022   freely, subject to the following restrictions:
00023 
00024   1. The origin of this software must not be misrepresented; you must not
00025      claim that you wrote the original software. If you use this software
00026      in a product, an acknowledgment in the product documentation would be
00027      appreciated but is not required.
00028   2. Altered source versions must be plainly marked as such, and must not be
00029      misrepresented as being the original software.
00030   3. This notice may not be removed or altered from any source distribution.
00031 
00032         ---------------------------------------------------------------------------
00033 
00034         Changes
00035 
00036         See header of zip.h
00037 
00038 */
00039 
00040 #ifndef _zip12_H
00041 #define _zip12_H
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 //#define HAVE_BZIP2
00048 
00049 #ifndef _ZLIB_H
00050 #include "zlib.h"
00051 #endif
00052 
00053 #ifndef _ZLIBIOAPI_H
00054 #include "ioapi.h"
00055 #endif
00056 
00057 #ifdef HAVE_BZIP2
00058 #include "bzlib.h"
00059 #endif
00060 
00061 #define Z_BZIP2ED 12
00062 
00063 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
00064 /* like the STRICT of WIN32, we define a pointer that cannot be converted
00065     from (void*) without cast */
00066 typedef struct TagzipFile__ { int unused; } zipFile__;
00067 typedef zipFile__ *zipFile;
00068 #else
00069 typedef voidp zipFile;
00070 #endif
00071 
00072 #define ZIP_OK                          (0)
00073 #define ZIP_EOF                         (0)
00074 #define ZIP_ERRNO                       (Z_ERRNO)
00075 #define ZIP_PARAMERROR                  (-102)
00076 #define ZIP_BADZIPFILE                  (-103)
00077 #define ZIP_INTERNALERROR               (-104)
00078 
00079 #ifndef DEF_MEM_LEVEL
00080 #  if MAX_MEM_LEVEL >= 8
00081 #    define DEF_MEM_LEVEL 8
00082 #  else
00083 #    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
00084 #  endif
00085 #endif
00086 /* default memLevel */
00087 
00088 /* tm_zip contain date/time info */
00089 typedef struct tm_zip_s
00090 {
00091     uInt tm_sec;            /* seconds after the minute - [0,59] */
00092     uInt tm_min;            /* minutes after the hour - [0,59] */
00093     uInt tm_hour;           /* hours since midnight - [0,23] */
00094     uInt tm_mday;           /* day of the month - [1,31] */
00095     uInt tm_mon;            /* months since January - [0,11] */
00096     uInt tm_year;           /* years - [1980..2044] */
00097 } tm_zip;
00098 
00099 typedef struct
00100 {
00101     tm_zip      tmz_date;       /* date in understandable format           */
00102     uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
00103 /*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
00104 
00105     uLong       internal_fa;    /* internal file attributes        2 bytes */
00106     uLong       external_fa;    /* external file attributes        4 bytes */
00107 } zip_fileinfo;
00108 
00109 typedef const char* zipcharpc;
00110 
00111 
00112 #define APPEND_STATUS_CREATE        (0)
00113 #define APPEND_STATUS_CREATEAFTER   (1)
00114 #define APPEND_STATUS_ADDINZIP      (2)
00115 
00116 extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
00117 extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
00118 /*
00119   Create a zipfile.
00120      pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
00121        an Unix computer "zlib/zlib113.zip".
00122      if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
00123        will be created at the end of the file.
00124          (useful if the file contain a self extractor code)
00125      if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
00126        add files in existing zip (be sure you don't add file that doesn't exist)
00127      If the zipfile cannot be opened, the return value is NULL.
00128      Else, the return value is a zipFile Handle, usable with other function
00129        of this zip package.
00130 */
00131 
00132 /* Note : there is no delete function into a zipfile.
00133    If you want delete file into a zipfile, you must open a zipfile, and create another
00134    Of couse, you can use RAW reading and writing to copy the file you did not want delte
00135 */
00136 
00137 extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
00138                                    int append,
00139                                    zipcharpc* globalcomment,
00140                                    zlib_filefunc_def* pzlib_filefunc_def));
00141 
00142 extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
00143                                    int append,
00144                                    zipcharpc* globalcomment,
00145                                    zlib_filefunc64_def* pzlib_filefunc_def));
00146 
00147 extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
00148                        const char* filename,
00149                        const zip_fileinfo* zipfi,
00150                        const void* extrafield_local,
00151                        uInt size_extrafield_local,
00152                        const void* extrafield_global,
00153                        uInt size_extrafield_global,
00154                        const char* comment,
00155                        int method,
00156                        int level));
00157 
00158 extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
00159                        const char* filename,
00160                        const zip_fileinfo* zipfi,
00161                        const void* extrafield_local,
00162                        uInt size_extrafield_local,
00163                        const void* extrafield_global,
00164                        uInt size_extrafield_global,
00165                        const char* comment,
00166                        int method,
00167                        int level,
00168                        int zip64));
00169 
00170 /*
00171   Open a file in the ZIP for writing.
00172   filename : the filename in zip (if NULL, '-' without quote will be used
00173   *zipfi contain supplemental information
00174   if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
00175     contains the extrafield data the the local header
00176   if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
00177     contains the extrafield data the the local header
00178   if comment != NULL, comment contain the comment string
00179   method contain the compression method (0 for store, Z_DEFLATED for deflate)
00180   level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
00181   zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
00182                     this MUST be '1' if the uncompressed size is >= 0xffffffff.
00183 
00184 */
00185 
00186 
00187 extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
00188                                             const char* filename,
00189                                             const zip_fileinfo* zipfi,
00190                                             const void* extrafield_local,
00191                                             uInt size_extrafield_local,
00192                                             const void* extrafield_global,
00193                                             uInt size_extrafield_global,
00194                                             const char* comment,
00195                                             int method,
00196                                             int level,
00197                                             int raw));
00198 
00199 
00200 extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
00201                                             const char* filename,
00202                                             const zip_fileinfo* zipfi,
00203                                             const void* extrafield_local,
00204                                             uInt size_extrafield_local,
00205                                             const void* extrafield_global,
00206                                             uInt size_extrafield_global,
00207                                             const char* comment,
00208                                             int method,
00209                                             int level,
00210                                             int raw,
00211                                             int zip64));
00212 /*
00213   Same than zipOpenNewFileInZip, except if raw=1, we write raw file
00214  */
00215 
00216 extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
00217                                             const char* filename,
00218                                             const zip_fileinfo* zipfi,
00219                                             const void* extrafield_local,
00220                                             uInt size_extrafield_local,
00221                                             const void* extrafield_global,
00222                                             uInt size_extrafield_global,
00223                                             const char* comment,
00224                                             int method,
00225                                             int level,
00226                                             int raw,
00227                                             int windowBits,
00228                                             int memLevel,
00229                                             int strategy,
00230                                             const char* password,
00231                                             uLong crcForCrypting));
00232 
00233 extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
00234                                             const char* filename,
00235                                             const zip_fileinfo* zipfi,
00236                                             const void* extrafield_local,
00237                                             uInt size_extrafield_local,
00238                                             const void* extrafield_global,
00239                                             uInt size_extrafield_global,
00240                                             const char* comment,
00241                                             int method,
00242                                             int level,
00243                                             int raw,
00244                                             int windowBits,
00245                                             int memLevel,
00246                                             int strategy,
00247                                             const char* password,
00248                                             uLong crcForCrypting,
00249                                             int zip64
00250                                             ));
00251 
00252 /*
00253   Same than zipOpenNewFileInZip2, except
00254     windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
00255     password : crypting password (NULL for no crypting)
00256     crcForCrypting : crc of file to compress (needed for crypting)
00257  */
00258 
00259 extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
00260                                             const char* filename,
00261                                             const zip_fileinfo* zipfi,
00262                                             const void* extrafield_local,
00263                                             uInt size_extrafield_local,
00264                                             const void* extrafield_global,
00265                                             uInt size_extrafield_global,
00266                                             const char* comment,
00267                                             int method,
00268                                             int level,
00269                                             int raw,
00270                                             int windowBits,
00271                                             int memLevel,
00272                                             int strategy,
00273                                             const char* password,
00274                                             uLong crcForCrypting,
00275                                             uLong versionMadeBy,
00276                                             uLong flagBase
00277                                             ));
00278 
00279 
00280 extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
00281                                             const char* filename,
00282                                             const zip_fileinfo* zipfi,
00283                                             const void* extrafield_local,
00284                                             uInt size_extrafield_local,
00285                                             const void* extrafield_global,
00286                                             uInt size_extrafield_global,
00287                                             const char* comment,
00288                                             int method,
00289                                             int level,
00290                                             int raw,
00291                                             int windowBits,
00292                                             int memLevel,
00293                                             int strategy,
00294                                             const char* password,
00295                                             uLong crcForCrypting,
00296                                             uLong versionMadeBy,
00297                                             uLong flagBase,
00298                                             int zip64
00299                                             ));
00300 /*
00301   Same than zipOpenNewFileInZip4, except
00302     versionMadeBy : value for Version made by field
00303     flag : value for flag field (compression level info will be added)
00304  */
00305 
00306 
00307 extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
00308                        const void* buf,
00309                        unsigned len));
00310 /*
00311   Write data in the zipfile
00312 */
00313 
00314 extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
00315 /*
00316   Close the current file in the zipfile
00317 */
00318 
00319 extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
00320                                             uLong uncompressed_size,
00321                                             uLong crc32));
00322 
00323 extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
00324                                             ZPOS64_T uncompressed_size,
00325                                             uLong crc32));
00326 
00327 /*
00328   Close the current file in the zipfile, for file opened with
00329     parameter raw=1 in zipOpenNewFileInZip2
00330   uncompressed_size and crc32 are value for the uncompressed size
00331 */
00332 
00333 extern int ZEXPORT zipClose OF((zipFile file,
00334                 const char* global_comment));
00335 /*
00336   Close the zipfile
00337 */
00338 
00339 
00340 extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
00341 /*
00342   zipRemoveExtraInfoBlock -  Added by Mathias Svensson
00343 
00344   Remove extra information block from a extra information data for the local file header or central directory header
00345 
00346   It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
00347 
00348   0x0001 is the signature header for the ZIP64 extra information blocks
00349 
00350   usage.
00351                         Remove ZIP64 Extra information from a central director extra field data
00352               zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
00353 
00354                         Remove ZIP64 Extra information from a Local File Header extra field data
00355         zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
00356 */
00357 
00358 #ifdef __cplusplus
00359 }
00360 #endif
00361 
00362 #endif /* _zip64_H */