xref: /netbsd-src/external/gpl3/binutils/dist/zlib/contrib/minizip/zip.h (revision 4f645668ed707e1f969c546666f8c8e45e6f8888)
19573673dSchristos /* zip.h -- IO on .zip files using zlib
29573673dSchristos    Version 1.1, February 14h, 2010
39573673dSchristos    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
49573673dSchristos 
59573673dSchristos          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
69573673dSchristos 
79573673dSchristos          Modifications for Zip64 support
89573673dSchristos          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
99573673dSchristos 
109573673dSchristos          For more info read MiniZip_info.txt
119573673dSchristos 
129573673dSchristos          ---------------------------------------------------------------------------
139573673dSchristos 
149573673dSchristos    Condition of use and distribution are the same than zlib :
159573673dSchristos 
169573673dSchristos   This software is provided 'as-is', without any express or implied
179573673dSchristos   warranty.  In no event will the authors be held liable for any damages
189573673dSchristos   arising from the use of this software.
199573673dSchristos 
209573673dSchristos   Permission is granted to anyone to use this software for any purpose,
219573673dSchristos   including commercial applications, and to alter it and redistribute it
229573673dSchristos   freely, subject to the following restrictions:
239573673dSchristos 
249573673dSchristos   1. The origin of this software must not be misrepresented; you must not
259573673dSchristos      claim that you wrote the original software. If you use this software
269573673dSchristos      in a product, an acknowledgment in the product documentation would be
279573673dSchristos      appreciated but is not required.
289573673dSchristos   2. Altered source versions must be plainly marked as such, and must not be
299573673dSchristos      misrepresented as being the original software.
309573673dSchristos   3. This notice may not be removed or altered from any source distribution.
319573673dSchristos 
329573673dSchristos         ---------------------------------------------------------------------------
339573673dSchristos 
349573673dSchristos         Changes
359573673dSchristos 
369573673dSchristos         See header of zip.h
379573673dSchristos 
389573673dSchristos */
399573673dSchristos 
409573673dSchristos #ifndef _zip12_H
419573673dSchristos #define _zip12_H
429573673dSchristos 
439573673dSchristos #ifdef __cplusplus
449573673dSchristos extern "C" {
459573673dSchristos #endif
469573673dSchristos 
479573673dSchristos //#define HAVE_BZIP2
489573673dSchristos 
499573673dSchristos #ifndef _ZLIB_H
509573673dSchristos #include "zlib.h"
519573673dSchristos #endif
529573673dSchristos 
539573673dSchristos #ifndef _ZLIBIOAPI_H
549573673dSchristos #include "ioapi.h"
559573673dSchristos #endif
569573673dSchristos 
579573673dSchristos #ifdef HAVE_BZIP2
589573673dSchristos #include "bzlib.h"
599573673dSchristos #endif
609573673dSchristos 
619573673dSchristos #define Z_BZIP2ED 12
629573673dSchristos 
639573673dSchristos #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
649573673dSchristos /* like the STRICT of WIN32, we define a pointer that cannot be converted
659573673dSchristos     from (void*) without cast */
669573673dSchristos typedef struct TagzipFile__ { int unused; } zipFile__;
679573673dSchristos typedef zipFile__ *zipFile;
689573673dSchristos #else
699573673dSchristos typedef voidp zipFile;
709573673dSchristos #endif
719573673dSchristos 
729573673dSchristos #define ZIP_OK                          (0)
739573673dSchristos #define ZIP_EOF                         (0)
749573673dSchristos #define ZIP_ERRNO                       (Z_ERRNO)
759573673dSchristos #define ZIP_PARAMERROR                  (-102)
769573673dSchristos #define ZIP_BADZIPFILE                  (-103)
779573673dSchristos #define ZIP_INTERNALERROR               (-104)
789573673dSchristos 
799573673dSchristos #ifndef DEF_MEM_LEVEL
809573673dSchristos #  if MAX_MEM_LEVEL >= 8
819573673dSchristos #    define DEF_MEM_LEVEL 8
829573673dSchristos #  else
839573673dSchristos #    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
849573673dSchristos #  endif
859573673dSchristos #endif
869573673dSchristos /* default memLevel */
879573673dSchristos 
889573673dSchristos /* tm_zip contain date/time info */
899573673dSchristos typedef struct tm_zip_s
909573673dSchristos {
91*4f645668Schristos     int tm_sec;             /* seconds after the minute - [0,59] */
92*4f645668Schristos     int tm_min;             /* minutes after the hour - [0,59] */
93*4f645668Schristos     int tm_hour;            /* hours since midnight - [0,23] */
94*4f645668Schristos     int tm_mday;            /* day of the month - [1,31] */
95*4f645668Schristos     int tm_mon;             /* months since January - [0,11] */
96*4f645668Schristos     int tm_year;            /* years - [1980..2044] */
979573673dSchristos } tm_zip;
989573673dSchristos 
999573673dSchristos typedef struct
1009573673dSchristos {
1019573673dSchristos     tm_zip      tmz_date;       /* date in understandable format           */
1029573673dSchristos     uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
1039573673dSchristos /*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
1049573673dSchristos 
1059573673dSchristos     uLong       internal_fa;    /* internal file attributes        2 bytes */
1069573673dSchristos     uLong       external_fa;    /* external file attributes        4 bytes */
1079573673dSchristos } zip_fileinfo;
1089573673dSchristos 
1099573673dSchristos typedef const char* zipcharpc;
1109573673dSchristos 
1119573673dSchristos 
1129573673dSchristos #define APPEND_STATUS_CREATE        (0)
1139573673dSchristos #define APPEND_STATUS_CREATEAFTER   (1)
1149573673dSchristos #define APPEND_STATUS_ADDINZIP      (2)
1159573673dSchristos 
1169573673dSchristos extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
1179573673dSchristos extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
1189573673dSchristos /*
1199573673dSchristos   Create a zipfile.
1209573673dSchristos      pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
1219573673dSchristos        an Unix computer "zlib/zlib113.zip".
1229573673dSchristos      if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
1239573673dSchristos        will be created at the end of the file.
1249573673dSchristos          (useful if the file contain a self extractor code)
1259573673dSchristos      if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
1269573673dSchristos        add files in existing zip (be sure you don't add file that doesn't exist)
1279573673dSchristos      If the zipfile cannot be opened, the return value is NULL.
1289573673dSchristos      Else, the return value is a zipFile Handle, usable with other function
1299573673dSchristos        of this zip package.
1309573673dSchristos */
1319573673dSchristos 
1329573673dSchristos /* Note : there is no delete function into a zipfile.
1339573673dSchristos    If you want delete file into a zipfile, you must open a zipfile, and create another
1349573673dSchristos    Of couse, you can use RAW reading and writing to copy the file you did not want delte
1359573673dSchristos */
1369573673dSchristos 
1379573673dSchristos extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
1389573673dSchristos                                    int append,
1399573673dSchristos                                    zipcharpc* globalcomment,
1409573673dSchristos                                    zlib_filefunc_def* pzlib_filefunc_def));
1419573673dSchristos 
1429573673dSchristos extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
1439573673dSchristos                                    int append,
1449573673dSchristos                                    zipcharpc* globalcomment,
1459573673dSchristos                                    zlib_filefunc64_def* pzlib_filefunc_def));
1469573673dSchristos 
147*4f645668Schristos extern zipFile ZEXPORT zipOpen3 OF((const void *pathname,
148*4f645668Schristos                                     int append,
149*4f645668Schristos                                     zipcharpc* globalcomment,
150*4f645668Schristos                                     zlib_filefunc64_32_def* pzlib_filefunc64_32_def));
151*4f645668Schristos 
1529573673dSchristos extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
1539573673dSchristos                        const char* filename,
1549573673dSchristos                        const zip_fileinfo* zipfi,
1559573673dSchristos                        const void* extrafield_local,
1569573673dSchristos                        uInt size_extrafield_local,
1579573673dSchristos                        const void* extrafield_global,
1589573673dSchristos                        uInt size_extrafield_global,
1599573673dSchristos                        const char* comment,
1609573673dSchristos                        int method,
1619573673dSchristos                        int level));
1629573673dSchristos 
1639573673dSchristos extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
1649573673dSchristos                        const char* filename,
1659573673dSchristos                        const zip_fileinfo* zipfi,
1669573673dSchristos                        const void* extrafield_local,
1679573673dSchristos                        uInt size_extrafield_local,
1689573673dSchristos                        const void* extrafield_global,
1699573673dSchristos                        uInt size_extrafield_global,
1709573673dSchristos                        const char* comment,
1719573673dSchristos                        int method,
1729573673dSchristos                        int level,
1739573673dSchristos                        int zip64));
1749573673dSchristos 
1759573673dSchristos /*
1769573673dSchristos   Open a file in the ZIP for writing.
1779573673dSchristos   filename : the filename in zip (if NULL, '-' without quote will be used
1789573673dSchristos   *zipfi contain supplemental information
1799573673dSchristos   if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
1809573673dSchristos     contains the extrafield data the the local header
1819573673dSchristos   if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
1829573673dSchristos     contains the extrafield data the the local header
1839573673dSchristos   if comment != NULL, comment contain the comment string
1849573673dSchristos   method contain the compression method (0 for store, Z_DEFLATED for deflate)
1859573673dSchristos   level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
1869573673dSchristos   zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
1879573673dSchristos                     this MUST be '1' if the uncompressed size is >= 0xffffffff.
1889573673dSchristos 
1899573673dSchristos */
1909573673dSchristos 
1919573673dSchristos 
1929573673dSchristos extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
1939573673dSchristos                                             const char* filename,
1949573673dSchristos                                             const zip_fileinfo* zipfi,
1959573673dSchristos                                             const void* extrafield_local,
1969573673dSchristos                                             uInt size_extrafield_local,
1979573673dSchristos                                             const void* extrafield_global,
1989573673dSchristos                                             uInt size_extrafield_global,
1999573673dSchristos                                             const char* comment,
2009573673dSchristos                                             int method,
2019573673dSchristos                                             int level,
2029573673dSchristos                                             int raw));
2039573673dSchristos 
2049573673dSchristos 
2059573673dSchristos extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
2069573673dSchristos                                             const char* filename,
2079573673dSchristos                                             const zip_fileinfo* zipfi,
2089573673dSchristos                                             const void* extrafield_local,
2099573673dSchristos                                             uInt size_extrafield_local,
2109573673dSchristos                                             const void* extrafield_global,
2119573673dSchristos                                             uInt size_extrafield_global,
2129573673dSchristos                                             const char* comment,
2139573673dSchristos                                             int method,
2149573673dSchristos                                             int level,
2159573673dSchristos                                             int raw,
2169573673dSchristos                                             int zip64));
2179573673dSchristos /*
2189573673dSchristos   Same than zipOpenNewFileInZip, except if raw=1, we write raw file
2199573673dSchristos  */
2209573673dSchristos 
2219573673dSchristos extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
2229573673dSchristos                                             const char* filename,
2239573673dSchristos                                             const zip_fileinfo* zipfi,
2249573673dSchristos                                             const void* extrafield_local,
2259573673dSchristos                                             uInt size_extrafield_local,
2269573673dSchristos                                             const void* extrafield_global,
2279573673dSchristos                                             uInt size_extrafield_global,
2289573673dSchristos                                             const char* comment,
2299573673dSchristos                                             int method,
2309573673dSchristos                                             int level,
2319573673dSchristos                                             int raw,
2329573673dSchristos                                             int windowBits,
2339573673dSchristos                                             int memLevel,
2349573673dSchristos                                             int strategy,
2359573673dSchristos                                             const char* password,
2369573673dSchristos                                             uLong crcForCrypting));
2379573673dSchristos 
2389573673dSchristos extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
2399573673dSchristos                                             const char* filename,
2409573673dSchristos                                             const zip_fileinfo* zipfi,
2419573673dSchristos                                             const void* extrafield_local,
2429573673dSchristos                                             uInt size_extrafield_local,
2439573673dSchristos                                             const void* extrafield_global,
2449573673dSchristos                                             uInt size_extrafield_global,
2459573673dSchristos                                             const char* comment,
2469573673dSchristos                                             int method,
2479573673dSchristos                                             int level,
2489573673dSchristos                                             int raw,
2499573673dSchristos                                             int windowBits,
2509573673dSchristos                                             int memLevel,
2519573673dSchristos                                             int strategy,
2529573673dSchristos                                             const char* password,
2539573673dSchristos                                             uLong crcForCrypting,
2549573673dSchristos                                             int zip64
2559573673dSchristos                                             ));
2569573673dSchristos 
2579573673dSchristos /*
2589573673dSchristos   Same than zipOpenNewFileInZip2, except
2599573673dSchristos     windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
2609573673dSchristos     password : crypting password (NULL for no crypting)
2619573673dSchristos     crcForCrypting : crc of file to compress (needed for crypting)
2629573673dSchristos  */
2639573673dSchristos 
2649573673dSchristos extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
2659573673dSchristos                                             const char* filename,
2669573673dSchristos                                             const zip_fileinfo* zipfi,
2679573673dSchristos                                             const void* extrafield_local,
2689573673dSchristos                                             uInt size_extrafield_local,
2699573673dSchristos                                             const void* extrafield_global,
2709573673dSchristos                                             uInt size_extrafield_global,
2719573673dSchristos                                             const char* comment,
2729573673dSchristos                                             int method,
2739573673dSchristos                                             int level,
2749573673dSchristos                                             int raw,
2759573673dSchristos                                             int windowBits,
2769573673dSchristos                                             int memLevel,
2779573673dSchristos                                             int strategy,
2789573673dSchristos                                             const char* password,
2799573673dSchristos                                             uLong crcForCrypting,
2809573673dSchristos                                             uLong versionMadeBy,
2819573673dSchristos                                             uLong flagBase
2829573673dSchristos                                             ));
2839573673dSchristos 
2849573673dSchristos 
2859573673dSchristos extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
2869573673dSchristos                                             const char* filename,
2879573673dSchristos                                             const zip_fileinfo* zipfi,
2889573673dSchristos                                             const void* extrafield_local,
2899573673dSchristos                                             uInt size_extrafield_local,
2909573673dSchristos                                             const void* extrafield_global,
2919573673dSchristos                                             uInt size_extrafield_global,
2929573673dSchristos                                             const char* comment,
2939573673dSchristos                                             int method,
2949573673dSchristos                                             int level,
2959573673dSchristos                                             int raw,
2969573673dSchristos                                             int windowBits,
2979573673dSchristos                                             int memLevel,
2989573673dSchristos                                             int strategy,
2999573673dSchristos                                             const char* password,
3009573673dSchristos                                             uLong crcForCrypting,
3019573673dSchristos                                             uLong versionMadeBy,
3029573673dSchristos                                             uLong flagBase,
3039573673dSchristos                                             int zip64
3049573673dSchristos                                             ));
3059573673dSchristos /*
3069573673dSchristos   Same than zipOpenNewFileInZip4, except
3079573673dSchristos     versionMadeBy : value for Version made by field
3089573673dSchristos     flag : value for flag field (compression level info will be added)
3099573673dSchristos  */
3109573673dSchristos 
3119573673dSchristos 
3129573673dSchristos extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
3139573673dSchristos                        const void* buf,
3149573673dSchristos                        unsigned len));
3159573673dSchristos /*
3169573673dSchristos   Write data in the zipfile
3179573673dSchristos */
3189573673dSchristos 
3199573673dSchristos extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
3209573673dSchristos /*
3219573673dSchristos   Close the current file in the zipfile
3229573673dSchristos */
3239573673dSchristos 
3249573673dSchristos extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
3259573673dSchristos                                             uLong uncompressed_size,
3269573673dSchristos                                             uLong crc32));
3279573673dSchristos 
3289573673dSchristos extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
3299573673dSchristos                                             ZPOS64_T uncompressed_size,
3309573673dSchristos                                             uLong crc32));
3319573673dSchristos 
3329573673dSchristos /*
3339573673dSchristos   Close the current file in the zipfile, for file opened with
3349573673dSchristos     parameter raw=1 in zipOpenNewFileInZip2
3359573673dSchristos   uncompressed_size and crc32 are value for the uncompressed size
3369573673dSchristos */
3379573673dSchristos 
3389573673dSchristos extern int ZEXPORT zipClose OF((zipFile file,
3399573673dSchristos                 const char* global_comment));
3409573673dSchristos /*
3419573673dSchristos   Close the zipfile
3429573673dSchristos */
3439573673dSchristos 
3449573673dSchristos 
3459573673dSchristos extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
3469573673dSchristos /*
3479573673dSchristos   zipRemoveExtraInfoBlock -  Added by Mathias Svensson
3489573673dSchristos 
3499573673dSchristos   Remove extra information block from a extra information data for the local file header or central directory header
3509573673dSchristos 
3519573673dSchristos   It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
3529573673dSchristos 
3539573673dSchristos   0x0001 is the signature header for the ZIP64 extra information blocks
3549573673dSchristos 
3559573673dSchristos   usage.
3569573673dSchristos                         Remove ZIP64 Extra information from a central director extra field data
3579573673dSchristos               zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
3589573673dSchristos 
3599573673dSchristos                         Remove ZIP64 Extra information from a Local File Header extra field data
3609573673dSchristos         zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
3619573673dSchristos */
3629573673dSchristos 
3639573673dSchristos #ifdef __cplusplus
3649573673dSchristos }
3659573673dSchristos #endif
3669573673dSchristos 
3679573673dSchristos #endif /* _zip64_H */
368