minor documentation corrections
[cacao.git] / unzip.h
1 /* MODIFIED BY Joseph Wenninger */
2 /* unzip.h -- IO for uncompress .zip files using zlib 
3    Version 0.15 beta, Mar 19th, 1998,
4
5    Copyright (C) 1998 Gilles Vollant
6
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
11
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
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 /* 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 */
41
42 #ifndef _unz_H
43 #define _unz_H
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #ifndef _ZLIB_H
50 #include "zlib.h"
51 #endif
52
53 #include "global.h"
54
55 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
56 /* like the STRICT of WIN32, we define a pointer that cannot be converted
57     from (void*) without cast */
58 typedef struct TagunzFile__ { int unused; } unzFile__; 
59 typedef unzFile__ *unzFile;
60 #else
61 typedef voidp unzFile;
62 #endif
63
64
65 #define UNZ_OK                                  (0)
66 #define UNZ_END_OF_LIST_OF_FILE (-100)
67 #define UNZ_ERRNO               (Z_ERRNO)
68 #define UNZ_EOF                 (0)
69 #define UNZ_PARAMERROR                  (-102)
70 #define UNZ_BADZIPFILE                  (-103)
71 #define UNZ_INTERNALERROR               (-104)
72 #define UNZ_CRCERROR                    (-105)
73
74 /* tm_unz contain date/time info */
75 typedef struct tm_unz_s 
76 {
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] */
83 } tm_unz;
84
85 #ifndef z_off_t
86 #define z_off_t uLong
87 #endif
88
89 int cacao_locate(unzFile file,utf* filename); /*JOWENN*/
90
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
94 {
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 */
98 } unz_global_info;
99
100
101 /* unz_file_info contain information about a file in the zipfile */
102 typedef struct unz_file_info_s
103 {
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 */
115
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 */
119
120     tm_unz tmu_date;
121 } unz_file_info;
122
123 int  unzStringFileNameCompare OF ((const char* fileName1,
124                                                                                                  const char* fileName2,
125                                                                                                  int iCaseSensitivity));
126 /*
127    Compare two filename (fileName1,fileName2).
128    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
129    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
130                                                                 or strcasecmp)
131    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
132         (like 1 on Unix, 2 on Windows)
133 */
134
135
136 unzFile unzOpen OF((const char *path));
137 /*
138   Open a Zip file. path contain the full pathname (by example,
139      on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
140          "zlib/zlib111.zip".
141          If the zipfile cannot be opened (file don't exist or in not valid), the
142            return value is NULL.
143      Else, the return value is a unzFile Handle, usable with other function
144            of this unzip package.
145 */
146
147 int  unzClose OF((unzFile file));
148 /*
149   Close a ZipFile opened with unzipOpen.
150   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
151     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
152   return UNZ_OK if there is no problem. */
153
154 int  unzGetGlobalInfo OF((unzFile file,
155                                         unz_global_info *pglobal_info));
156 /*
157   Write info about the ZipFile in the *pglobal_info structure.
158   No preparation of the structure is needed
159   return UNZ_OK if there is no problem. */
160
161
162 int unzGetGlobalComment OF((unzFile file,
163                                                                                    char *szComment,
164                                            uLong uSizeBuf));
165 /*
166   Get the global comment string of the ZipFile, in the szComment buffer.
167   uSizeBuf is the size of the szComment buffer.
168   return the number of byte copied or an error code <0
169 */
170
171
172 /***************************************************************************/
173 /* Unzip package allow you browse the directory of the zipfile */
174
175 int  unzGoToFirstFile OF((unzFile file));
176 /*
177   Set the current file of the zipfile to the first file.
178   return UNZ_OK if there is no problem
179 */
180
181 int  unzGoToNextFile OF((unzFile file));
182 /*
183   Set the current file of the zipfile to the next file.
184   return UNZ_OK if there is no problem
185   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
186 */
187
188 void cacao_create_directoryList(unzFile file);
189
190 int  unzLocateFile OF((unzFile file, 
191                                      const char *szFileName,
192                                      int iCaseSensitivity));
193 /*
194   Try locate the file szFileName in the zipfile.
195   For the iCaseSensitivity signification, see unzStringFileNameCompare
196
197   return value :
198   UNZ_OK if the file is found. It becomes the current file.
199   UNZ_END_OF_LIST_OF_FILE if the file is not found
200 */
201
202
203 int  unzGetCurrentFileInfo OF((unzFile file,
204                                              unz_file_info *pfile_info,
205                                              char *szFileName,
206                                              uLong fileNameBufferSize,
207                                              void *extraField,
208                                              uLong extraFieldBufferSize,
209                                              char *szComment,
210                                              uLong commentBufferSize));
211 /*
212   Get Info about the current file
213   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
214             the current file
215   if szFileName!=NULL, the filemane string will be copied in szFileName
216                         (fileNameBufferSize is the size of the buffer)
217   if extraField!=NULL, the extra field information will be copied in extraField
218                         (extraFieldBufferSize is the size of the buffer).
219                         This is the Central-header version of the extra field
220   if szComment!=NULL, the comment string of the file will be copied in szComment
221                         (commentBufferSize is the size of the buffer)
222 */
223
224 /***************************************************************************/
225 /* for reading the content of the current zipfile, you can open it, read data
226    from it, and close it (you can close it before reading all the file)
227    */
228
229 int  unzOpenCurrentFile OF((unzFile file));
230 /*
231   Open for reading data the current file in the zipfile.
232   If there is no error, the return value is UNZ_OK.
233 */
234
235 int  unzCloseCurrentFile OF((unzFile file));
236 /*
237   Close the file in zip opened with unzOpenCurrentFile
238   Return UNZ_CRCERROR if all the file was read but the CRC is not good
239 */
240
241                                                                                                 
242 int  unzReadCurrentFile OF((unzFile file, 
243                                           voidp buf,
244                                           unsigned len));
245 /*
246   Read bytes from the current file (opened by unzOpenCurrentFile)
247   buf contain buffer where data must be copied
248   len the size of buf.
249
250   return the number of byte copied if somes bytes are copied
251   return 0 if the end of file was reached
252   return <0 with error code if there is an error
253     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
254 */
255
256 z_off_t unztell OF((unzFile file));
257 /*
258   Give the current position in uncompressed data
259 */
260
261 int  unzeof OF((unzFile file));
262 /*
263   return 1 if the end of file was reached, 0 elsewhere 
264 */
265
266 int  unzGetLocalExtrafield OF((unzFile file,
267                                                                                          voidp buf,
268                                                                                          unsigned len));
269 /*
270   Read extra field from the current file (opened by unzOpenCurrentFile)
271   This is the local-header version of the extra field (sometimes, there is
272     more info in the local-header version than in the central-header)
273
274   if buf==NULL, it return the size of the local extra field
275
276   if buf!=NULL, len is the size of the buffer, the extra header is copied in
277         buf.
278   the return value is the number of bytes copied in buf, or (if <0) 
279         the error code
280 */
281
282
283 #ifdef __cplusplus
284 }
285 #endif
286
287 #endif /* _unz_H */