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.... */
33 voidpf ZCALLBACK fopen_file_func
OF((
39 uLong ZCALLBACK fread_file_func
OF((
46 uLong ZCALLBACK fwrite_file_func
OF((
53 long ZCALLBACK ftell_file_func
OF((
58 long ZCALLBACK fseek_file_func
OF((
65 int ZCALLBACK fclose_file_func
OF((
70 int ZCALLBACK ferror_file_func
OF((
75 voidpf ZCALLBACK
fopen_file_func (opaque
, filename
, mode
)
81 const char* mode_fopen
= NULL
;
82 if ((mode
& ZLIB_FILEFUNC_MODE_READWRITEFILTER
)==ZLIB_FILEFUNC_MODE_READ
)
85 if (mode
& ZLIB_FILEFUNC_MODE_EXISTING
)
88 if (mode
& ZLIB_FILEFUNC_MODE_CREATE
)
91 if ((filename
!=NULL
) && (mode_fopen
!= NULL
))
92 file
= fopen(filename
, mode_fopen
);
97 uLong ZCALLBACK
fread_file_func (opaque
, stream
, buf
, size
)
104 ret
= (uLong
)fread(buf
, 1, (size_t)size
, (FILE *)stream
);
109 uLong ZCALLBACK
fwrite_file_func (opaque
, stream
, buf
, size
)
116 ret
= (uLong
)fwrite(buf
, 1, (size_t)size
, (FILE *)stream
);
121 long ZCALLBACK
ftell_file_func (opaque
, stream
)
126 ret
= ftell((FILE *)stream
);
131 long ZCALLBACK
fseek_file_func (opaque
, stream
, offset
, origin
)
141 case ZLIB_FILEFUNC_SEEK_CUR
:
142 fseek_origin
= SEEK_CUR
;
144 case ZLIB_FILEFUNC_SEEK_END
:
145 fseek_origin
= SEEK_END
;
147 case ZLIB_FILEFUNC_SEEK_SET
:
148 fseek_origin
= SEEK_SET
;
153 fseek((FILE *)stream
, offset
, fseek_origin
);
158 int ZCALLBACK
fclose_file_func (opaque
, stream
)
163 ret
= fclose((FILE *)stream
);
168 int ZCALLBACK
ferror_file_func (opaque
, stream
)
173 ret
= ferror((FILE *)stream
);
177 void fill_fopen_filefunc (pzlib_filefunc_def
)
178 zlib_filefunc_def
* pzlib_filefunc_def
;
180 pzlib_filefunc_def
->zopen_file
= fopen_file_func
;
181 pzlib_filefunc_def
->zread_file
= fread_file_func
;
182 pzlib_filefunc_def
->zwrite_file
= fwrite_file_func
;
183 pzlib_filefunc_def
->ztell_file
= ftell_file_func
;
184 pzlib_filefunc_def
->zseek_file
= fseek_file_func
;
185 pzlib_filefunc_def
->zclose_file
= fclose_file_func
;
186 pzlib_filefunc_def
->zerror_file
= ferror_file_func
;
187 pzlib_filefunc_def
->opaque
= NULL
;