]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/pak/unzip.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / libs / pak / unzip.h
1 \r
2 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)\r
3 /* like the STRICT of WIN32, we define a pointer that cannot be converted\r
4     from (void*) without cast */\r
5 typedef struct TagunzFile__ { int unused; } unzFile__; \r
6 typedef unzFile__ *unzFile;\r
7 #else\r
8 typedef void* unzFile;\r
9 #endif\r
10 \r
11 \r
12 /* tm_unz contain date/time info */\r
13 typedef struct tm_unz_s \r
14 {\r
15         unsigned int tm_sec;            /* seconds after the minute - [0,59] */\r
16         unsigned int tm_min;            /* minutes after the hour - [0,59] */\r
17         unsigned int tm_hour;           /* hours since midnight - [0,23] */\r
18         unsigned int tm_mday;           /* day of the month - [1,31] */\r
19         unsigned int tm_mon;            /* months since January - [0,11] */\r
20         unsigned int tm_year;           /* years - [1980..2044] */\r
21 } tm_unz;\r
22 \r
23 /* unz_global_info structure contain global data about the ZIPfile\r
24    These data comes from the end of central dir */\r
25 typedef struct unz_global_info_s\r
26 {\r
27         unsigned long number_entry;         /* total number of entries in the central dir on this disk */\r
28         unsigned long size_comment;         /* size of the global comment of the zipfile */\r
29 } unz_global_info;\r
30 \r
31 \r
32 /* unz_file_info contain information about a file in the zipfile */\r
33 typedef struct unz_file_info_s\r
34 {\r
35     unsigned long version;              /* version made by                 2 unsigned chars */\r
36     unsigned long version_needed;       /* version needed to extract       2 unsigned chars */\r
37     unsigned long flag;                 /* general purpose bit flag        2 unsigned chars */\r
38     unsigned long compression_method;   /* compression method              2 unsigned chars */\r
39     unsigned long dosDate;              /* last mod file date in Dos fmt   4 unsigned chars */\r
40     unsigned long crc;                  /* crc-32                          4 unsigned chars */\r
41     unsigned long compressed_size;      /* compressed size                 4 unsigned chars */ \r
42     unsigned long uncompressed_size;    /* uncompressed size               4 unsigned chars */ \r
43     unsigned long size_filename;        /* filename length                 2 unsigned chars */\r
44     unsigned long size_file_extra;      /* extra field length              2 unsigned chars */\r
45     unsigned long size_file_comment;    /* file comment length             2 unsigned chars */\r
46 \r
47     unsigned long disk_num_start;       /* disk number start               2 unsigned chars */\r
48     unsigned long internal_fa;          /* internal file attributes        2 unsigned chars */\r
49     unsigned long external_fa;          /* external file attributes        4 unsigned chars */\r
50 \r
51     tm_unz tmu_date;\r
52 } unz_file_info;\r
53 \r
54 /* unz_file_info_interntal contain internal info about a file in zipfile*/\r
55 typedef struct unz_file_info_internal_s\r
56 {\r
57     unsigned long offset_curfile;/* relative offset of static header 4 unsigned chars */\r
58 } unz_file_info_internal;\r
59 \r
60 typedef void* (*alloc_func) (void* opaque, unsigned int items, unsigned int size);\r
61 typedef void   (*free_func) (void* opaque, void* address);\r
62 \r
63 struct internal_state;\r
64 \r
65 typedef struct z_stream_s {\r
66     unsigned char    *next_in;  /* next input unsigned char */\r
67     unsigned int     avail_in;  /* number of unsigned chars available at next_in */\r
68     unsigned long    total_in;  /* total nb of input unsigned chars read so */\r
69 \r
70     unsigned char    *next_out; /* next output unsigned char should be put there */\r
71     unsigned int     avail_out; /* remaining free space at next_out */\r
72     unsigned long    total_out; /* total nb of unsigned chars output so */\r
73 \r
74     char     *msg;      /* last error message, NULL if no error */\r
75     struct internal_state *state; /* not visible by applications */\r
76 \r
77     alloc_func zalloc;  /* used to allocate the internal state */\r
78     free_func  zfree;   /* used to free the internal state */\r
79     unsigned char*     opaque;  /* private data object passed to zalloc and zfree */\r
80 \r
81     int     data_type;  /* best guess about the data type: ascii or binary */\r
82     unsigned long   adler;      /* adler32 value of the uncompressed data */\r
83     unsigned long   reserved;   /* reserved for future use */\r
84 } z_stream;\r
85 \r
86 typedef z_stream *z_streamp;\r
87 \r
88 \r
89 /* file_in_zip_read_info_s contain internal information about a file in zipfile,\r
90     when reading and decompress it */\r
91 typedef struct\r
92 {\r
93         char  *read_buffer;         /* internal buffer for compressed data */\r
94         z_stream stream;            /* zLib stream structure for inflate */\r
95 \r
96         unsigned long pos_in_zipfile;       /* position in unsigned char on the zipfile, for fseek*/\r
97         unsigned long stream_initialised;   /* flag set if stream structure is initialised*/\r
98 \r
99         unsigned long offset_local_extrafield;/* offset of the static extra field */\r
100         unsigned int  size_local_extrafield;/* size of the static extra field */\r
101         unsigned long pos_local_extrafield;   /* position in the static extra field in read*/\r
102 \r
103         unsigned long crc32;                /* crc32 of all data uncompressed */\r
104         unsigned long crc32_wait;           /* crc32 we must obtain after decompress all */\r
105         unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */\r
106         unsigned long rest_read_uncompressed;/*number of unsigned char to be obtained after decomp*/\r
107         FILE* file;                 /* io structore of the zipfile */\r
108         unsigned long compression_method;   /* compression method (0==store) */\r
109         unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/\r
110 } file_in_zip_read_info_s;\r
111 \r
112 \r
113 /* unz_s contain internal information about the zipfile\r
114 */\r
115 typedef struct\r
116 {\r
117         FILE* file;                 /* io structore of the zipfile */\r
118         unz_global_info gi;       /* public global information */\r
119         unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/\r
120         unsigned long num_file;             /* number of the current file in the zipfile*/\r
121         unsigned long pos_in_central_dir;   /* pos of the current file in the central dir*/\r
122         unsigned long current_file_ok;      /* flag about the usability of the current file*/\r
123         unsigned long central_pos;          /* position of the beginning of the central dir*/\r
124 \r
125         unsigned long size_central_dir;     /* size of the central directory  */\r
126         unsigned long offset_central_dir;   /* offset of start of central directory with\r
127                                                                    respect to the starting disk number */\r
128 \r
129         unz_file_info cur_file_info; /* public info about the current file in zip*/\r
130         unz_file_info_internal cur_file_info_internal; /* private info about it*/\r
131     file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current\r
132                                             file if we are decompressing it */\r
133 } unz_s;\r
134 \r
135 #define UNZ_OK                                  (0)\r
136 #define UNZ_END_OF_LIST_OF_FILE (-100)\r
137 #define UNZ_ERRNO               (Z_ERRNO)\r
138 #define UNZ_EOF                 (0)\r
139 #define UNZ_PARAMERROR                  (-102)\r
140 #define UNZ_BADZIPFILE                  (-103)\r
141 #define UNZ_INTERNALERROR               (-104)\r
142 #define UNZ_CRCERROR                    (-105)\r
143 \r
144 #define UNZ_CASESENSITIVE               1\r
145 #define UNZ_NOTCASESENSITIVE    2\r
146 #define UNZ_OSDEFAULTCASE               0\r
147 \r
148 extern int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity);\r
149 \r
150 /*\r
151    Compare two filename (fileName1,fileName2).\r
152    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)\r
153    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi\r
154                                                                 or strcasecmp)\r
155    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system\r
156         (like 1 on Unix, 2 on Windows)\r
157 */\r
158 \r
159 extern unzFile unzOpen (const char *path);\r
160 extern unzFile unzReOpen (const char* path, unzFile file);\r
161 \r
162 /*\r
163   Open a Zip file. path contain the full pathname (by example,\r
164      on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer\r
165          "zlib/zlib111.zip".\r
166          If the zipfile cannot be opened (file don't exist or in not valid), the\r
167            return value is NULL.\r
168      Else, the return value is a unzFile Handle, usable with other function\r
169            of this unzip package.\r
170 */\r
171 \r
172 extern int unzClose (unzFile file);\r
173 \r
174 /*\r
175   Close a ZipFile opened with unzipOpen.\r
176   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),\r
177     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.\r
178   return UNZ_OK if there is no problem. */\r
179 \r
180 extern int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info);\r
181 \r
182 /*\r
183   Write info about the ZipFile in the *pglobal_info structure.\r
184   No preparation of the structure is needed\r
185   return UNZ_OK if there is no problem. */\r
186 \r
187 \r
188 extern int unzGetGlobalComment (unzFile file, char *szComment, unsigned long uSizeBuf);\r
189 \r
190 /*\r
191   Get the global comment string of the ZipFile, in the szComment buffer.\r
192   uSizeBuf is the size of the szComment buffer.\r
193   return the number of unsigned char copied or an error code <0\r
194 */\r
195 \r
196 \r
197 /***************************************************************************/\r
198 /* Unzip package allow you browse the directory of the zipfile */\r
199 \r
200 extern int unzGoToFirstFile (unzFile file);\r
201 \r
202 /*\r
203   Set the current file of the zipfile to the first file.\r
204   return UNZ_OK if there is no problem\r
205 */\r
206 \r
207 extern int unzGoToNextFile (unzFile file);\r
208 \r
209 /*\r
210   Set the current file of the zipfile to the next file.\r
211   return UNZ_OK if there is no problem\r
212   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.\r
213 */\r
214 \r
215 extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity);\r
216 \r
217 /*\r
218   Try locate the file szFileName in the zipfile.\r
219   For the iCaseSensitivity signification, see unzStringFileNameCompare\r
220 \r
221   return value :\r
222   UNZ_OK if the file is found. It becomes the current file.\r
223   UNZ_END_OF_LIST_OF_FILE if the file is not found\r
224 */\r
225 \r
226 \r
227 extern int unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize);\r
228 \r
229 /*\r
230   Get Info about the current file\r
231   if pfile_info!=NULL, the *pfile_info structure will contain somes info about\r
232             the current file\r
233   if szFileName!=NULL, the filemane string will be copied in szFileName\r
234                         (fileNameBufferSize is the size of the buffer)\r
235   if extraField!=NULL, the extra field information will be copied in extraField\r
236                         (extraFieldBufferSize is the size of the buffer).\r
237                         This is the Central-header version of the extra field\r
238   if szComment!=NULL, the comment string of the file will be copied in szComment\r
239                         (commentBufferSize is the size of the buffer)\r
240 */\r
241 \r
242 /***************************************************************************/\r
243 /* for reading the content of the current zipfile, you can open it, read data\r
244    from it, and close it (you can close it before reading all the file)\r
245    */\r
246 \r
247 extern int unzOpenCurrentFile (unzFile file);\r
248 \r
249 /*\r
250   Open for reading data the current file in the zipfile.\r
251   If there is no error, the return value is UNZ_OK.\r
252 */\r
253 \r
254 extern int unzCloseCurrentFile (unzFile file);\r
255 \r
256 /*\r
257   Close the file in zip opened with unzOpenCurrentFile\r
258   Return UNZ_CRCERROR if all the file was read but the CRC is not good\r
259 */\r
260 \r
261                                                                                                 \r
262 extern int unzReadCurrentFile (unzFile file, void* buf, unsigned len);\r
263 \r
264 /*\r
265   Read unsigned chars from the current file (opened by unzOpenCurrentFile)\r
266   buf contain buffer where data must be copied\r
267   len the size of buf.\r
268 \r
269   return the number of unsigned char copied if somes unsigned chars are copied\r
270   return 0 if the end of file was reached\r
271   return <0 with error code if there is an error\r
272     (UNZ_ERRNO for IO error, or zLib error for uncompress error)\r
273 */\r
274 \r
275 extern long unztell(unzFile file);\r
276 \r
277 /*\r
278   Give the current position in uncompressed data\r
279 */\r
280 \r
281 extern int unzeof (unzFile file);\r
282 \r
283 /*\r
284   return 1 if the end of file was reached, 0 elsewhere \r
285 */\r
286 \r
287 extern int unzGetLocalExtrafield (unzFile file, void* buf, unsigned len);\r
288 \r
289 /*\r
290   Read extra field from the current file (opened by unzOpenCurrentFile)\r
291   This is the local-header version of the extra field (sometimes, there is\r
292     more info in the local-header version than in the central-header)\r
293 \r
294   if buf==NULL, it return the size of the local extra field\r
295 \r
296   if buf!=NULL, len is the size of the buffer, the extra header is copied in\r
297         buf.\r
298   the return value is the number of unsigned chars copied in buf, or (if <0) \r
299         the error code\r
300 */\r