Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: third_party/zlib/contrib/minizip/ioapi.c

Issue 8806004: Update zlib to 1.2.5. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/zlib/contrib/minizip/ioapi.h ('k') | third_party/zlib/contrib/minizip/iowin32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5
6 Copyright (C) 1998-2005 Gilles Vollant 6 Modifications for Zip64 support
7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8
9 For more info read MiniZip_info.txt
10
7 */ 11 */
8 12
9 #include <stdio.h> 13 #if (defined(_WIN32))
10 #include <stdlib.h> 14 #define _CRT_SECURE_NO_WARNINGS
11 #include <string.h>
12
13 #if defined(USE_SYSTEM_ZLIB)
14 #include <zlib.h>
15 #else
16 #include "third_party/zlib/zlib.h"
17 #endif 15 #endif
18 16
19 #include "ioapi.h" 17 #include "ioapi.h"
20 18
21 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 19 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename ,int mode)
20 {
21 if (pfilefunc->zfile_func64.zopen64_file != NULL)
22 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func6 4.opaque,filename,mode);
23 else
24 {
25 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(cons t char*)filename,mode);
26 }
27 }
22 28
23 #ifndef SEEK_CUR 29 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZP OS64_T offset, int origin)
24 #define SEEK_CUR 1 30 {
25 #endif 31 if (pfilefunc->zfile_func64.zseek64_file != NULL)
32 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func6 4.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,f ilestream,offsetTruncated,origin);
40 }
41 }
26 42
27 #ifndef SEEK_END 43 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream )
28 #define SEEK_END 2 44 {
29 #endif 45 if (pfilefunc->zfile_func64.zseek64_file != NULL)
46 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func6 4.opaque,filestream);
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 }
30 56
31 #ifndef SEEK_SET 57 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef unc64_32,const zlib_filefunc_def* p_filefunc32)
32 #define SEEK_SET 0 58 {
33 #endif 59 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
34 60 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
35 voidpf ZCALLBACK fopen_file_func OF(( 61 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
36 voidpf opaque, 62 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
37 const char* filename, 63 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
38 int mode)); 64 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
39 65 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
40 uLong ZCALLBACK fread_file_func OF(( 66 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
41 voidpf opaque, 67 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
42 voidpf stream, 68 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
43 void* buf, 69 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
44 uLong size)); 70 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
45 71 }
46 uLong ZCALLBACK fwrite_file_func OF((
47 voidpf opaque,
48 voidpf stream,
49 const void* buf,
50 uLong size));
51
52 long ZCALLBACK ftell_file_func OF((
53 voidpf opaque,
54 voidpf stream));
55
56 long ZCALLBACK fseek_file_func OF((
57 voidpf opaque,
58 voidpf stream,
59 uLong offset,
60 int origin));
61
62 int ZCALLBACK fclose_file_func OF((
63 voidpf opaque,
64 voidpf stream));
65
66 int ZCALLBACK ferror_file_func OF((
67 voidpf opaque,
68 voidpf stream));
69 72
70 73
71 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 74
72 voidpf opaque; 75 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename , int mode));
73 const char* filename; 76 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
74 int mode; 77 static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, cons t 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, ZPO S64_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));
82
83 static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in t mode)
75 { 84 {
76 FILE* file = NULL; 85 FILE* file = NULL;
77 const char* mode_fopen = 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";
95
96 if ((filename!=NULL) && (mode_fopen != NULL))
97 file = fopen(filename, mode_fopen);
98 return file;
99 }
100
101 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
102 {
103 FILE* file = NULL;
104 const char* mode_fopen = NULL;
78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 105 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
79 mode_fopen = "rb"; 106 mode_fopen = "rb";
80 else 107 else
81 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 108 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
82 mode_fopen = "r+b"; 109 mode_fopen = "r+b";
83 else 110 else
84 if (mode & ZLIB_FILEFUNC_MODE_CREATE) 111 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
85 mode_fopen = "wb"; 112 mode_fopen = "wb";
86 113
87 if ((filename!=NULL) && (mode_fopen != NULL)) 114 if ((filename!=NULL) && (mode_fopen != NULL))
88 file = fopen(filename, mode_fopen); 115 file = fopen64((const char*)filename, mode_fopen);
89 return file; 116 return file;
90 } 117 }
91 118
92 119
93 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 120 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
94 voidpf opaque;
95 voidpf stream;
96 void* buf;
97 uLong size;
98 { 121 {
99 uLong ret; 122 uLong ret;
100 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 123 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
101 return ret; 124 return ret;
102 } 125 }
103 126
104 127 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const voi d* buf, uLong size)
105 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
106 voidpf opaque;
107 voidpf stream;
108 const void* buf;
109 uLong size;
110 { 128 {
111 uLong ret; 129 uLong ret;
112 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 130 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
113 return ret; 131 return ret;
114 } 132 }
115 133
116 long ZCALLBACK ftell_file_func (opaque, stream) 134 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
117 voidpf opaque;
118 voidpf stream;
119 { 135 {
120 long ret; 136 long ret;
121 ret = ftell((FILE *)stream); 137 ret = ftell((FILE *)stream);
122 return ret; 138 return ret;
123 } 139 }
124 140
125 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 141
126 voidpf opaque; 142 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
127 voidpf stream; 143 {
128 uLong offset; 144 ZPOS64_T ret;
129 int origin; 145 ret = ftello64((FILE *)stream);
146 return ret;
147 }
148
149 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs et, int origin)
130 { 150 {
131 int fseek_origin=0; 151 int fseek_origin=0;
132 long ret; 152 long ret;
133 switch (origin) 153 switch (origin)
134 { 154 {
135 case ZLIB_FILEFUNC_SEEK_CUR : 155 case ZLIB_FILEFUNC_SEEK_CUR :
136 fseek_origin = SEEK_CUR; 156 fseek_origin = SEEK_CUR;
137 break; 157 break;
138 case ZLIB_FILEFUNC_SEEK_END : 158 case ZLIB_FILEFUNC_SEEK_END :
139 fseek_origin = SEEK_END; 159 fseek_origin = SEEK_END;
140 break; 160 break;
141 case ZLIB_FILEFUNC_SEEK_SET : 161 case ZLIB_FILEFUNC_SEEK_SET :
142 fseek_origin = SEEK_SET; 162 fseek_origin = SEEK_SET;
143 break; 163 break;
144 default: return -1; 164 default: return -1;
145 } 165 }
146 ret = 0; 166 ret = 0;
147 fseek((FILE *)stream, offset, fseek_origin); 167 if (fseek((FILE *)stream, offset, fseek_origin) != 0)
168 ret = -1;
148 return ret; 169 return ret;
149 } 170 }
150 171
151 int ZCALLBACK fclose_file_func (opaque, stream) 172 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
152 voidpf opaque; 173 {
153 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)
154 { 199 {
155 int ret; 200 int ret;
156 ret = fclose((FILE *)stream); 201 ret = fclose((FILE *)stream);
157 return ret; 202 return ret;
158 } 203 }
159 204
160 int ZCALLBACK ferror_file_func (opaque, stream) 205 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
161 voidpf opaque;
162 voidpf stream;
163 { 206 {
164 int ret; 207 int ret;
165 ret = ferror((FILE *)stream); 208 ret = ferror((FILE *)stream);
166 return ret; 209 return ret;
167 } 210 }
168 211
169 void fill_fopen_filefunc (pzlib_filefunc_def) 212 void fill_fopen_filefunc (pzlib_filefunc_def)
170 zlib_filefunc_def* pzlib_filefunc_def; 213 zlib_filefunc_def* pzlib_filefunc_def;
171 { 214 {
172 pzlib_filefunc_def->zopen_file = fopen_file_func; 215 pzlib_filefunc_def->zopen_file = fopen_file_func;
173 pzlib_filefunc_def->zread_file = fread_file_func; 216 pzlib_filefunc_def->zread_file = fread_file_func;
174 pzlib_filefunc_def->zwrite_file = fwrite_file_func; 217 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
175 pzlib_filefunc_def->ztell_file = ftell_file_func; 218 pzlib_filefunc_def->ztell_file = ftell_file_func;
176 pzlib_filefunc_def->zseek_file = fseek_file_func; 219 pzlib_filefunc_def->zseek_file = fseek_file_func;
177 pzlib_filefunc_def->zclose_file = fclose_file_func; 220 pzlib_filefunc_def->zclose_file = fclose_file_func;
178 pzlib_filefunc_def->zerror_file = ferror_file_func; 221 pzlib_filefunc_def->zerror_file = ferror_file_func;
179 pzlib_filefunc_def->opaque = NULL; 222 pzlib_filefunc_def->opaque = NULL;
180 } 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 }
OLDNEW
« no previous file with comments | « third_party/zlib/contrib/minizip/ioapi.h ('k') | third_party/zlib/contrib/minizip/iowin32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698