1 /* MODIFIED BY Joseph Wenninger */
2 /* unzip.h -- IO for uncompress .zip files using zlib
3 Version 0.15 beta, Mar 19th, 1998,
5 Copyright (C) 1998 Gilles Vollant
7 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
8 WinZip, InfoZip tools and compatible.
9 Encryption and multi volume ZipFile (span) are not supported.
10 Old compressions used by old PKZip 1.x are not supported
12 THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
13 CAN CHANGE IN FUTURE VERSION !!
14 I WAIT FEEDBACK at mail info@winimage.com
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
17 Condition of use and distribution are the same than zlib :
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.
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:
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.
37 /* for more info about .ZIP format, see
38 ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
39 PkWare has also a specification at :
40 ftp://ftp.pkware.com/probdesc.zip */
53 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
54 /* like the STRICT of WIN32, we define a pointer that cannot be converted
55 from (void*) without cast */
56 typedef struct TagunzFile__ { int unused; } unzFile__;
57 typedef unzFile__ *unzFile;
59 typedef voidp unzFile;
66 #define UNZ_END_OF_LIST_OF_FILE (-100)
67 #define UNZ_ERRNO (Z_ERRNO)
69 #define UNZ_PARAMERROR (-102)
70 #define UNZ_BADZIPFILE (-103)
71 #define UNZ_INTERNALERROR (-104)
72 #define UNZ_CRCERROR (-105)
74 /* tm_unz contain date/time info */
75 typedef struct tm_unz_s
77 uInt tm_sec; /* seconds after the minute - [0,59] */
78 uInt tm_min; /* minutes after the hour - [0,59] */
79 uInt tm_hour; /* hours since midnight - [0,23] */
80 uInt tm_mday; /* day of the month - [1,31] */
81 uInt tm_mon; /* months since January - [0,11] */
82 uInt tm_year; /* years - [1980..2044] */
89 int cacao_locate(unzFile file,utf* filename); /*JOWENN*/
91 /* unz_global_info structure contain global data about the ZIPfile
92 These data comes from the end of central dir */
93 typedef struct unz_global_info_s
95 uLong number_entry; /* total number of entries in
96 the central dir on this disk */
97 uLong size_comment; /* size of the global comment of the zipfile */
101 /* unz_file_info contain information about a file in the zipfile */
102 typedef struct unz_file_info_s
104 uLong version; /* version made by 2 bytes */
105 uLong version_needed; /* version needed to extract 2 bytes */
106 uLong flag; /* general purpose bit flag 2 bytes */
107 uLong compression_method; /* compression method 2 bytes */
108 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
109 uLong crc; /* crc-32 4 bytes */
110 uLong compressed_size; /* compressed size 4 bytes */
111 uLong uncompressed_size; /* uncompressed size 4 bytes */
112 uLong size_filename; /* filename length 2 bytes */
113 uLong size_file_extra; /* extra field length 2 bytes */
114 uLong size_file_comment; /* file comment length 2 bytes */
116 uLong disk_num_start; /* disk number start 2 bytes */
117 uLong internal_fa; /* internal file attributes 2 bytes */
118 uLong external_fa; /* external file attributes 4 bytes */
124 /* unz_file_info_interntal contain internal info about a file in zipfile*/
125 typedef struct unz_file_info_internal_s
127 uLong offset_curfile;/* relative offset of local header 4 bytes */
128 } unz_file_info_internal;
131 /* file_in_zip_read_info_s contain internal information about a file in zipfile,
132 when reading and decompress it */
135 char *read_buffer; /* internal buffer for compressed data */
136 z_stream stream; /* zLib stream structure for inflate */
138 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
139 uLong stream_initialised; /* flag set if stream structure is initialised*/
141 uLong offset_local_extrafield;/* offset of the local extra field */
142 uInt size_local_extrafield;/* size of the local extra field */
143 uLong pos_local_extrafield; /* position in the local extra field in read*/
145 uLong crc32; /* crc32 of all data uncompressed */
146 uLong crc32_wait; /* crc32 we must obtain after decompress all */
147 uLong rest_read_compressed; /* number of byte to be decompressed */
148 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
149 FILE* file; /* io structore of the zipfile */
150 uLong compression_method; /* compression method (0==store) */
151 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
152 } file_in_zip_read_info_s;
156 typedef struct cacao_entry
158 struct cacao_entry *next;
163 /* unz_s contain internal information about the zipfile
167 FILE* file; /* io structore of the zipfile */
168 unz_global_info gi; /* public global information */
169 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
170 uLong num_file; /* number of the current file in the zipfile*/
171 uLong pos_in_central_dir; /* pos of the current file in the central dir*/
172 uLong current_file_ok; /* flag about the usability of the current file*/
173 uLong central_pos; /* position of the beginning of the central dir*/
175 uLong size_central_dir; /* size of the central directory */
176 uLong offset_central_dir; /* offset of start of central directory with
177 respect to the starting disk number */
179 unz_file_info cur_file_info; /* public info about the current file in zip*/
180 unz_file_info_internal cur_file_info_internal; /* private info about it*/
181 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
182 file if we are decompressing it */
183 cacao_entry_s *cacao_dir_list;
187 int unzStringFileNameCompare OF ((const char* fileName1,
188 const char* fileName2,
189 int iCaseSensitivity));
191 Compare two filename (fileName1,fileName2).
192 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
193 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
195 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
196 (like 1 on Unix, 2 on Windows)
200 unzFile unzOpen OF((const char *path));
202 Open a Zip file. path contain the full pathname (by example,
203 on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
205 If the zipfile cannot be opened (file don't exist or in not valid), the
206 return value is NULL.
207 Else, the return value is a unzFile Handle, usable with other function
208 of this unzip package.
211 int unzClose OF((unzFile file));
213 Close a ZipFile opened with unzipOpen.
214 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
215 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
216 return UNZ_OK if there is no problem. */
218 int unzGetGlobalInfo OF((unzFile file,
219 unz_global_info *pglobal_info));
221 Write info about the ZipFile in the *pglobal_info structure.
222 No preparation of the structure is needed
223 return UNZ_OK if there is no problem. */
226 int unzGetGlobalComment OF((unzFile file,
230 Get the global comment string of the ZipFile, in the szComment buffer.
231 uSizeBuf is the size of the szComment buffer.
232 return the number of byte copied or an error code <0
236 /***************************************************************************/
237 /* Unzip package allow you browse the directory of the zipfile */
239 int unzGoToFirstFile OF((unzFile file));
241 Set the current file of the zipfile to the first file.
242 return UNZ_OK if there is no problem
245 int unzGoToNextFile OF((unzFile file));
247 Set the current file of the zipfile to the next file.
248 return UNZ_OK if there is no problem
249 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
252 void cacao_create_directoryList(unzFile file);
254 int unzLocateFile OF((unzFile file,
255 const char *szFileName,
256 int iCaseSensitivity));
258 Try locate the file szFileName in the zipfile.
259 For the iCaseSensitivity signification, see unzStringFileNameCompare
262 UNZ_OK if the file is found. It becomes the current file.
263 UNZ_END_OF_LIST_OF_FILE if the file is not found
267 int unzGetCurrentFileInfo OF((unzFile file,
268 unz_file_info *pfile_info,
270 uLong fileNameBufferSize,
272 uLong extraFieldBufferSize,
274 uLong commentBufferSize));
276 Get Info about the current file
277 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
279 if szFileName!=NULL, the filemane string will be copied in szFileName
280 (fileNameBufferSize is the size of the buffer)
281 if extraField!=NULL, the extra field information will be copied in extraField
282 (extraFieldBufferSize is the size of the buffer).
283 This is the Central-header version of the extra field
284 if szComment!=NULL, the comment string of the file will be copied in szComment
285 (commentBufferSize is the size of the buffer)
288 /***************************************************************************/
289 /* for reading the content of the current zipfile, you can open it, read data
290 from it, and close it (you can close it before reading all the file)
293 int unzOpenCurrentFile OF((unzFile file));
295 Open for reading data the current file in the zipfile.
296 If there is no error, the return value is UNZ_OK.
299 int unzCloseCurrentFile OF((unzFile file));
301 Close the file in zip opened with unzOpenCurrentFile
302 Return UNZ_CRCERROR if all the file was read but the CRC is not good
306 int unzReadCurrentFile OF((unzFile file,
310 Read bytes from the current file (opened by unzOpenCurrentFile)
311 buf contain buffer where data must be copied
314 return the number of byte copied if somes bytes are copied
315 return 0 if the end of file was reached
316 return <0 with error code if there is an error
317 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
320 z_off_t unztell OF((unzFile file));
322 Give the current position in uncompressed data
325 int unzeof OF((unzFile file));
327 return 1 if the end of file was reached, 0 elsewhere
330 int unzGetLocalExtrafield OF((unzFile file,
334 Read extra field from the current file (opened by unzOpenCurrentFile)
335 This is the local-header version of the extra field (sometimes, there is
336 more info in the local-header version than in the central-header)
338 if buf==NULL, it return the size of the local extra field
340 if buf!=NULL, len is the size of the buffer, the extra header is copied in
342 the return value is the number of bytes copied in buf, or (if <0)