annotate src/common/unzip.h @ 265:7de2c855392c

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