1 /* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
4 Version 1.01e, February 12th, 2005
6 Copyright (C) 1998-2005 Gilles Vollant
16 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
30 voidpf ZCALLBACK fopen_file_func OF((
35 uLong ZCALLBACK fread_file_func OF((
41 uLong ZCALLBACK fwrite_file_func OF((
47 long ZCALLBACK ftell_file_func OF((
51 long ZCALLBACK fseek_file_func OF((
57 int ZCALLBACK fclose_file_func OF((
61 int ZCALLBACK ferror_file_func OF((
66 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
72 const char* mode_fopen = NULL;
73 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
76 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
79 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
82 if ((filename!=NULL) && (mode_fopen != NULL))
83 file = fopen(filename, mode_fopen);
88 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
95 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
100 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
107 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
111 long ZCALLBACK ftell_file_func (opaque, stream)
116 ret = ftell((FILE *)stream);
120 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
130 case ZLIB_FILEFUNC_SEEK_CUR :
131 fseek_origin = SEEK_CUR;
133 case ZLIB_FILEFUNC_SEEK_END :
134 fseek_origin = SEEK_END;
136 case ZLIB_FILEFUNC_SEEK_SET :
137 fseek_origin = SEEK_SET;
142 fseek((FILE *)stream, offset, fseek_origin);
146 int ZCALLBACK fclose_file_func (opaque, stream)
151 ret = fclose((FILE *)stream);
155 int ZCALLBACK ferror_file_func (opaque, stream)
160 ret = ferror((FILE *)stream);
164 void fill_fopen_filefunc (pzlib_filefunc_def)
165 zlib_filefunc_def* pzlib_filefunc_def;
167 pzlib_filefunc_def->zopen_file = fopen_file_func;
168 pzlib_filefunc_def->zread_file = fread_file_func;
169 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
170 pzlib_filefunc_def->ztell_file = ftell_file_func;
171 pzlib_filefunc_def->zseek_file = fseek_file_func;
172 pzlib_filefunc_def->zclose_file = fclose_file_func;
173 pzlib_filefunc_def->zerror_file = ferror_file_func;
174 pzlib_filefunc_def->opaque = NULL;