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
18
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
32
voidpf ZCALLBACK fopen_file_func OF((
37
uLong ZCALLBACK fread_file_func OF((
43
uLong ZCALLBACK fwrite_file_func OF((
49
long ZCALLBACK ftell_file_func OF((
53
long ZCALLBACK fseek_file_func OF((
59
int ZCALLBACK fclose_file_func OF((
63
int ZCALLBACK ferror_file_func OF((
68
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
73
(void) opaque; /* avoid "unused parameter" warning */
75
const char* mode_fopen = NULL;
76
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
79
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
82
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
85
if ((filename!=NULL) && (mode_fopen != NULL))
86
file = fopen(filename, mode_fopen);
91
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
97
(void) opaque; /* avoid "unused parameter" warning */
99
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
104
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
110
(void) opaque; /* avoid "unused parameter" warning */
112
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
116
long ZCALLBACK ftell_file_func (opaque, stream)
120
(void) opaque; /* avoid "unused parameter" warning */
122
ret = ftell((FILE *)stream);
126
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
132
(void) opaque; /* avoid "unused parameter" warning */
137
case ZLIB_FILEFUNC_SEEK_CUR :
138
fseek_origin = SEEK_CUR;
140
case ZLIB_FILEFUNC_SEEK_END :
141
fseek_origin = SEEK_END;
143
case ZLIB_FILEFUNC_SEEK_SET :
144
fseek_origin = SEEK_SET;
149
fseek((FILE *)stream, offset, fseek_origin);
153
int ZCALLBACK fclose_file_func (opaque, stream)
157
(void) opaque; /* avoid "unused parameter" warning */
159
ret = fclose((FILE *)stream);
163
int ZCALLBACK ferror_file_func (opaque, stream)
167
(void) opaque; /* avoid "unused parameter" warning */
169
ret = ferror((FILE *)stream);
173
void fill_fopen_filefunc (pzlib_filefunc_def)
174
zlib_filefunc_def* pzlib_filefunc_def;
176
pzlib_filefunc_def->zopen_file = fopen_file_func;
177
pzlib_filefunc_def->zread_file = fread_file_func;
178
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
179
pzlib_filefunc_def->ztell_file = ftell_file_func;
180
pzlib_filefunc_def->zseek_file = fseek_file_func;
181
pzlib_filefunc_def->zclose_file = fclose_file_func;
182
pzlib_filefunc_def->zerror_file = ferror_file_func;
183
pzlib_filefunc_def->opaque = NULL;