14 #define _CRT_SECURE_NO_WARNINGS
21 if (pfilefunc->zfile_func64.zopen64_file != NULL)
22 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
25 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(
const char*)filename,mode);
31 if (pfilefunc->zfile_func64.zseek64_file != NULL)
32 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
35 uLong offsetTruncated = (uLong)offset;
36 if (offsetTruncated != offset)
39 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
45 if (pfilefunc->zfile_func64.zseek64_file != NULL)
46 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
49 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
50 if ((tell_uLong) == ((uLong)-1))
59 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
60 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
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;
75 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque,
const char* filename,
int mode));
76 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream,
void* buf, uLong size));
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));
83 static voidpf ZCALLBACK fopen_file_func (voidpf opaque,
const char* filename,
int mode)
86 const char* mode_fopen = NULL;
87 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
90 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
93 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
96 if ((filename!=NULL) && (mode_fopen != NULL))
97 file = fopen(filename, mode_fopen);
101 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque,
const void* filename,
int mode)
104 const char* mode_fopen = NULL;
105 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
108 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
111 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
114 if ((filename!=NULL) && (mode_fopen != NULL))
115 file = fopen64((
const char*)filename, mode_fopen);
120 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream,
void* buf, uLong size)
123 ret = (uLong)fread(buf, 1, (
size_t)size, (FILE *)stream);
127 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream,
const void* buf, uLong size)
130 ret = (uLong)fwrite(buf, 1, (
size_t)size, (FILE *)stream);
134 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
137 ret = ftell((FILE *)stream);
142 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
145 ret = ftello64((FILE *)stream);
149 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset,
int origin)
155 case ZLIB_FILEFUNC_SEEK_CUR :
156 fseek_origin = SEEK_CUR;
158 case ZLIB_FILEFUNC_SEEK_END :
159 fseek_origin = SEEK_END;
161 case ZLIB_FILEFUNC_SEEK_SET :
162 fseek_origin = SEEK_SET;
167 if (fseek((FILE *)stream, offset, fseek_origin) != 0)
172 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset,
int origin)
178 case ZLIB_FILEFUNC_SEEK_CUR :
179 fseek_origin = SEEK_CUR;
181 case ZLIB_FILEFUNC_SEEK_END :
182 fseek_origin = SEEK_END;
184 case ZLIB_FILEFUNC_SEEK_SET :
185 fseek_origin = SEEK_SET;
191 if(fseeko64((FILE *)stream, offset, fseek_origin) != 0)
198 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
201 ret = fclose((FILE *)stream);
205 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
208 ret = ferror((FILE *)stream);
212 void fill_fopen_filefunc (pzlib_filefunc_def)
215 pzlib_filefunc_def->zopen_file = fopen_file_func;
216 pzlib_filefunc_def->zread_file = fread_file_func;
217 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
218 pzlib_filefunc_def->ztell_file = ftell_file_func;
219 pzlib_filefunc_def->zseek_file = fseek_file_func;
220 pzlib_filefunc_def->zclose_file = fclose_file_func;
221 pzlib_filefunc_def->zerror_file = ferror_file_func;
222 pzlib_filefunc_def->opaque = NULL;
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;