CXXR (C++ R)
unzip.h
1 /*CXXR $Id: unzip.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /* unzip.h -- IO for uncompress .zip files using zlib
18  Version 1.1, February 14h, 2010
19  part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
20 
21  Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
22 
23  Modifications of Unzip for Zip64
24  Copyright (C) 2007-2008 Even Rouault
25 
26  Modifications for Zip64 support on both zip and unzip
27  Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
28 
29  For more info read MiniZip_info.txt
30 
31  ---------------------------------------------------------------------------------
32 
33  Condition of use and distribution are the same than zlib :
34 
35  This software is provided 'as-is', without any express or implied
36  warranty. In no event will the authors be held liable for any damages
37  arising from the use of this software.
38 
39  Permission is granted to anyone to use this software for any purpose,
40  including commercial applications, and to alter it and redistribute it
41  freely, subject to the following restrictions:
42 
43  1. The origin of this software must not be misrepresented; you must not
44  claim that you wrote the original software. If you use this software
45  in a product, an acknowledgment in the product documentation would be
46  appreciated but is not required.
47  2. Altered source versions must be plainly marked as such, and must not be
48  misrepresented as being the original software.
49  3. This notice may not be removed or altered from any source distribution.
50 
51  ---------------------------------------------------------------------------------
52 
53  Changes
54 
55  See header of unzip64.c
56 
57 */
58 
59 #ifndef _unz64_H
60 #define _unz64_H
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #ifndef _ZLIB_H
67 #include "zlib.h"
68 #endif
69 
70 /* merged from ioapi.h */
71 #include <stdint.h>
72 typedef uint64_t ZPOS64_T;
73 
74 #define ZLIB_FILEFUNC_SEEK_CUR (1)
75 #define ZLIB_FILEFUNC_SEEK_END (2)
76 #define ZLIB_FILEFUNC_SEEK_SET (0)
77 
78 #define ZLIB_FILEFUNC_MODE_READ (1)
79 #define ZLIB_FILEFUNC_MODE_WRITE (2)
80 #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
81 
82 #define ZLIB_FILEFUNC_MODE_EXISTING (4)
83 #define ZLIB_FILEFUNC_MODE_CREATE (8)
84 
85 static voidpf fopen_func(const void* filename, int mode);
86 static ZPOS64_T ftell_func(voidpf stream);
87 static int fseek_func(voidpf stream, ZPOS64_T offset, int origin);
88 static size_t fread_func(voidpf stream, void* buf, size_t size);
89 static int fclose_func(voidpf stream);
90 static int ferror_func(voidpf stream);
91 /* end of merge */
92 
93 #ifdef HAVE_BZIP2
94 #include "bzlib.h"
95 #endif
96 
97 #define Z_BZIP2ED 12
98 
99 typedef voidp unzFile;
100 
101 #define UNZ_OK (0)
102 #define UNZ_END_OF_LIST_OF_FILE (-100)
103 #define UNZ_ERRNO (Z_ERRNO)
104 #define UNZ_EOF (0)
105 #define UNZ_PARAMERROR (-102)
106 #define UNZ_BADZIPFILE (-103)
107 #define UNZ_INTERNALERROR (-104)
108 #define UNZ_CRCERROR (-105)
109 
110 /* tm_unz contain date/time info */
111 typedef struct tm_unz_s
112 {
113  uInt tm_sec; /* seconds after the minute - [0,59] */
114  uInt tm_min; /* minutes after the hour - [0,59] */
115  uInt tm_hour; /* hours since midnight - [0,23] */
116  uInt tm_mday; /* day of the month - [1,31] */
117  uInt tm_mon; /* months since January - [0,11] */
118  uInt tm_year; /* years - [1980..2044] */
119 } tm_unz;
120 
121 typedef struct unz_global_info64_s
122 {
123  ZPOS64_T number_entry; /* total number of entries in
124  the central dir on this disk */
125  uLong size_comment; /* size of the global comment of the zipfile */
126 } unz_global_info64;
127 
128 
129 typedef struct unz_file_info64_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  ZPOS64_T compressed_size; /* compressed size 8 bytes */
138  ZPOS64_T uncompressed_size; /* uncompressed size 8 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_info64;
149 
150 
151 int unzStringFileNameCompare OF ((const char* fileName1,
152  const char* fileName2,
153  int iCaseSensitivity));
154 
155 unzFile unzOpen64 OF((const void *path));
156 
157 
158 int unzClose OF((unzFile file));
159 
160 static int unzGetGlobalInfo64 OF((unzFile file,
161  unz_global_info64 *pglobal_info));
162 
163 
164 /***************************************************************************/
165 /* Unzip package allow you browse the directory of the zipfile */
166 
167 int unzGoToFirstFile OF((unzFile file));
168 /*
169  Set the current file of the zipfile to the first file.
170  return UNZ_OK if there is no problem
171 */
172 
173 int unzGoToNextFile OF((unzFile file));
174 /*
175  Set the current file of the zipfile to the next file.
176  return UNZ_OK if there is no problem
177  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
178 */
179 
180 int unzLocateFile OF((unzFile file,
181  const char *szFileName,
182  int iCaseSensitivity));
183 /*
184  Try locate the file szFileName in the zipfile.
185  For the iCaseSensitivity signification, see unzStringFileNameCompare
186 
187  return value :
188  UNZ_OK if the file is found. It becomes the current file.
189  UNZ_END_OF_LIST_OF_FILE if the file is not found
190 */
191 
192 
193 
194 /* ****************************************** */
195 
196 int unzGetCurrentFileInfo64 OF((unzFile file,
197  unz_file_info64 *pfile_info,
198  char *szFileName,
199  uLong fileNameBufferSize,
200  void *extraField,
201  uLong extraFieldBufferSize,
202  char *szComment,
203  uLong commentBufferSize));
204 /*
205  Get Info about the current file
206  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
207  the current file
208  if szFileName!=NULL, the filemane string will be copied in szFileName
209  (fileNameBufferSize is the size of the buffer)
210  if extraField!=NULL, the extra field information will be copied in extraField
211  (extraFieldBufferSize is the size of the buffer).
212  This is the Central-header version of the extra field
213  if szComment!=NULL, the comment string of the file will be copied in szComment
214  (commentBufferSize is the size of the buffer)
215 */
216 
217 
218 /***************************************************************************/
219 /* for reading the content of the current zipfile, you can open it, read data
220  from it, and close it (you can close it before reading all the file)
221  */
222 
223 int unzOpenCurrentFile OF((unzFile file));
224 /*
225  Open for reading data the current file in the zipfile.
226  If there is no error, the return value is UNZ_OK.
227 */
228 
229 int unzCloseCurrentFile OF((unzFile file));
230 /*
231  Close the file in zip opened with unzOpenCurrentFile
232  Return UNZ_CRCERROR if all the file was read but the CRC is not good
233 */
234 
235 int unzReadCurrentFile OF((unzFile file,
236  voidp buf,
237  unsigned len));
238 /*
239  Read bytes from the current file (opened by unzOpenCurrentFile)
240  buf contain buffer where data must be copied
241  len the size of buf.
242 
243  return the number of byte copied if somes bytes are copied
244  return 0 if the end of file was reached
245  return <0 with error code if there is an error
246  (UNZ_ERRNO for IO error, or zLib error for uncompress error)
247 */
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* _unz64_H */