UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unzip.h
Go to the documentation of this file.
1 /* unzip.h -- IO for uncompress .zip files using zlib
2  Version 1.01e, February 12th, 2005
3 
4  Copyright (C) 1998-2005 Gilles Vollant
5 
6  This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7  WinZip, InfoZip tools and compatible.
8 
9  Multi volume ZipFile (span) are not supported.
10  Encryption compatible with pkzip 2.04g only supported
11  Old compressions used by old PKZip 1.x are not supported
12 
13 
14  I WAIT FEEDBACK at mail info@winimage.com
15  Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
16 
17  Condition of use and distribution are the same than zlib :
18 
19  This software is provided 'as-is', without any express or implied
20  warranty. In no event will the authors be held liable for any damages
21  arising from the use of this software.
22 
23  Permission is granted to anyone to use this software for any purpose,
24  including commercial applications, and to alter it and redistribute it
25  freely, subject to the following restrictions:
26 
27  1. The origin of this software must not be misrepresented; you must not
28  claim that you wrote the original software. If you use this software
29  in a product, an acknowledgment in the product documentation would be
30  appreciated but is not required.
31  2. Altered source versions must be plainly marked as such, and must not be
32  misrepresented as being the original software.
33  3. This notice may not be removed or altered from any source distribution.
34 
35 
36 */
37 
38 /* for more info about .ZIP format, see
39  http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40  http://www.info-zip.org/pub/infozip/doc/
41  PkWare has also a specification at :
42  ftp://ftp.pkware.com/probdesc.zip
43 */
44 
45 #pragma once
46 
47 /* disable encryption */
48 #ifndef NOUNCRYPT
49 #define NOUNCRYPT
50 #endif
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #ifndef _ZLIB_H
57 #include <zlib.h>
58 #endif
59 
60 #ifndef _ZLIBIOAPI_H
61 #include "ioapi.h"
62 #endif
63 
64 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
65 /* like the STRICT of WIN32, we define a pointer that cannot be converted
66  from (void*) without cast */
67 typedef struct TagunzFile__ { int unused; } unzFile__;
68 typedef unzFile__ *unzFile;
69 #else
70 typedef voidp unzFile;
71 #endif
72 
73 
74 #define UNZ_OK (0)
75 #define UNZ_END_OF_LIST_OF_FILE (-100)
76 #define UNZ_ERRNO (Z_ERRNO)
77 #define UNZ_EOF (0)
78 #define UNZ_PARAMERROR (-102)
79 #define UNZ_BADZIPFILE (-103)
80 #define UNZ_INTERNALERROR (-104)
81 #define UNZ_CRCERROR (-105)
82 
83 /* tm_unz contain date/time info */
84 typedef struct tm_unz_s
85 {
86  uInt tm_sec; /* seconds after the minute - [0,59] */
87  uInt tm_min; /* minutes after the hour - [0,59] */
88  uInt tm_hour; /* hours since midnight - [0,23] */
89  uInt tm_mday; /* day of the month - [1,31] */
90  uInt tm_mon; /* months since January - [0,11] */
91  uInt tm_year; /* years - [1980..2044] */
92 } tm_unz;
93 
94 /* unz_global_info structure contain global data about the ZIPfile
95  These data comes from the end of central dir */
96 typedef struct unz_global_info_s
97 {
98  uLong number_entry; /* total number of entries in
99  the central dir on this disk */
100  uLong size_comment; /* size of the global comment of the zipfile */
102 
103 
104 /* unz_file_info contain information about a file in the zipfile */
105 typedef struct unz_file_info_s
106 {
107  uLong version; /* version made by 2 bytes */
108  uLong version_needed; /* version needed to extract 2 bytes */
109  uLong flag; /* general purpose bit flag 2 bytes */
110  uLong compression_method; /* compression method 2 bytes */
111  uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
112  uLong crc; /* crc-32 4 bytes */
113  uLong compressed_size; /* compressed size 4 bytes */
114  uLong uncompressed_size; /* uncompressed size 4 bytes */
115  uLong size_filename; /* filename length 2 bytes */
116  uLong size_file_extra; /* extra field length 2 bytes */
117  uLong size_file_comment; /* file comment length 2 bytes */
118 
119  uLong disk_num_start; /* disk number start 2 bytes */
120  uLong internal_fa; /* internal file attributes 2 bytes */
121  uLong external_fa; /* external file attributes 4 bytes */
122 
124 } unz_file_info;
125 
126 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
127  const char* fileName2,
128  int iCaseSensitivity));
129 /*
130  Compare two filename (fileName1,fileName2).
131  If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
132  If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
133  or strcasecmp)
134  If iCaseSenisivity = 0, case sensitivity is default of your operating system
135  (like 1 on Unix, 2 on Windows)
136 */
137 
138 
139 extern unzFile ZEXPORT unzOpen OF((const char* path));
140 /*
141  Open a Zip file. path contain the full pathname (by example,
142  on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
143  "zlib/zlib113.zip".
144  If the zipfile cannot be opened (file don't exist or in not valid), the
145  return value is NULL.
146  Else, the return value is a unzFile Handle, usable with other function
147  of this unzip package.
148 */
149 
150 extern unzFile ZEXPORT unzOpen2 OF((const char* path,
151  zlib_filefunc_def* pzlib_filefunc_def));
152 /*
153  Open a Zip file, like unzOpen, but provide a set of file low level API
154  for read/write the zip file (see ioapi.h)
155 */
156 
157 extern int ZEXPORT unzClose OF((unzFile file));
158 /*
159  Close a ZipFile opened with unzipOpen.
160  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
161  these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
162  return UNZ_OK if there is no problem. */
163 
164 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
165  unz_global_info *pglobal_info));
166 /*
167  Write info about the ZipFile in the *pglobal_info structure.
168  No preparation of the structure is needed
169  return UNZ_OK if there is no problem. */
170 
171 
172 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
173  char* szComment,
174  uLong uSizeBuf));
175 /*
176  Get the global comment string of the ZipFile, in the szComment buffer.
177  uSizeBuf is the size of the szComment buffer.
178  return the number of byte copied or an error code <0
179 */
180 
181 
182 /***************************************************************************/
183 /* Unzip package allow you browse the directory of the zipfile */
184 
185 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
186 /*
187  Set the current file of the zipfile to the first file.
188  return UNZ_OK if there is no problem
189 */
190 
191 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
192 /*
193  Set the current file of the zipfile to the next file.
194  return UNZ_OK if there is no problem
195  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
196 */
197 
198 extern int ZEXPORT unzLocateFile OF((unzFile file,
199  const char* szFileName,
200  int iCaseSensitivity));
201 /*
202  Try locate the file szFileName in the zipfile.
203  For the iCaseSensitivity signification, see unzStringFileNameCompare
204 
205  return value :
206  UNZ_OK if the file is found. It becomes the current file.
207  UNZ_END_OF_LIST_OF_FILE if the file is not found
208 */
209 
210 
211 /* ****************************************** */
212 /* Ryan supplied functions */
213 /* unz_file_info contain information about a file in the zipfile */
214 typedef struct unz_file_pos_s
215 {
216  uLong pos_in_zip_directory; /* offset in zip file directory */
217  uLong num_of_file; /* # of file */
218 } unz_file_pos;
219 
220 extern int ZEXPORT unzGetFilePos(
221  unzFile file,
222  unz_file_pos* file_pos);
223 
224 extern int ZEXPORT unzGoToFilePos(
225  unzFile file,
226  unz_file_pos* file_pos);
227 
228 /* ****************************************** */
229 
230 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
231  unz_file_info *pfile_info,
232  char* szFileName,
233  uLong fileNameBufferSize,
234  void* extraField,
235  uLong extraFieldBufferSize,
236  char* szComment,
237  uLong commentBufferSize));
238 /*
239  Get Info about the current file
240  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
241  the current file
242  if szFileName!=NULL, the filemane string will be copied in szFileName
243  (fileNameBufferSize is the size of the buffer)
244  if extraField!=NULL, the extra field information will be copied in extraField
245  (extraFieldBufferSize is the size of the buffer).
246  This is the Central-header version of the extra field
247  if szComment!=NULL, the comment string of the file will be copied in szComment
248  (commentBufferSize is the size of the buffer)
249 */
250 
251 /***************************************************************************/
252 /* for reading the content of the current zipfile, you can open it, read data
253  from it, and close it (you can close it before reading all the file)
254  */
255 
256 extern int unzSetCurrentFileInfoPosition (unzFile file, unsigned long pos );
257 
258 /*
259  Set the position of the info of the current file in the zip.
260  return UNZ_OK if there is no problem
261 */
262 
263 extern int unzGetCurrentFileInfoPosition (unzFile file, unsigned long *pos );
264 
265 /*
266  Get the position of the info of the current file in the zip.
267  return UNZ_OK if there is no problem
268 */
269 
270 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
271 /*
272  Open for reading data the current file in the zipfile.
273  If there is no error, the return value is UNZ_OK.
274 */
275 
276 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
277  const char* password));
278 /*
279  Open for reading data the current file in the zipfile.
280  password is a crypting password
281  If there is no error, the return value is UNZ_OK.
282 */
283 
284 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
285  int* method,
286  int* level,
287  int raw));
288 /*
289  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
290  if raw==1
291  *method will receive method of compression, *level will receive level of
292  compression
293  note : you can set level parameter as NULL (if you did not want known level,
294  but you CANNOT set method parameter as NULL
295 */
296 
297 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
298  int* method,
299  int* level,
300  int raw,
301  const char* password));
302 /*
303  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
304  if raw==1
305  *method will receive method of compression, *level will receive level of
306  compression
307  note : you can set level parameter as NULL (if you did not want known level,
308  but you CANNOT set method parameter as NULL
309 */
310 
311 
312 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
313 /*
314  Close the file in zip opened with unzOpenCurrentFile
315  Return UNZ_CRCERROR if all the file was read but the CRC is not good
316 */
317 
318 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
319  voidp buf,
320  unsigned len));
321 /*
322  Read bytes from the current file (opened by unzOpenCurrentFile)
323  buf contain buffer where data must be copied
324  len the size of buf.
325 
326  return the number of byte copied if somes bytes are copied
327  return 0 if the end of file was reached
328  return <0 with error code if there is an error
329  (UNZ_ERRNO for IO error, or zLib error for uncompress error)
330 */
331 
332 extern z_off_t ZEXPORT unztell OF((unzFile file));
333 /*
334  Give the current position in uncompressed data
335 */
336 
337 extern int ZEXPORT unzeof OF((unzFile file));
338 /*
339  return 1 if the end of file was reached, 0 elsewhere
340 */
341 
342 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
343  voidp buf,
344  unsigned len));
345 /*
346  Read extra field from the current file (opened by unzOpenCurrentFile)
347  This is the local-header version of the extra field (sometimes, there is
348  more info in the local-header version than in the central-header)
349 
350  if buf==NULL, it return the size of the local extra field
351 
352  if buf!=NULL, len is the size of the buffer, the extra header is copied in
353  buf.
354  the return value is the number of bytes copied in buf, or (if <0)
355  the error code
356 */
357 
358 /***************************************************************************/
359 
360 /* Get the current file offset */
361 extern uLong ZEXPORT unzGetOffset (unzFile file);
362 
363 /* Set the current file offset */
364 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
365 
366 
367 
368 #ifdef __cplusplus
369 }
370 #endif
int unzSetCurrentFileInfoPosition(unzFile file, unsigned long pos)
Definition: unzip.cpp:1432
int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
Definition: unzip.cpp:797
voidp unzFile
Definition: unzip.h:70
tm_unz tmu_date
Definition: unzip.h:123
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
Definition: unzip.cpp:1069
uLong size_file_extra
Definition: unzip.h:116
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info)
Definition: unzip.cpp:475
uLong pos_in_zip_directory
Definition: unzip.h:216
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
Definition: unzip.cpp:731
int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.cpp:669
uInt tm_mon
Definition: unzip.h:90
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
Definition: unzip.cpp:927
uLong uncompressed_size
Definition: unzip.h:114
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
Definition: unzip.cpp:346
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.cpp:701
voidpf void * buf
Definition: ioapi.h:42
uLong size_file_comment
Definition: unzip.h:117
int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
Definition: unzip.cpp:1288
uLong ZEXPORT unzGetOffset(unzFile file)
Definition: unzip.cpp:1399
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.cpp:681
uInt tm_mday
Definition: unzip.h:89
int ZEXPORT unzStringFileNameCompare OF((const char *fileName1, const char *fileName2, int iCaseSensitivity))
int unzGetCurrentFileInfoPosition(unzFile file, unsigned long *pos)
Definition: unzip.cpp:1450
uLong size_filename
Definition: unzip.h:115
uInt tm_hour
Definition: unzip.h:88
uInt tm_min
Definition: unzip.h:87
unzFile ZEXPORT unzOpen(const char *path)
Definition: unzip.cpp:446
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.cpp:1333
int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
Definition: unzip.cpp:811
uLong internal_fa
Definition: unzip.h:120
uInt tm_sec
Definition: unzip.h:86
uLong disk_num_start
Definition: unzip.h:119
uLong compression_method
Definition: unzip.h:110
Definition: unzip.h:84
z_off_t ZEXPORT unztell(unzFile file)
Definition: unzip.cpp:1241
uLong version
Definition: unzip.h:107
struct unz_file_info_s unz_file_info
uLong crc
Definition: unzip.h:112
cvar_t * password
Definition: g_main.cpp:67
uLong version_needed
Definition: unzip.h:108
QGL_EXTERN GLuint GLchar GLuint * len
Definition: r_gl.h:99
int ZEXPORT unzeof(unzFile file)
Definition: unzip.cpp:1258
int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition: unzip.cpp:1064
int ZEXPORT unzSetOffset(unzFile file, uLong pos)
Definition: unzip.cpp:1412
uLong compressed_size
Definition: unzip.h:113
uLong number_entry
Definition: unzip.h:98
struct unz_file_pos_s unz_file_pos
uLong num_of_file
Definition: unzip.h:217
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
Definition: unzip.cpp:1373
int ZEXPORT unzClose(unzFile file)
Definition: unzip.cpp:456
uLong dosDate
Definition: unzip.h:111
struct unz_global_info_s unz_global_info
struct tm_unz_s tm_unz
uInt tm_year
Definition: unzip.h:91
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
Definition: unzip.cpp:1074
uLong flag
Definition: unzip.h:109
typedef uLong(ZCALLBACK *read_file_func) OF((voidpf opaque
int ZEXPORT unzStringFileNameCompare(const char *fileName1, const char *fileName2, int iCaseSensitivity)
Definition: unzip.cpp:269
level_locals_t level
Definition: g_main.cpp:38
uLong size_comment
Definition: unzip.h:100
uLong external_fa
Definition: unzip.h:121
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Definition: unzip.cpp:1089