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 (voidpf opaque, const char* filename, int 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 (voidpf opaque, voidpf stream, void* buf, uLong size)
90 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
95 uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
98 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
102 long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
105 ret = ftell((FILE *)stream);
109 long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
115 case ZLIB_FILEFUNC_SEEK_CUR :
116 fseek_origin = SEEK_CUR;
118 case ZLIB_FILEFUNC_SEEK_END :
119 fseek_origin = SEEK_END;
121 case ZLIB_FILEFUNC_SEEK_SET :
122 fseek_origin = SEEK_SET;
127 fseek((FILE *)stream, offset, fseek_origin);
131 int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
134 ret = fclose((FILE *)stream);
138 int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
141 ret = ferror((FILE *)stream);
145 void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
147 pzlib_filefunc_def->zopen_file = fopen_file_func;
148 pzlib_filefunc_def->zread_file = fread_file_func;
149 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
150 pzlib_filefunc_def->ztell_file = ftell_file_func;
151 pzlib_filefunc_def->zseek_file = fseek_file_func;
152 pzlib_filefunc_def->zclose_file = fclose_file_func;
153 pzlib_filefunc_def->zerror_file = ferror_file_func;
154 pzlib_filefunc_def->opaque = NULL;