diff options
Diffstat (limited to 'contrib/minizip/ioapi.c')
-rw-r--r-- | contrib/minizip/ioapi.c | 220 |
1 files changed, 139 insertions, 81 deletions
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c index f1bee23..36ed0e0 100644 --- a/contrib/minizip/ioapi.c +++ b/contrib/minizip/ioapi.c | |||
@@ -1,74 +1,104 @@ | |||
1 | /* ioapi.c -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip |
2 | files using zlib + zip or unzip API | 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) |
3 | 3 | ||
4 | Version 1.01e, February 12th, 2005 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
5 | |||
6 | Copyright (C) 1998-2005 Gilles Vollant | ||
7 | */ | ||
8 | |||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | #include "zlib.h" | ||
14 | #include "ioapi.h" | ||
15 | 5 | ||
6 | Modifications for Zip64 support | ||
7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | ||
16 | 8 | ||
9 | For more info read MiniZip_info.txt | ||
17 | 10 | ||
18 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ | 11 | */ |
19 | 12 | ||
20 | #ifndef SEEK_CUR | 13 | #if (defined(_WIN32)) |
21 | #define SEEK_CUR 1 | 14 | #define _CRT_SECURE_NO_WARNINGS |
22 | #endif | 15 | #endif |
23 | 16 | ||
24 | #ifndef SEEK_END | 17 | #include "ioapi.h" |
25 | #define SEEK_END 2 | ||
26 | #endif | ||
27 | 18 | ||
28 | #ifndef SEEK_SET | 19 | voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) |
29 | #define SEEK_SET 0 | 20 | { |
30 | #endif | 21 | if (pfilefunc->zfile_func64.zopen64_file != NULL) |
22 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); | ||
23 | else | ||
24 | { | ||
25 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); | ||
26 | } | ||
27 | } | ||
31 | 28 | ||
32 | voidpf ZCALLBACK fopen_file_func OF(( | 29 | long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) |
33 | voidpf opaque, | 30 | { |
34 | const char* filename, | 31 | if (pfilefunc->zfile_func64.zseek64_file != NULL) |
35 | int mode)); | 32 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); |
33 | else | ||
34 | { | ||
35 | uLong offsetTruncated = (uLong)offset; | ||
36 | if (offsetTruncated != offset) | ||
37 | return -1; | ||
38 | else | ||
39 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); | ||
40 | } | ||
41 | } | ||
36 | 42 | ||
37 | uLong ZCALLBACK fread_file_func OF(( | 43 | ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) |
38 | voidpf opaque, | 44 | { |
39 | voidpf stream, | 45 | if (pfilefunc->zfile_func64.zseek64_file != NULL) |
40 | void* buf, | 46 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); |
41 | uLong size)); | 47 | else |
48 | { | ||
49 | uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); | ||
50 | if ((tell_uLong) == ((uLong)-1)) | ||
51 | return (ZPOS64_T)-1; | ||
52 | else | ||
53 | return tell_uLong; | ||
54 | } | ||
55 | } | ||
42 | 56 | ||
43 | uLong ZCALLBACK fwrite_file_func OF(( | 57 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) |
44 | voidpf opaque, | 58 | { |
45 | voidpf stream, | 59 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; |
46 | const void* buf, | 60 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; |
47 | uLong size)); | 61 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; |
62 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; | ||
63 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; | ||
64 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; | ||
65 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; | ||
66 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; | ||
67 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; | ||
68 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; | ||
69 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; | ||
70 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; | ||
71 | } | ||
48 | 72 | ||
49 | long ZCALLBACK ftell_file_func OF(( | ||
50 | voidpf opaque, | ||
51 | voidpf stream)); | ||
52 | 73 | ||
53 | long ZCALLBACK fseek_file_func OF(( | ||
54 | voidpf opaque, | ||
55 | voidpf stream, | ||
56 | uLong offset, | ||
57 | int origin)); | ||
58 | 74 | ||
59 | int ZCALLBACK fclose_file_func OF(( | 75 | static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); |
60 | voidpf opaque, | 76 | static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); |
61 | voidpf stream)); | 77 | static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); |
78 | static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); | ||
79 | static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | ||
80 | static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); | ||
81 | static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); | ||
62 | 82 | ||
63 | int ZCALLBACK ferror_file_func OF(( | 83 | static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) |
64 | voidpf opaque, | 84 | { |
65 | voidpf stream)); | 85 | FILE* file = NULL; |
86 | const char* mode_fopen = NULL; | ||
87 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | ||
88 | mode_fopen = "rb"; | ||
89 | else | ||
90 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | ||
91 | mode_fopen = "r+b"; | ||
92 | else | ||
93 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) | ||
94 | mode_fopen = "wb"; | ||
66 | 95 | ||
96 | if ((filename!=NULL) && (mode_fopen != NULL)) | ||
97 | file = fopen(filename, mode_fopen); | ||
98 | return file; | ||
99 | } | ||
67 | 100 | ||
68 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) | 101 | static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) |
69 | voidpf opaque; | ||
70 | const char* filename; | ||
71 | int mode; | ||
72 | { | 102 | { |
73 | FILE* file = NULL; | 103 | FILE* file = NULL; |
74 | const char* mode_fopen = NULL; | 104 | const char* mode_fopen = NULL; |
@@ -82,48 +112,41 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) | |||
82 | mode_fopen = "wb"; | 112 | mode_fopen = "wb"; |
83 | 113 | ||
84 | if ((filename!=NULL) && (mode_fopen != NULL)) | 114 | if ((filename!=NULL) && (mode_fopen != NULL)) |
85 | file = fopen(filename, mode_fopen); | 115 | file = fopen64((const char*)filename, mode_fopen); |
86 | return file; | 116 | return file; |
87 | } | 117 | } |
88 | 118 | ||
89 | 119 | ||
90 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) | 120 | static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) |
91 | voidpf opaque; | ||
92 | voidpf stream; | ||
93 | void* buf; | ||
94 | uLong size; | ||
95 | { | 121 | { |
96 | uLong ret; | 122 | uLong ret; |
97 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | 123 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); |
98 | return ret; | 124 | return ret; |
99 | } | 125 | } |
100 | 126 | ||
101 | 127 | static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) | |
102 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) | ||
103 | voidpf opaque; | ||
104 | voidpf stream; | ||
105 | const void* buf; | ||
106 | uLong size; | ||
107 | { | 128 | { |
108 | uLong ret; | 129 | uLong ret; |
109 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | 130 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); |
110 | return ret; | 131 | return ret; |
111 | } | 132 | } |
112 | 133 | ||
113 | long ZCALLBACK ftell_file_func (opaque, stream) | 134 | static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) |
114 | voidpf opaque; | ||
115 | voidpf stream; | ||
116 | { | 135 | { |
117 | long ret; | 136 | long ret; |
118 | ret = ftell((FILE *)stream); | 137 | ret = ftell((FILE *)stream); |
119 | return ret; | 138 | return ret; |
120 | } | 139 | } |
121 | 140 | ||
122 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) | 141 | |
123 | voidpf opaque; | 142 | static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) |
124 | voidpf stream; | 143 | { |
125 | uLong offset; | 144 | ZPOS64_T ret; |
126 | int origin; | 145 | ret = ftello64((FILE *)stream); |
146 | return ret; | ||
147 | } | ||
148 | |||
149 | static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) | ||
127 | { | 150 | { |
128 | int fseek_origin=0; | 151 | int fseek_origin=0; |
129 | long ret; | 152 | long ret; |
@@ -141,22 +164,45 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) | |||
141 | default: return -1; | 164 | default: return -1; |
142 | } | 165 | } |
143 | ret = 0; | 166 | ret = 0; |
144 | fseek((FILE *)stream, offset, fseek_origin); | 167 | if (fseek((FILE *)stream, offset, fseek_origin) != 0) |
168 | ret = -1; | ||
145 | return ret; | 169 | return ret; |
146 | } | 170 | } |
147 | 171 | ||
148 | int ZCALLBACK fclose_file_func (opaque, stream) | 172 | static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) |
149 | voidpf opaque; | 173 | { |
150 | voidpf stream; | 174 | int fseek_origin=0; |
175 | long ret; | ||
176 | switch (origin) | ||
177 | { | ||
178 | case ZLIB_FILEFUNC_SEEK_CUR : | ||
179 | fseek_origin = SEEK_CUR; | ||
180 | break; | ||
181 | case ZLIB_FILEFUNC_SEEK_END : | ||
182 | fseek_origin = SEEK_END; | ||
183 | break; | ||
184 | case ZLIB_FILEFUNC_SEEK_SET : | ||
185 | fseek_origin = SEEK_SET; | ||
186 | break; | ||
187 | default: return -1; | ||
188 | } | ||
189 | ret = 0; | ||
190 | |||
191 | if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) | ||
192 | ret = -1; | ||
193 | |||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | |||
198 | static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) | ||
151 | { | 199 | { |
152 | int ret; | 200 | int ret; |
153 | ret = fclose((FILE *)stream); | 201 | ret = fclose((FILE *)stream); |
154 | return ret; | 202 | return ret; |
155 | } | 203 | } |
156 | 204 | ||
157 | int ZCALLBACK ferror_file_func (opaque, stream) | 205 | static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) |
158 | voidpf opaque; | ||
159 | voidpf stream; | ||
160 | { | 206 | { |
161 | int ret; | 207 | int ret; |
162 | ret = ferror((FILE *)stream); | 208 | ret = ferror((FILE *)stream); |
@@ -175,3 +221,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def) | |||
175 | pzlib_filefunc_def->zerror_file = ferror_file_func; | 221 | pzlib_filefunc_def->zerror_file = ferror_file_func; |
176 | pzlib_filefunc_def->opaque = NULL; | 222 | pzlib_filefunc_def->opaque = NULL; |
177 | } | 223 | } |
224 | |||
225 | void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) | ||
226 | { | ||
227 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; | ||
228 | pzlib_filefunc_def->zread_file = fread_file_func; | ||
229 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; | ||
230 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; | ||
231 | pzlib_filefunc_def->zseek64_file = fseek64_file_func; | ||
232 | pzlib_filefunc_def->zclose_file = fclose_file_func; | ||
233 | pzlib_filefunc_def->zerror_file = ferror_file_func; | ||
234 | pzlib_filefunc_def->opaque = NULL; | ||
235 | } | ||