xref: /netbsd-src/external/gpl3/gdb/dist/zlib/contrib/minizip/unzip.h (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1212397c6Schristos /* unzip.h -- IO for uncompress .zip files using zlib
2212397c6Schristos    Version 1.1, February 14h, 2010
3212397c6Schristos    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4212397c6Schristos 
5212397c6Schristos          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6212397c6Schristos 
7212397c6Schristos          Modifications of Unzip for Zip64
8212397c6Schristos          Copyright (C) 2007-2008 Even Rouault
9212397c6Schristos 
10212397c6Schristos          Modifications for Zip64 support on both zip and unzip
11212397c6Schristos          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
12212397c6Schristos 
13212397c6Schristos          For more info read MiniZip_info.txt
14212397c6Schristos 
15212397c6Schristos          ---------------------------------------------------------------------------------
16212397c6Schristos 
17212397c6Schristos         Condition of use and distribution are the same than zlib :
18212397c6Schristos 
19212397c6Schristos   This software is provided 'as-is', without any express or implied
20212397c6Schristos   warranty.  In no event will the authors be held liable for any damages
21212397c6Schristos   arising from the use of this software.
22212397c6Schristos 
23212397c6Schristos   Permission is granted to anyone to use this software for any purpose,
24212397c6Schristos   including commercial applications, and to alter it and redistribute it
25212397c6Schristos   freely, subject to the following restrictions:
26212397c6Schristos 
27212397c6Schristos   1. The origin of this software must not be misrepresented; you must not
28212397c6Schristos      claim that you wrote the original software. If you use this software
29212397c6Schristos      in a product, an acknowledgment in the product documentation would be
30212397c6Schristos      appreciated but is not required.
31212397c6Schristos   2. Altered source versions must be plainly marked as such, and must not be
32212397c6Schristos      misrepresented as being the original software.
33212397c6Schristos   3. This notice may not be removed or altered from any source distribution.
34212397c6Schristos 
35212397c6Schristos   ---------------------------------------------------------------------------------
36212397c6Schristos 
37212397c6Schristos         Changes
38212397c6Schristos 
39212397c6Schristos         See header of unzip64.c
40212397c6Schristos 
41212397c6Schristos */
42212397c6Schristos 
43212397c6Schristos #ifndef _unz64_H
44212397c6Schristos #define _unz64_H
45212397c6Schristos 
46212397c6Schristos #ifdef __cplusplus
47212397c6Schristos extern "C" {
48212397c6Schristos #endif
49212397c6Schristos 
50212397c6Schristos #ifndef _ZLIB_H
51212397c6Schristos #include "zlib.h"
52212397c6Schristos #endif
53212397c6Schristos 
54212397c6Schristos #ifndef  _ZLIBIOAPI_H
55212397c6Schristos #include "ioapi.h"
56212397c6Schristos #endif
57212397c6Schristos 
58212397c6Schristos #ifdef HAVE_BZIP2
59212397c6Schristos #include "bzlib.h"
60212397c6Schristos #endif
61212397c6Schristos 
62212397c6Schristos #define Z_BZIP2ED 12
63212397c6Schristos 
64212397c6Schristos #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
65212397c6Schristos /* like the STRICT of WIN32, we define a pointer that cannot be converted
66212397c6Schristos     from (void*) without cast */
67212397c6Schristos typedef struct TagunzFile__ { int unused; } unzFile__;
68212397c6Schristos typedef unzFile__ *unzFile;
69212397c6Schristos #else
70212397c6Schristos typedef voidp unzFile;
71212397c6Schristos #endif
72212397c6Schristos 
73212397c6Schristos 
74212397c6Schristos #define UNZ_OK                          (0)
75212397c6Schristos #define UNZ_END_OF_LIST_OF_FILE         (-100)
76212397c6Schristos #define UNZ_ERRNO                       (Z_ERRNO)
77212397c6Schristos #define UNZ_EOF                         (0)
78212397c6Schristos #define UNZ_PARAMERROR                  (-102)
79212397c6Schristos #define UNZ_BADZIPFILE                  (-103)
80212397c6Schristos #define UNZ_INTERNALERROR               (-104)
81212397c6Schristos #define UNZ_CRCERROR                    (-105)
82212397c6Schristos 
83212397c6Schristos /* tm_unz contain date/time info */
84212397c6Schristos typedef struct tm_unz_s
85212397c6Schristos {
86*4b169a6bSchristos     int tm_sec;             /* seconds after the minute - [0,59] */
87*4b169a6bSchristos     int tm_min;             /* minutes after the hour - [0,59] */
88*4b169a6bSchristos     int tm_hour;            /* hours since midnight - [0,23] */
89*4b169a6bSchristos     int tm_mday;            /* day of the month - [1,31] */
90*4b169a6bSchristos     int tm_mon;             /* months since January - [0,11] */
91*4b169a6bSchristos     int tm_year;            /* years - [1980..2044] */
92212397c6Schristos } tm_unz;
93212397c6Schristos 
94212397c6Schristos /* unz_global_info structure contain global data about the ZIPfile
95212397c6Schristos    These data comes from the end of central dir */
96212397c6Schristos typedef struct unz_global_info64_s
97212397c6Schristos {
98212397c6Schristos     ZPOS64_T number_entry;         /* total number of entries in
99212397c6Schristos                                      the central dir on this disk */
100212397c6Schristos     uLong size_comment;         /* size of the global comment of the zipfile */
101212397c6Schristos } unz_global_info64;
102212397c6Schristos 
103212397c6Schristos typedef struct unz_global_info_s
104212397c6Schristos {
105212397c6Schristos     uLong number_entry;         /* total number of entries in
106212397c6Schristos                                      the central dir on this disk */
107212397c6Schristos     uLong size_comment;         /* size of the global comment of the zipfile */
108212397c6Schristos } unz_global_info;
109212397c6Schristos 
110212397c6Schristos /* unz_file_info contain information about a file in the zipfile */
111212397c6Schristos typedef struct unz_file_info64_s
112212397c6Schristos {
113212397c6Schristos     uLong version;              /* version made by                 2 bytes */
114212397c6Schristos     uLong version_needed;       /* version needed to extract       2 bytes */
115212397c6Schristos     uLong flag;                 /* general purpose bit flag        2 bytes */
116212397c6Schristos     uLong compression_method;   /* compression method              2 bytes */
117212397c6Schristos     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
118212397c6Schristos     uLong crc;                  /* crc-32                          4 bytes */
119212397c6Schristos     ZPOS64_T compressed_size;   /* compressed size                 8 bytes */
120212397c6Schristos     ZPOS64_T uncompressed_size; /* uncompressed size               8 bytes */
121212397c6Schristos     uLong size_filename;        /* filename length                 2 bytes */
122212397c6Schristos     uLong size_file_extra;      /* extra field length              2 bytes */
123212397c6Schristos     uLong size_file_comment;    /* file comment length             2 bytes */
124212397c6Schristos 
125212397c6Schristos     uLong disk_num_start;       /* disk number start               2 bytes */
126212397c6Schristos     uLong internal_fa;          /* internal file attributes        2 bytes */
127212397c6Schristos     uLong external_fa;          /* external file attributes        4 bytes */
128212397c6Schristos 
129212397c6Schristos     tm_unz tmu_date;
130212397c6Schristos } unz_file_info64;
131212397c6Schristos 
132212397c6Schristos typedef struct unz_file_info_s
133212397c6Schristos {
134212397c6Schristos     uLong version;              /* version made by                 2 bytes */
135212397c6Schristos     uLong version_needed;       /* version needed to extract       2 bytes */
136212397c6Schristos     uLong flag;                 /* general purpose bit flag        2 bytes */
137212397c6Schristos     uLong compression_method;   /* compression method              2 bytes */
138212397c6Schristos     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
139212397c6Schristos     uLong crc;                  /* crc-32                          4 bytes */
140212397c6Schristos     uLong compressed_size;      /* compressed size                 4 bytes */
141212397c6Schristos     uLong uncompressed_size;    /* uncompressed size               4 bytes */
142212397c6Schristos     uLong size_filename;        /* filename length                 2 bytes */
143212397c6Schristos     uLong size_file_extra;      /* extra field length              2 bytes */
144212397c6Schristos     uLong size_file_comment;    /* file comment length             2 bytes */
145212397c6Schristos 
146212397c6Schristos     uLong disk_num_start;       /* disk number start               2 bytes */
147212397c6Schristos     uLong internal_fa;          /* internal file attributes        2 bytes */
148212397c6Schristos     uLong external_fa;          /* external file attributes        4 bytes */
149212397c6Schristos 
150212397c6Schristos     tm_unz tmu_date;
151212397c6Schristos } unz_file_info;
152212397c6Schristos 
153212397c6Schristos extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
154212397c6Schristos                                                  const char* fileName2,
155212397c6Schristos                                                  int iCaseSensitivity));
156212397c6Schristos /*
157212397c6Schristos    Compare two filename (fileName1,fileName2).
158212397c6Schristos    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
159212397c6Schristos    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
160212397c6Schristos                                 or strcasecmp)
161212397c6Schristos    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
162212397c6Schristos     (like 1 on Unix, 2 on Windows)
163212397c6Schristos */
164212397c6Schristos 
165212397c6Schristos 
166212397c6Schristos extern unzFile ZEXPORT unzOpen OF((const char *path));
167212397c6Schristos extern unzFile ZEXPORT unzOpen64 OF((const void *path));
168212397c6Schristos /*
169212397c6Schristos   Open a Zip file. path contain the full pathname (by example,
170212397c6Schristos      on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
171212397c6Schristos      "zlib/zlib113.zip".
172212397c6Schristos      If the zipfile cannot be opened (file don't exist or in not valid), the
173212397c6Schristos        return value is NULL.
174212397c6Schristos      Else, the return value is a unzFile Handle, usable with other function
175212397c6Schristos        of this unzip package.
176212397c6Schristos      the "64" function take a const void* pointer, because the path is just the
177212397c6Schristos        value passed to the open64_file_func callback.
178212397c6Schristos      Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
179212397c6Schristos        is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180212397c6Schristos        does not describe the reality
181212397c6Schristos */
182212397c6Schristos 
183212397c6Schristos 
184212397c6Schristos extern unzFile ZEXPORT unzOpen2 OF((const char *path,
185212397c6Schristos                                     zlib_filefunc_def* pzlib_filefunc_def));
186212397c6Schristos /*
187212397c6Schristos    Open a Zip file, like unzOpen, but provide a set of file low level API
188212397c6Schristos       for read/write the zip file (see ioapi.h)
189212397c6Schristos */
190212397c6Schristos 
191212397c6Schristos extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
192212397c6Schristos                                     zlib_filefunc64_def* pzlib_filefunc_def));
193212397c6Schristos /*
194212397c6Schristos    Open a Zip file, like unz64Open, but provide a set of file low level API
195212397c6Schristos       for read/write the zip file (see ioapi.h)
196212397c6Schristos */
197212397c6Schristos 
198212397c6Schristos extern int ZEXPORT unzClose OF((unzFile file));
199212397c6Schristos /*
200ba340e45Schristos   Close a ZipFile opened with unzOpen.
201212397c6Schristos   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
202ba340e45Schristos     these files MUST be closed with unzCloseCurrentFile before call unzClose.
203212397c6Schristos   return UNZ_OK if there is no problem. */
204212397c6Schristos 
205212397c6Schristos extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
206212397c6Schristos                                         unz_global_info *pglobal_info));
207212397c6Schristos 
208212397c6Schristos extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
209212397c6Schristos                                         unz_global_info64 *pglobal_info));
210212397c6Schristos /*
211212397c6Schristos   Write info about the ZipFile in the *pglobal_info structure.
212212397c6Schristos   No preparation of the structure is needed
213212397c6Schristos   return UNZ_OK if there is no problem. */
214212397c6Schristos 
215212397c6Schristos 
216212397c6Schristos extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
217212397c6Schristos                                            char *szComment,
218212397c6Schristos                                            uLong uSizeBuf));
219212397c6Schristos /*
220212397c6Schristos   Get the global comment string of the ZipFile, in the szComment buffer.
221212397c6Schristos   uSizeBuf is the size of the szComment buffer.
222212397c6Schristos   return the number of byte copied or an error code <0
223212397c6Schristos */
224212397c6Schristos 
225212397c6Schristos 
226212397c6Schristos /***************************************************************************/
227212397c6Schristos /* Unzip package allow you browse the directory of the zipfile */
228212397c6Schristos 
229212397c6Schristos extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
230212397c6Schristos /*
231212397c6Schristos   Set the current file of the zipfile to the first file.
232212397c6Schristos   return UNZ_OK if there is no problem
233212397c6Schristos */
234212397c6Schristos 
235212397c6Schristos extern int ZEXPORT unzGoToNextFile OF((unzFile file));
236212397c6Schristos /*
237212397c6Schristos   Set the current file of the zipfile to the next file.
238212397c6Schristos   return UNZ_OK if there is no problem
239212397c6Schristos   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
240212397c6Schristos */
241212397c6Schristos 
242212397c6Schristos extern int ZEXPORT unzLocateFile OF((unzFile file,
243212397c6Schristos                      const char *szFileName,
244212397c6Schristos                      int iCaseSensitivity));
245212397c6Schristos /*
246212397c6Schristos   Try locate the file szFileName in the zipfile.
247212397c6Schristos   For the iCaseSensitivity signification, see unzStringFileNameCompare
248212397c6Schristos 
249212397c6Schristos   return value :
250212397c6Schristos   UNZ_OK if the file is found. It becomes the current file.
251212397c6Schristos   UNZ_END_OF_LIST_OF_FILE if the file is not found
252212397c6Schristos */
253212397c6Schristos 
254212397c6Schristos 
255212397c6Schristos /* ****************************************** */
256212397c6Schristos /* Ryan supplied functions */
257212397c6Schristos /* unz_file_info contain information about a file in the zipfile */
258212397c6Schristos typedef struct unz_file_pos_s
259212397c6Schristos {
260212397c6Schristos     uLong pos_in_zip_directory;   /* offset in zip file directory */
261212397c6Schristos     uLong num_of_file;            /* # of file */
262212397c6Schristos } unz_file_pos;
263212397c6Schristos 
264212397c6Schristos extern int ZEXPORT unzGetFilePos(
265212397c6Schristos     unzFile file,
266212397c6Schristos     unz_file_pos* file_pos);
267212397c6Schristos 
268212397c6Schristos extern int ZEXPORT unzGoToFilePos(
269212397c6Schristos     unzFile file,
270212397c6Schristos     unz_file_pos* file_pos);
271212397c6Schristos 
272212397c6Schristos typedef struct unz64_file_pos_s
273212397c6Schristos {
274212397c6Schristos     ZPOS64_T pos_in_zip_directory;   /* offset in zip file directory */
275212397c6Schristos     ZPOS64_T num_of_file;            /* # of file */
276212397c6Schristos } unz64_file_pos;
277212397c6Schristos 
278212397c6Schristos extern int ZEXPORT unzGetFilePos64(
279212397c6Schristos     unzFile file,
280212397c6Schristos     unz64_file_pos* file_pos);
281212397c6Schristos 
282212397c6Schristos extern int ZEXPORT unzGoToFilePos64(
283212397c6Schristos     unzFile file,
284212397c6Schristos     const unz64_file_pos* file_pos);
285212397c6Schristos 
286212397c6Schristos /* ****************************************** */
287212397c6Schristos 
288212397c6Schristos extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
289212397c6Schristos                          unz_file_info64 *pfile_info,
290212397c6Schristos                          char *szFileName,
291212397c6Schristos                          uLong fileNameBufferSize,
292212397c6Schristos                          void *extraField,
293212397c6Schristos                          uLong extraFieldBufferSize,
294212397c6Schristos                          char *szComment,
295212397c6Schristos                          uLong commentBufferSize));
296212397c6Schristos 
297212397c6Schristos extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
298212397c6Schristos                          unz_file_info *pfile_info,
299212397c6Schristos                          char *szFileName,
300212397c6Schristos                          uLong fileNameBufferSize,
301212397c6Schristos                          void *extraField,
302212397c6Schristos                          uLong extraFieldBufferSize,
303212397c6Schristos                          char *szComment,
304212397c6Schristos                          uLong commentBufferSize));
305212397c6Schristos /*
306212397c6Schristos   Get Info about the current file
307212397c6Schristos   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
308212397c6Schristos         the current file
309212397c6Schristos   if szFileName!=NULL, the filemane string will be copied in szFileName
310212397c6Schristos             (fileNameBufferSize is the size of the buffer)
311212397c6Schristos   if extraField!=NULL, the extra field information will be copied in extraField
312212397c6Schristos             (extraFieldBufferSize is the size of the buffer).
313212397c6Schristos             This is the Central-header version of the extra field
314212397c6Schristos   if szComment!=NULL, the comment string of the file will be copied in szComment
315212397c6Schristos             (commentBufferSize is the size of the buffer)
316212397c6Schristos */
317212397c6Schristos 
318212397c6Schristos 
319212397c6Schristos /** Addition for GDAL : START */
320212397c6Schristos 
321212397c6Schristos extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
322212397c6Schristos 
323212397c6Schristos /** Addition for GDAL : END */
324212397c6Schristos 
325212397c6Schristos 
326212397c6Schristos /***************************************************************************/
327212397c6Schristos /* for reading the content of the current zipfile, you can open it, read data
328212397c6Schristos    from it, and close it (you can close it before reading all the file)
329212397c6Schristos    */
330212397c6Schristos 
331212397c6Schristos extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
332212397c6Schristos /*
333212397c6Schristos   Open for reading data the current file in the zipfile.
334212397c6Schristos   If there is no error, the return value is UNZ_OK.
335212397c6Schristos */
336212397c6Schristos 
337212397c6Schristos extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
338212397c6Schristos                                                   const char* password));
339212397c6Schristos /*
340212397c6Schristos   Open for reading data the current file in the zipfile.
341212397c6Schristos   password is a crypting password
342212397c6Schristos   If there is no error, the return value is UNZ_OK.
343212397c6Schristos */
344212397c6Schristos 
345212397c6Schristos extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
346212397c6Schristos                                            int* method,
347212397c6Schristos                                            int* level,
348212397c6Schristos                                            int raw));
349212397c6Schristos /*
350212397c6Schristos   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
351212397c6Schristos     if raw==1
352212397c6Schristos   *method will receive method of compression, *level will receive level of
353212397c6Schristos      compression
354212397c6Schristos   note : you can set level parameter as NULL (if you did not want known level,
355212397c6Schristos          but you CANNOT set method parameter as NULL
356212397c6Schristos */
357212397c6Schristos 
358212397c6Schristos extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
359212397c6Schristos                                            int* method,
360212397c6Schristos                                            int* level,
361212397c6Schristos                                            int raw,
362212397c6Schristos                                            const char* password));
363212397c6Schristos /*
364212397c6Schristos   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
365212397c6Schristos     if raw==1
366212397c6Schristos   *method will receive method of compression, *level will receive level of
367212397c6Schristos      compression
368212397c6Schristos   note : you can set level parameter as NULL (if you did not want known level,
369212397c6Schristos          but you CANNOT set method parameter as NULL
370212397c6Schristos */
371212397c6Schristos 
372212397c6Schristos 
373212397c6Schristos extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
374212397c6Schristos /*
375212397c6Schristos   Close the file in zip opened with unzOpenCurrentFile
376212397c6Schristos   Return UNZ_CRCERROR if all the file was read but the CRC is not good
377212397c6Schristos */
378212397c6Schristos 
379212397c6Schristos extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
380212397c6Schristos                       voidp buf,
381212397c6Schristos                       unsigned len));
382212397c6Schristos /*
383212397c6Schristos   Read bytes from the current file (opened by unzOpenCurrentFile)
384212397c6Schristos   buf contain buffer where data must be copied
385212397c6Schristos   len the size of buf.
386212397c6Schristos 
387212397c6Schristos   return the number of byte copied if somes bytes are copied
388212397c6Schristos   return 0 if the end of file was reached
389212397c6Schristos   return <0 with error code if there is an error
390212397c6Schristos     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
391212397c6Schristos */
392212397c6Schristos 
393212397c6Schristos extern z_off_t ZEXPORT unztell OF((unzFile file));
394212397c6Schristos 
395212397c6Schristos extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
396212397c6Schristos /*
397212397c6Schristos   Give the current position in uncompressed data
398212397c6Schristos */
399212397c6Schristos 
400212397c6Schristos extern int ZEXPORT unzeof OF((unzFile file));
401212397c6Schristos /*
402212397c6Schristos   return 1 if the end of file was reached, 0 elsewhere
403212397c6Schristos */
404212397c6Schristos 
405212397c6Schristos extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
406212397c6Schristos                                              voidp buf,
407212397c6Schristos                                              unsigned len));
408212397c6Schristos /*
409212397c6Schristos   Read extra field from the current file (opened by unzOpenCurrentFile)
410212397c6Schristos   This is the local-header version of the extra field (sometimes, there is
411212397c6Schristos     more info in the local-header version than in the central-header)
412212397c6Schristos 
413212397c6Schristos   if buf==NULL, it return the size of the local extra field
414212397c6Schristos 
415212397c6Schristos   if buf!=NULL, len is the size of the buffer, the extra header is copied in
416212397c6Schristos     buf.
417212397c6Schristos   the return value is the number of bytes copied in buf, or (if <0)
418212397c6Schristos     the error code
419212397c6Schristos */
420212397c6Schristos 
421212397c6Schristos /***************************************************************************/
422212397c6Schristos 
423212397c6Schristos /* Get the current file offset */
424212397c6Schristos extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
425212397c6Schristos extern uLong ZEXPORT unzGetOffset (unzFile file);
426212397c6Schristos 
427212397c6Schristos /* Set the current file offset */
428212397c6Schristos extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
429212397c6Schristos extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
430212397c6Schristos 
431212397c6Schristos 
432212397c6Schristos 
433212397c6Schristos #ifdef __cplusplus
434212397c6Schristos }
435212397c6Schristos #endif
436212397c6Schristos 
437212397c6Schristos #endif /* _unz64_H */
438