1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ioapi.m,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 *************************************************************************/
31 /* ioapi.c -- IO base function header for compress/uncompress .zip
32 files using zlib + zip or unzip API
34 Version 1.01e, February 12th, 2005
36 Copyright (C) 1998-2005 Gilles Vollant
48 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
62 voidpf ZCALLBACK fopen_file_func OF((
67 uLong ZCALLBACK fread_file_func OF((
73 uLong ZCALLBACK fwrite_file_func OF((
79 long ZCALLBACK ftell_file_func OF((
83 long ZCALLBACK fseek_file_func OF((
89 int ZCALLBACK fclose_file_func OF((
93 int ZCALLBACK ferror_file_func OF((
98 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
100 const char* filename;
104 const char* mode_fopen = NULL;
105 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
108 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
111 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
114 if ((filename!=NULL) && (mode_fopen != NULL))
115 file = fopen(filename, mode_fopen);
120 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
127 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
132 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
139 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
143 long ZCALLBACK ftell_file_func (opaque, stream)
148 ret = ftell((FILE *)stream);
152 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
162 case ZLIB_FILEFUNC_SEEK_CUR :
163 fseek_origin = SEEK_CUR;
165 case ZLIB_FILEFUNC_SEEK_END :
166 fseek_origin = SEEK_END;
168 case ZLIB_FILEFUNC_SEEK_SET :
169 fseek_origin = SEEK_SET;
174 fseek((FILE *)stream, offset, fseek_origin);
178 int ZCALLBACK fclose_file_func (opaque, stream)
183 ret = fclose((FILE *)stream);
187 int ZCALLBACK ferror_file_func (opaque, stream)
192 ret = ferror((FILE *)stream);
196 void fill_fopen_filefunc (pzlib_filefunc_def)
197 zlib_filefunc_def* pzlib_filefunc_def;
199 pzlib_filefunc_def->zopen_file = fopen_file_func;
200 pzlib_filefunc_def->zread_file = fread_file_func;
201 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
202 pzlib_filefunc_def->ztell_file = ftell_file_func;
203 pzlib_filefunc_def->zseek_file = fseek_file_func;
204 pzlib_filefunc_def->zclose_file = fclose_file_func;
205 pzlib_filefunc_def->zerror_file = ferror_file_func;
206 pzlib_filefunc_def->opaque = NULL;