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
15 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
29 voidpf ZCALLBACK fopen_file_func OF((
34 uLong ZCALLBACK fread_file_func OF((
40 uLong ZCALLBACK fwrite_file_func OF((
46 long ZCALLBACK ftell_file_func OF((
50 long ZCALLBACK fseek_file_func OF((
56 int ZCALLBACK fclose_file_func OF((
60 int ZCALLBACK ferror_file_func OF((
65 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
71 const char* mode_fopen = NULL;
72 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
75 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
78 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
81 if ((filename!=NULL) && (mode_fopen != NULL))
82 file = fopen(filename, mode_fopen);
87 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
94 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
99 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
106 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
110 long ZCALLBACK ftell_file_func (opaque, stream)
115 ret = ftell((FILE *)stream);
119 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
129 case ZLIB_FILEFUNC_SEEK_CUR :
130 fseek_origin = SEEK_CUR;
132 case ZLIB_FILEFUNC_SEEK_END :
133 fseek_origin = SEEK_END;
135 case ZLIB_FILEFUNC_SEEK_SET :
136 fseek_origin = SEEK_SET;
141 fseek((FILE *)stream, offset, fseek_origin);
145 int ZCALLBACK fclose_file_func (opaque, stream)
150 ret = fclose((FILE *)stream);
154 int ZCALLBACK ferror_file_func (opaque, stream)
159 ret = ferror((FILE *)stream);
163 void fill_fopen_filefunc (pzlib_filefunc_def)
164 zlib_filefunc_def* pzlib_filefunc_def;
166 pzlib_filefunc_def->zopen_file = fopen_file_func;
167 pzlib_filefunc_def->zread_file = fread_file_func;
168 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
169 pzlib_filefunc_def->ztell_file = ftell_file_func;
170 pzlib_filefunc_def->zseek_file = fseek_file_func;
171 pzlib_filefunc_def->zclose_file = fclose_file_func;
172 pzlib_filefunc_def->zerror_file = ferror_file_func;
173 pzlib_filefunc_def->opaque = NULL;