20 #define _CRT_SECURE_NO_WARNINGS 24 #if defined(__APPLE__) || defined(ANDROID) 26 #define FOPEN_FUNC(filename, mode) fopen(filename, mode) 27 #define FTELLO_FUNC(stream) ftello(stream) 28 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 30 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 31 #define FTELLO_FUNC(stream) ftello64(stream) 32 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 36 #include "minizip/ioapi.h" 40 if (pfilefunc->zfile_func64.zopen64_file != NULL)
42 return (*(pfilefunc->zfile_func64.zopen64_file))(pfilefunc->zfile_func64.opaque,filename,mode);
46 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(
const char*)filename,mode);
52 if (pfilefunc->zfile_func64.zseek64_file != NULL)
54 return (*(pfilefunc->zfile_func64.zseek64_file))(pfilefunc->zfile_func64.opaque,filestream,offset,origin);
58 uLong offsetTruncated = (uLong)offset;
59 if (offsetTruncated != offset)
65 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
72 if (pfilefunc->zfile_func64.zseek64_file != NULL)
74 return (*(pfilefunc->zfile_func64.ztell64_file))(pfilefunc->zfile_func64.opaque,filestream);
78 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
79 if ((tell_uLong) == ((uLong)-1))
93 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
94 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
95 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
96 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
97 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
98 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
99 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
100 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
101 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
102 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
103 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
104 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
109 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque,
const char* filename,
int mode));
110 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream,
void* buf, uLong size));
111 static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream,
const void* buf,uLong size));
112 static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
113 static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset,
int origin));
114 static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
115 static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
117 static voidpf ZCALLBACK fopen_file_func (voidpf opaque,
const char* filename,
int mode)
120 const char* mode_fopen = NULL;
121 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
126 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
131 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
136 if ((filename!=NULL) && (mode_fopen != NULL))
138 file = fopen(filename, mode_fopen);
143 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque,
const void* filename,
int mode)
146 const char* mode_fopen = NULL;
147 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
152 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
157 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
162 if ((filename!=NULL) && (mode_fopen != NULL))
164 file = FOPEN_FUNC((
const char*)filename, mode_fopen);
170 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream,
void* buf, uLong size)
173 ret = (uLong)fread(buf, 1, (
size_t)size, (
FILE *)stream);
177 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream,
const void* buf, uLong size)
180 ret = (uLong)fwrite(buf, 1, (
size_t)size, (
FILE *)stream);
184 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
187 ret = ftell((FILE *)stream);
192 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
195 ret = FTELLO_FUNC((FILE *)stream);
199 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset,
int origin)
201 int fseek_origin = 0;
205 case ZLIB_FILEFUNC_SEEK_CUR:
206 fseek_origin = SEEK_CUR;
208 case ZLIB_FILEFUNC_SEEK_END:
209 fseek_origin = SEEK_END;
211 case ZLIB_FILEFUNC_SEEK_SET:
212 fseek_origin = SEEK_SET;
217 if (fseek((FILE *)stream, offset, fseek_origin) != 0)
224 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset,
int origin)
226 int fseek_origin = 0;
230 case ZLIB_FILEFUNC_SEEK_CUR:
231 fseek_origin = SEEK_CUR;
233 case ZLIB_FILEFUNC_SEEK_END:
234 fseek_origin = SEEK_END;
236 case ZLIB_FILEFUNC_SEEK_SET:
237 fseek_origin = SEEK_SET;
243 if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
252 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
255 ret = fclose((FILE *)stream);
259 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
262 ret = ferror((FILE *)stream);
266 void fill_fopen_filefunc (pzlib_filefunc_def)
269 pzlib_filefunc_def->zopen_file = fopen_file_func;
270 pzlib_filefunc_def->zread_file = fread_file_func;
271 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
272 pzlib_filefunc_def->ztell_file = ftell_file_func;
273 pzlib_filefunc_def->zseek_file = fseek_file_func;
274 pzlib_filefunc_def->zclose_file = fclose_file_func;
275 pzlib_filefunc_def->zerror_file = ferror_file_func;
276 pzlib_filefunc_def->opaque = NULL;
281 pzlib_filefunc_def->zopen64_file = fopen64_file_func;
282 pzlib_filefunc_def->zread_file = fread_file_func;
283 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
284 pzlib_filefunc_def->ztell64_file = ftell64_file_func;
285 pzlib_filefunc_def->zseek64_file = fseek64_file_func;
286 pzlib_filefunc_def->zclose_file = fclose_file_func;
287 pzlib_filefunc_def->zerror_file = ferror_file_func;
288 pzlib_filefunc_def->opaque = NULL;