]> git.saurik.com Git - wxWidgets.git/blob - src/common/unzip.h
Reverted patch [ 832096 ] Final separation for GUI and console for Open Watcom
[wxWidgets.git] / src / common / unzip.h
1 /*
2
3 This file was altered for needs of wxWindows.
4 $Id$
5
6 */
7
8 /* unzip.h -- IO for uncompress .zip files using zlib
9 Version 0.15 beta, Mar 19th, 1998,
10
11 Copyright (C) 1998 Gilles Vollant
12
13 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
14 WinZip, InfoZip tools and compatible.
15 Encryption and multi volume ZipFile (span) are not supported.
16 Old compressions used by old PKZip 1.x are not supported
17
18 THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
19 CAN CHANGE IN FUTURE VERSION !!
20 I WAIT FEEDBACK at mail info@winimage.com
21 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
22
23 Condition of use and distribution are the same than zlib :
24
25 This software is provided 'as-is', without any express or implied
26 warranty. In no event will the authors be held liable for any damages
27 arising from the use of this software.
28
29 Permission is granted to anyone to use this software for any purpose,
30 including commercial applications, and to alter it and redistribute it
31 freely, subject to the following restrictions:
32
33 1. The origin of this software must not be misrepresented; you must not
34 claim that you wrote the original software. If you use this software
35 in a product, an acknowledgment in the product documentation would be
36 appreciated but is not required.
37 2. Altered source versions must be plainly marked as such, and must not be
38 misrepresented as being the original software.
39 3. This notice may not be removed or altered from any source distribution.
40
41
42 */
43 /* for more info about .ZIP format, see
44 ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
45 PkWare has also a specification at :
46 ftp://ftp.pkware.com/probdesc.zip */
47
48 #ifndef _unz_H
49 #define _unz_H
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /* include zlib.h if not done yet */
56 #ifndef _ZLIB_H
57 /*
58 normally, the compiler options should contain -I../zlib, but it is
59 apparently not the case for all MSW makefiles and so, unless we use
60 configure (which defines __WX_SETUP_H__) or it is explicitly overridden
61 by the user (who can define wxUSE_ZLIB_H_IN_PATH), we hardcode the path
62 here
63 */
64 # if defined(__WXMSW__) && !defined(__WX_SETUP_H__) && !defined(wxUSE_ZLIB_H_IN_PATH)
65 # include "../zlib/zlib.h"
66 # else
67 # include "zlib.h"
68 # endif
69 #endif /* _ZLIB_H */
70
71 /*
72 Some system zlib.h headers are modified to not define the OF() macro but use
73 the (standard) __P() instead (example: NetBSD 1.6), work around this if
74 needed assuming that we deal with an ANSI C compiler (which is a natural
75 assumption in 21st century!)
76 */
77 #ifndef OF
78 # define OF(args) args
79 #endif
80
81 /*
82 And on some systems ZEXPORT is not defined neither -- work around this too
83 */
84 #ifndef ZEXPORT
85 # define ZEXPORT
86 #endif
87
88 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
89 /* like the STRICT of WIN32, we define a pointer that cannot be converted
90 from (void*) without cast */
91 typedef struct TagunzFile__ { int unused; } unzFile__;
92 typedef unzFile__ *unzFile;
93 #else
94 typedef voidp unzFile;
95 #endif
96
97
98 #define UNZ_OK (0)
99 #define UNZ_END_OF_LIST_OF_FILE (-100)
100 #define UNZ_ERRNO (Z_ERRNO)
101 #define UNZ_EOF (0)
102 #define UNZ_PARAMERROR (-102)
103 #define UNZ_BADZIPFILE (-103)
104 #define UNZ_INTERNALERROR (-104)
105 #define UNZ_CRCERROR (-105)
106
107 /* tm_unz contain date/time info */
108 typedef struct tm_unz_s
109 {
110 uInt tm_sec; /* seconds after the minute - [0,59] */
111 uInt tm_min; /* minutes after the hour - [0,59] */
112 uInt tm_hour; /* hours since midnight - [0,23] */
113 uInt tm_mday; /* day of the month - [1,31] */
114 uInt tm_mon; /* months since January - [0,11] */
115 uInt tm_year; /* years - [1980..2044] */
116 } tm_unz;
117
118 /* unz_global_info structure contain global data about the ZIPfile
119 These data comes from the end of central dir */
120 typedef struct unz_global_info_s
121 {
122 uLong number_entry; /* total number of entries in
123 the central dir on this disk */
124 uLong size_comment; /* size of the global comment of the zipfile */
125 } unz_global_info;
126
127
128 /* unz_file_info contain information about a file in the zipfile */
129 typedef struct unz_file_info_s
130 {
131 uLong version; /* version made by 2 bytes */
132 uLong version_needed; /* version needed to extract 2 bytes */
133 uLong flag; /* general purpose bit flag 2 bytes */
134 uLong compression_method; /* compression method 2 bytes */
135 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
136 uLong crc; /* crc-32 4 bytes */
137 uLong compressed_size; /* compressed size 4 bytes */
138 uLong uncompressed_size; /* uncompressed size 4 bytes */
139 uLong size_filename; /* filename length 2 bytes */
140 uLong size_file_extra; /* extra field length 2 bytes */
141 uLong size_file_comment; /* file comment length 2 bytes */
142
143 uLong disk_num_start; /* disk number start 2 bytes */
144 uLong internal_fa; /* internal file attributes 2 bytes */
145 uLong external_fa; /* external file attributes 4 bytes */
146
147 tm_unz tmu_date;
148 } unz_file_info;
149
150 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
151 const char* fileName2,
152 int iCaseSensitivity));
153 /*
154 Compare two filename (fileName1,fileName2).
155 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
156 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
157 or strcasecmp)
158 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
159 (like 1 on Unix, 2 on Windows)
160 */
161
162
163 extern unzFile ZEXPORT unzOpen OF((const char *path));
164 /*
165 Open a Zip file. path contain the full pathname (by example,
166 on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
167 "zlib/zlib111.zip".
168 If the zipfile cannot be opened (file don't exist or in not valid), the
169 return value is NULL.
170 Else, the return value is a unzFile Handle, usable with other function
171 of this unzip package.
172 */
173
174 extern int ZEXPORT unzClose OF((unzFile file));
175 /*
176 Close a ZipFile opened with unzipOpen.
177 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
178 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
179 return UNZ_OK if there is no problem. */
180
181 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
182 unz_global_info *pglobal_info));
183 /*
184 Write info about the ZipFile in the *pglobal_info structure.
185 No preparation of the structure is needed
186 return UNZ_OK if there is no problem. */
187
188
189 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
190 char *szComment,
191 uLong uSizeBuf));
192 /*
193 Get the global comment string of the ZipFile, in the szComment buffer.
194 uSizeBuf is the size of the szComment buffer.
195 return the number of byte copied or an error code <0
196 */
197
198
199 /***************************************************************************/
200 /* Unzip package allow you browse the directory of the zipfile */
201
202 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
203 /*
204 Set the current file of the zipfile to the first file.
205 return UNZ_OK if there is no problem
206 */
207
208 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
209 /*
210 Set the current file of the zipfile to the next file.
211 return UNZ_OK if there is no problem
212 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
213 */
214
215 extern int ZEXPORT unzLocateFile OF((unzFile file,
216 const char *szFileName,
217 int iCaseSensitivity));
218 /*
219 Try locate the file szFileName in the zipfile.
220 For the iCaseSensitivity signification, see unzStringFileNameCompare
221
222 return value :
223 UNZ_OK if the file is found. It becomes the current file.
224 UNZ_END_OF_LIST_OF_FILE if the file is not found
225 */
226
227
228 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
229 unz_file_info *pfile_info,
230 char *szFileName,
231 uLong fileNameBufferSize,
232 void *extraField,
233 uLong extraFieldBufferSize,
234 char *szComment,
235 uLong commentBufferSize));
236 /*
237 Get Info about the current file
238 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
239 the current file
240 if szFileName!=NULL, the filemane string will be copied in szFileName
241 (fileNameBufferSize is the size of the buffer)
242 if extraField!=NULL, the extra field information will be copied in extraField
243 (extraFieldBufferSize is the size of the buffer).
244 This is the Central-header version of the extra field
245 if szComment!=NULL, the comment string of the file will be copied in szComment
246 (commentBufferSize is the size of the buffer)
247 */
248
249 /***************************************************************************/
250 /* for reading the content of the current zipfile, you can open it, read data
251 from it, and close it (you can close it before reading all the file)
252 */
253
254 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
255 /*
256 Open for reading data the current file in the zipfile.
257 If there is no error, the return value is UNZ_OK.
258 */
259
260 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
261 /*
262 Close the file in zip opened with unzOpenCurrentFile
263 Return UNZ_CRCERROR if all the file was read but the CRC is not good
264 */
265
266
267 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
268 voidp buf,
269 unsigned len));
270 /*
271 Read bytes from the current file (opened by unzOpenCurrentFile)
272 buf contain buffer where data must be copied
273 len the size of buf.
274
275 return the number of byte copied if somes bytes are copied
276 return 0 if the end of file was reached
277 return <0 with error code if there is an error
278 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
279 */
280
281 extern z_off_t ZEXPORT unztell OF((unzFile file));
282 /*
283 Give the current position in uncompressed data
284 */
285
286 extern int ZEXPORT unzeof OF((unzFile file));
287 /*
288 return 1 if the end of file was reached, 0 elsewhere
289 */
290
291 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
292 voidp buf,
293 unsigned len));
294 /*
295 Read extra field from the current file (opened by unzOpenCurrentFile)
296 This is the local-header version of the extra field (sometimes, there is
297 more info in the local-header version than in the central-header)
298
299 if buf==NULL, it return the size of the local extra field
300
301 if buf!=NULL, len is the size of the buffer, the extra header is copied in
302 buf.
303 the return value is the number of bytes copied in buf, or (if <0)
304 the error code
305 */
306
307 #if defined(__VISAGECPP__) || defined(__BORLANDC__)
308 /*Visualage complains of no prototypes*/
309 int unzlocal_getByte(FILE* , int*);
310 int strcmpcasenosensitive_internal (const char*, const char*);
311 int unzlocal_getShort (FILE*, uLong*);
312 int unzlocal_getLong (FILE*, uLong*);
313 uLong unzlocal_SearchCentralDir(FILE*);
314 void unzlocal_DosDateToTmuDate (uLong, tm_unz*);
315 #endif
316
317 #ifdef __cplusplus
318 }
319 #endif
320
321 #endif /* _unz_H */