xref: /netbsd-src/external/gpl3/binutils.old/dist/zlib/contrib/minizip/zip.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* zip.h -- IO on .zip files using zlib
275fd0b74Schristos    Version 1.1, February 14h, 2010
375fd0b74Schristos    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
475fd0b74Schristos 
575fd0b74Schristos          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
675fd0b74Schristos 
775fd0b74Schristos          Modifications for Zip64 support
875fd0b74Schristos          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
975fd0b74Schristos 
1075fd0b74Schristos          For more info read MiniZip_info.txt
1175fd0b74Schristos 
1275fd0b74Schristos          ---------------------------------------------------------------------------
1375fd0b74Schristos 
1475fd0b74Schristos    Condition of use and distribution are the same than zlib :
1575fd0b74Schristos 
1675fd0b74Schristos   This software is provided 'as-is', without any express or implied
1775fd0b74Schristos   warranty.  In no event will the authors be held liable for any damages
1875fd0b74Schristos   arising from the use of this software.
1975fd0b74Schristos 
2075fd0b74Schristos   Permission is granted to anyone to use this software for any purpose,
2175fd0b74Schristos   including commercial applications, and to alter it and redistribute it
2275fd0b74Schristos   freely, subject to the following restrictions:
2375fd0b74Schristos 
2475fd0b74Schristos   1. The origin of this software must not be misrepresented; you must not
2575fd0b74Schristos      claim that you wrote the original software. If you use this software
2675fd0b74Schristos      in a product, an acknowledgment in the product documentation would be
2775fd0b74Schristos      appreciated but is not required.
2875fd0b74Schristos   2. Altered source versions must be plainly marked as such, and must not be
2975fd0b74Schristos      misrepresented as being the original software.
3075fd0b74Schristos   3. This notice may not be removed or altered from any source distribution.
3175fd0b74Schristos 
3275fd0b74Schristos         ---------------------------------------------------------------------------
3375fd0b74Schristos 
3475fd0b74Schristos         Changes
3575fd0b74Schristos 
3675fd0b74Schristos         See header of zip.h
3775fd0b74Schristos 
3875fd0b74Schristos */
3975fd0b74Schristos 
4075fd0b74Schristos #ifndef _zip12_H
4175fd0b74Schristos #define _zip12_H
4275fd0b74Schristos 
4375fd0b74Schristos #ifdef __cplusplus
4475fd0b74Schristos extern "C" {
4575fd0b74Schristos #endif
4675fd0b74Schristos 
4775fd0b74Schristos //#define HAVE_BZIP2
4875fd0b74Schristos 
4975fd0b74Schristos #ifndef _ZLIB_H
5075fd0b74Schristos #include "zlib.h"
5175fd0b74Schristos #endif
5275fd0b74Schristos 
5375fd0b74Schristos #ifndef _ZLIBIOAPI_H
5475fd0b74Schristos #include "ioapi.h"
5575fd0b74Schristos #endif
5675fd0b74Schristos 
5775fd0b74Schristos #ifdef HAVE_BZIP2
5875fd0b74Schristos #include "bzlib.h"
5975fd0b74Schristos #endif
6075fd0b74Schristos 
6175fd0b74Schristos #define Z_BZIP2ED 12
6275fd0b74Schristos 
6375fd0b74Schristos #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
6475fd0b74Schristos /* like the STRICT of WIN32, we define a pointer that cannot be converted
6575fd0b74Schristos     from (void*) without cast */
6675fd0b74Schristos typedef struct TagzipFile__ { int unused; } zipFile__;
6775fd0b74Schristos typedef zipFile__ *zipFile;
6875fd0b74Schristos #else
6975fd0b74Schristos typedef voidp zipFile;
7075fd0b74Schristos #endif
7175fd0b74Schristos 
7275fd0b74Schristos #define ZIP_OK                          (0)
7375fd0b74Schristos #define ZIP_EOF                         (0)
7475fd0b74Schristos #define ZIP_ERRNO                       (Z_ERRNO)
7575fd0b74Schristos #define ZIP_PARAMERROR                  (-102)
7675fd0b74Schristos #define ZIP_BADZIPFILE                  (-103)
7775fd0b74Schristos #define ZIP_INTERNALERROR               (-104)
7875fd0b74Schristos 
7975fd0b74Schristos #ifndef DEF_MEM_LEVEL
8075fd0b74Schristos #  if MAX_MEM_LEVEL >= 8
8175fd0b74Schristos #    define DEF_MEM_LEVEL 8
8275fd0b74Schristos #  else
8375fd0b74Schristos #    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
8475fd0b74Schristos #  endif
8575fd0b74Schristos #endif
8675fd0b74Schristos /* default memLevel */
8775fd0b74Schristos 
8875fd0b74Schristos /* tm_zip contain date/time info */
8975fd0b74Schristos typedef struct tm_zip_s
9075fd0b74Schristos {
91*e992f068Schristos     int tm_sec;             /* seconds after the minute - [0,59] */
92*e992f068Schristos     int tm_min;             /* minutes after the hour - [0,59] */
93*e992f068Schristos     int tm_hour;            /* hours since midnight - [0,23] */
94*e992f068Schristos     int tm_mday;            /* day of the month - [1,31] */
95*e992f068Schristos     int tm_mon;             /* months since January - [0,11] */
96*e992f068Schristos     int tm_year;            /* years - [1980..2044] */
9775fd0b74Schristos } tm_zip;
9875fd0b74Schristos 
9975fd0b74Schristos typedef struct
10075fd0b74Schristos {
10175fd0b74Schristos     tm_zip      tmz_date;       /* date in understandable format           */
10275fd0b74Schristos     uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
10375fd0b74Schristos /*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
10475fd0b74Schristos 
10575fd0b74Schristos     uLong       internal_fa;    /* internal file attributes        2 bytes */
10675fd0b74Schristos     uLong       external_fa;    /* external file attributes        4 bytes */
10775fd0b74Schristos } zip_fileinfo;
10875fd0b74Schristos 
10975fd0b74Schristos typedef const char* zipcharpc;
11075fd0b74Schristos 
11175fd0b74Schristos 
11275fd0b74Schristos #define APPEND_STATUS_CREATE        (0)
11375fd0b74Schristos #define APPEND_STATUS_CREATEAFTER   (1)
11475fd0b74Schristos #define APPEND_STATUS_ADDINZIP      (2)
11575fd0b74Schristos 
11675fd0b74Schristos extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
11775fd0b74Schristos extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
11875fd0b74Schristos /*
11975fd0b74Schristos   Create a zipfile.
12075fd0b74Schristos      pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
12175fd0b74Schristos        an Unix computer "zlib/zlib113.zip".
12275fd0b74Schristos      if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
12375fd0b74Schristos        will be created at the end of the file.
12475fd0b74Schristos          (useful if the file contain a self extractor code)
12575fd0b74Schristos      if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
12675fd0b74Schristos        add files in existing zip (be sure you don't add file that doesn't exist)
12775fd0b74Schristos      If the zipfile cannot be opened, the return value is NULL.
12875fd0b74Schristos      Else, the return value is a zipFile Handle, usable with other function
12975fd0b74Schristos        of this zip package.
13075fd0b74Schristos */
13175fd0b74Schristos 
13275fd0b74Schristos /* Note : there is no delete function into a zipfile.
13375fd0b74Schristos    If you want delete file into a zipfile, you must open a zipfile, and create another
13475fd0b74Schristos    Of couse, you can use RAW reading and writing to copy the file you did not want delte
13575fd0b74Schristos */
13675fd0b74Schristos 
13775fd0b74Schristos extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
13875fd0b74Schristos                                    int append,
13975fd0b74Schristos                                    zipcharpc* globalcomment,
14075fd0b74Schristos                                    zlib_filefunc_def* pzlib_filefunc_def));
14175fd0b74Schristos 
14275fd0b74Schristos extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
14375fd0b74Schristos                                    int append,
14475fd0b74Schristos                                    zipcharpc* globalcomment,
14575fd0b74Schristos                                    zlib_filefunc64_def* pzlib_filefunc_def));
14675fd0b74Schristos 
147*e992f068Schristos extern zipFile ZEXPORT zipOpen3 OF((const void *pathname,
148*e992f068Schristos                                     int append,
149*e992f068Schristos                                     zipcharpc* globalcomment,
150*e992f068Schristos                                     zlib_filefunc64_32_def* pzlib_filefunc64_32_def));
151*e992f068Schristos 
15275fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
15375fd0b74Schristos                        const char* filename,
15475fd0b74Schristos                        const zip_fileinfo* zipfi,
15575fd0b74Schristos                        const void* extrafield_local,
15675fd0b74Schristos                        uInt size_extrafield_local,
15775fd0b74Schristos                        const void* extrafield_global,
15875fd0b74Schristos                        uInt size_extrafield_global,
15975fd0b74Schristos                        const char* comment,
16075fd0b74Schristos                        int method,
16175fd0b74Schristos                        int level));
16275fd0b74Schristos 
16375fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
16475fd0b74Schristos                        const char* filename,
16575fd0b74Schristos                        const zip_fileinfo* zipfi,
16675fd0b74Schristos                        const void* extrafield_local,
16775fd0b74Schristos                        uInt size_extrafield_local,
16875fd0b74Schristos                        const void* extrafield_global,
16975fd0b74Schristos                        uInt size_extrafield_global,
17075fd0b74Schristos                        const char* comment,
17175fd0b74Schristos                        int method,
17275fd0b74Schristos                        int level,
17375fd0b74Schristos                        int zip64));
17475fd0b74Schristos 
17575fd0b74Schristos /*
17675fd0b74Schristos   Open a file in the ZIP for writing.
17775fd0b74Schristos   filename : the filename in zip (if NULL, '-' without quote will be used
17875fd0b74Schristos   *zipfi contain supplemental information
17975fd0b74Schristos   if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
18075fd0b74Schristos     contains the extrafield data the the local header
18175fd0b74Schristos   if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
18275fd0b74Schristos     contains the extrafield data the the local header
18375fd0b74Schristos   if comment != NULL, comment contain the comment string
18475fd0b74Schristos   method contain the compression method (0 for store, Z_DEFLATED for deflate)
18575fd0b74Schristos   level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
18675fd0b74Schristos   zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
18775fd0b74Schristos                     this MUST be '1' if the uncompressed size is >= 0xffffffff.
18875fd0b74Schristos 
18975fd0b74Schristos */
19075fd0b74Schristos 
19175fd0b74Schristos 
19275fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
19375fd0b74Schristos                                             const char* filename,
19475fd0b74Schristos                                             const zip_fileinfo* zipfi,
19575fd0b74Schristos                                             const void* extrafield_local,
19675fd0b74Schristos                                             uInt size_extrafield_local,
19775fd0b74Schristos                                             const void* extrafield_global,
19875fd0b74Schristos                                             uInt size_extrafield_global,
19975fd0b74Schristos                                             const char* comment,
20075fd0b74Schristos                                             int method,
20175fd0b74Schristos                                             int level,
20275fd0b74Schristos                                             int raw));
20375fd0b74Schristos 
20475fd0b74Schristos 
20575fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
20675fd0b74Schristos                                             const char* filename,
20775fd0b74Schristos                                             const zip_fileinfo* zipfi,
20875fd0b74Schristos                                             const void* extrafield_local,
20975fd0b74Schristos                                             uInt size_extrafield_local,
21075fd0b74Schristos                                             const void* extrafield_global,
21175fd0b74Schristos                                             uInt size_extrafield_global,
21275fd0b74Schristos                                             const char* comment,
21375fd0b74Schristos                                             int method,
21475fd0b74Schristos                                             int level,
21575fd0b74Schristos                                             int raw,
21675fd0b74Schristos                                             int zip64));
21775fd0b74Schristos /*
21875fd0b74Schristos   Same than zipOpenNewFileInZip, except if raw=1, we write raw file
21975fd0b74Schristos  */
22075fd0b74Schristos 
22175fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
22275fd0b74Schristos                                             const char* filename,
22375fd0b74Schristos                                             const zip_fileinfo* zipfi,
22475fd0b74Schristos                                             const void* extrafield_local,
22575fd0b74Schristos                                             uInt size_extrafield_local,
22675fd0b74Schristos                                             const void* extrafield_global,
22775fd0b74Schristos                                             uInt size_extrafield_global,
22875fd0b74Schristos                                             const char* comment,
22975fd0b74Schristos                                             int method,
23075fd0b74Schristos                                             int level,
23175fd0b74Schristos                                             int raw,
23275fd0b74Schristos                                             int windowBits,
23375fd0b74Schristos                                             int memLevel,
23475fd0b74Schristos                                             int strategy,
23575fd0b74Schristos                                             const char* password,
23675fd0b74Schristos                                             uLong crcForCrypting));
23775fd0b74Schristos 
23875fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
23975fd0b74Schristos                                             const char* filename,
24075fd0b74Schristos                                             const zip_fileinfo* zipfi,
24175fd0b74Schristos                                             const void* extrafield_local,
24275fd0b74Schristos                                             uInt size_extrafield_local,
24375fd0b74Schristos                                             const void* extrafield_global,
24475fd0b74Schristos                                             uInt size_extrafield_global,
24575fd0b74Schristos                                             const char* comment,
24675fd0b74Schristos                                             int method,
24775fd0b74Schristos                                             int level,
24875fd0b74Schristos                                             int raw,
24975fd0b74Schristos                                             int windowBits,
25075fd0b74Schristos                                             int memLevel,
25175fd0b74Schristos                                             int strategy,
25275fd0b74Schristos                                             const char* password,
25375fd0b74Schristos                                             uLong crcForCrypting,
25475fd0b74Schristos                                             int zip64
25575fd0b74Schristos                                             ));
25675fd0b74Schristos 
25775fd0b74Schristos /*
25875fd0b74Schristos   Same than zipOpenNewFileInZip2, except
25975fd0b74Schristos     windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
26075fd0b74Schristos     password : crypting password (NULL for no crypting)
26175fd0b74Schristos     crcForCrypting : crc of file to compress (needed for crypting)
26275fd0b74Schristos  */
26375fd0b74Schristos 
26475fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
26575fd0b74Schristos                                             const char* filename,
26675fd0b74Schristos                                             const zip_fileinfo* zipfi,
26775fd0b74Schristos                                             const void* extrafield_local,
26875fd0b74Schristos                                             uInt size_extrafield_local,
26975fd0b74Schristos                                             const void* extrafield_global,
27075fd0b74Schristos                                             uInt size_extrafield_global,
27175fd0b74Schristos                                             const char* comment,
27275fd0b74Schristos                                             int method,
27375fd0b74Schristos                                             int level,
27475fd0b74Schristos                                             int raw,
27575fd0b74Schristos                                             int windowBits,
27675fd0b74Schristos                                             int memLevel,
27775fd0b74Schristos                                             int strategy,
27875fd0b74Schristos                                             const char* password,
27975fd0b74Schristos                                             uLong crcForCrypting,
28075fd0b74Schristos                                             uLong versionMadeBy,
28175fd0b74Schristos                                             uLong flagBase
28275fd0b74Schristos                                             ));
28375fd0b74Schristos 
28475fd0b74Schristos 
28575fd0b74Schristos extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
28675fd0b74Schristos                                             const char* filename,
28775fd0b74Schristos                                             const zip_fileinfo* zipfi,
28875fd0b74Schristos                                             const void* extrafield_local,
28975fd0b74Schristos                                             uInt size_extrafield_local,
29075fd0b74Schristos                                             const void* extrafield_global,
29175fd0b74Schristos                                             uInt size_extrafield_global,
29275fd0b74Schristos                                             const char* comment,
29375fd0b74Schristos                                             int method,
29475fd0b74Schristos                                             int level,
29575fd0b74Schristos                                             int raw,
29675fd0b74Schristos                                             int windowBits,
29775fd0b74Schristos                                             int memLevel,
29875fd0b74Schristos                                             int strategy,
29975fd0b74Schristos                                             const char* password,
30075fd0b74Schristos                                             uLong crcForCrypting,
30175fd0b74Schristos                                             uLong versionMadeBy,
30275fd0b74Schristos                                             uLong flagBase,
30375fd0b74Schristos                                             int zip64
30475fd0b74Schristos                                             ));
30575fd0b74Schristos /*
30675fd0b74Schristos   Same than zipOpenNewFileInZip4, except
30775fd0b74Schristos     versionMadeBy : value for Version made by field
30875fd0b74Schristos     flag : value for flag field (compression level info will be added)
30975fd0b74Schristos  */
31075fd0b74Schristos 
31175fd0b74Schristos 
31275fd0b74Schristos extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
31375fd0b74Schristos                        const void* buf,
31475fd0b74Schristos                        unsigned len));
31575fd0b74Schristos /*
31675fd0b74Schristos   Write data in the zipfile
31775fd0b74Schristos */
31875fd0b74Schristos 
31975fd0b74Schristos extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
32075fd0b74Schristos /*
32175fd0b74Schristos   Close the current file in the zipfile
32275fd0b74Schristos */
32375fd0b74Schristos 
32475fd0b74Schristos extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
32575fd0b74Schristos                                             uLong uncompressed_size,
32675fd0b74Schristos                                             uLong crc32));
32775fd0b74Schristos 
32875fd0b74Schristos extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
32975fd0b74Schristos                                             ZPOS64_T uncompressed_size,
33075fd0b74Schristos                                             uLong crc32));
33175fd0b74Schristos 
33275fd0b74Schristos /*
33375fd0b74Schristos   Close the current file in the zipfile, for file opened with
33475fd0b74Schristos     parameter raw=1 in zipOpenNewFileInZip2
33575fd0b74Schristos   uncompressed_size and crc32 are value for the uncompressed size
33675fd0b74Schristos */
33775fd0b74Schristos 
33875fd0b74Schristos extern int ZEXPORT zipClose OF((zipFile file,
33975fd0b74Schristos                 const char* global_comment));
34075fd0b74Schristos /*
34175fd0b74Schristos   Close the zipfile
34275fd0b74Schristos */
34375fd0b74Schristos 
34475fd0b74Schristos 
34575fd0b74Schristos extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
34675fd0b74Schristos /*
34775fd0b74Schristos   zipRemoveExtraInfoBlock -  Added by Mathias Svensson
34875fd0b74Schristos 
34975fd0b74Schristos   Remove extra information block from a extra information data for the local file header or central directory header
35075fd0b74Schristos 
35175fd0b74Schristos   It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
35275fd0b74Schristos 
35375fd0b74Schristos   0x0001 is the signature header for the ZIP64 extra information blocks
35475fd0b74Schristos 
35575fd0b74Schristos   usage.
35675fd0b74Schristos                         Remove ZIP64 Extra information from a central director extra field data
35775fd0b74Schristos               zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
35875fd0b74Schristos 
35975fd0b74Schristos                         Remove ZIP64 Extra information from a Local File Header extra field data
36075fd0b74Schristos         zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
36175fd0b74Schristos */
36275fd0b74Schristos 
36375fd0b74Schristos #ifdef __cplusplus
36475fd0b74Schristos }
36575fd0b74Schristos #endif
36675fd0b74Schristos 
36775fd0b74Schristos #endif /* _zip64_H */
368