3 /* ioapi.c -- IO base function header for compress/uncompress .zip
4 files using zlib + zip or unzip API
6 Version 1.01e, February 12th, 2005
8 Copyright (C) 1998-2005 Gilles Vollant
20 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
34 voidpf ZCALLBACK fopen_file_func
OF((
39 uLong ZCALLBACK fread_file_func
OF((
45 uLong ZCALLBACK fwrite_file_func
OF((
51 long ZCALLBACK ftell_file_func
OF((
55 long ZCALLBACK fseek_file_func
OF((
61 int ZCALLBACK fclose_file_func
OF((
65 int ZCALLBACK ferror_file_func
OF((
70 voidpf ZCALLBACK
fopen_file_func (opaque
, filename
, mode
)
76 const char* mode_fopen
= NULL
;
77 if ((mode
& ZLIB_FILEFUNC_MODE_READWRITEFILTER
)==ZLIB_FILEFUNC_MODE_READ
)
80 if (mode
& ZLIB_FILEFUNC_MODE_EXISTING
)
83 if (mode
& ZLIB_FILEFUNC_MODE_CREATE
)
86 if ((filename
!=NULL
) && (mode_fopen
!= NULL
))
87 file
= fopen(filename
, mode_fopen
);
92 uLong ZCALLBACK
fread_file_func (opaque
, stream
, buf
, size
)
99 ret
= (uLong
)fread(buf
, 1, (size_t)size
, (FILE *)stream
);
104 uLong ZCALLBACK
fwrite_file_func (opaque
, stream
, buf
, size
)
111 ret
= (uLong
)fwrite(buf
, 1, (size_t)size
, (FILE *)stream
);
115 long ZCALLBACK
ftell_file_func (opaque
, stream
)
120 ret
= ftell((FILE *)stream
);
124 long ZCALLBACK
fseek_file_func (opaque
, stream
, offset
, origin
)
134 case ZLIB_FILEFUNC_SEEK_CUR
:
135 fseek_origin
= SEEK_CUR
;
137 case ZLIB_FILEFUNC_SEEK_END
:
138 fseek_origin
= SEEK_END
;
140 case ZLIB_FILEFUNC_SEEK_SET
:
141 fseek_origin
= SEEK_SET
;
146 fseek((FILE *)stream
, offset
, fseek_origin
);
150 int ZCALLBACK
fclose_file_func (opaque
, stream
)
155 ret
= fclose((FILE *)stream
);
159 int ZCALLBACK
ferror_file_func (opaque
, stream
)
164 ret
= ferror((FILE *)stream
);
168 void fill_fopen_filefunc (pzlib_filefunc_def
)
169 zlib_filefunc_def
* pzlib_filefunc_def
;
171 pzlib_filefunc_def
->zopen_file
= fopen_file_func
;
172 pzlib_filefunc_def
->zread_file
= fread_file_func
;
173 pzlib_filefunc_def
->zwrite_file
= fwrite_file_func
;
174 pzlib_filefunc_def
->ztell_file
= ftell_file_func
;
175 pzlib_filefunc_def
->zseek_file
= fseek_file_func
;
176 pzlib_filefunc_def
->zclose_file
= fclose_file_func
;
177 pzlib_filefunc_def
->zerror_file
= ferror_file_func
;
178 pzlib_filefunc_def
->opaque
= NULL
;