source: OGRE/trunk/ogrenew/Dependencies/include/zzip/zzip.h @ 657

Revision 657, 10.1 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2 * Author:
3 *      Guido Draheim <guidod@gmx.de>
4 *      Tomi Ollila <Tomi.Ollila@iki.fi>
5 *
6 *      Copyright (c) 1999,2000,2001,2002,2003,2004 Guido Draheim
7 *          All rights reserved,
8 *          usage allowed under the restrictions of the
9 *          Lesser GNU General Public License
10 *          or alternatively the restrictions
11 *          of the Mozilla Public License 1.1
12 *
13 * if you see "unknown symbol" errors, check first that `-I ..` is part of
14 * your compiler options - a special hint to VC/IDE users who tend to make up
15 * their own workspace files. All includes look like #include <zzip|*.h>, so
16 * you need to add an include path to the dir containing (!!) the ./zzip/ dir
17 */
18
19#ifndef _ZZIP_ZZIP_H /* zziplib.h */
20#define _ZZIP_ZZIP_H
21
22#include <zzip/types.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* the zzip_error_t is also used to pass back ZLIB errors... */
29#define ZZIP_ERROR -4096
30
31typedef enum
32{
33    ZZIP_NO_ERROR = 0,  /* no error, may be used if user sets it. */
34    ZZIP_OUTOFMEM =     ZZIP_ERROR-20, /* out of memory */
35    ZZIP_DIR_OPEN =      ZZIP_ERROR-21, /* failed to open zipfile, see errno for details */
36    ZZIP_DIR_STAT =      ZZIP_ERROR-22, /* failed to fstat zipfile, see errno for details */
37    ZZIP_DIR_SEEK =      ZZIP_ERROR-23, /* failed to lseek zipfile, see errno for details */
38    ZZIP_DIR_READ =      ZZIP_ERROR-24, /* failed to read zipfile, see errno for details */
39    ZZIP_DIR_TOO_SHORT = ZZIP_ERROR-25,
40    ZZIP_DIR_EDH_MISSING = ZZIP_ERROR-26,
41    ZZIP_DIRSIZE =      ZZIP_ERROR-27,
42    ZZIP_ENOENT =       ZZIP_ERROR-28,
43    ZZIP_UNSUPP_COMPR = ZZIP_ERROR-29,
44    ZZIP_CORRUPTED =    ZZIP_ERROR-31,
45    ZZIP_UNDEF =        ZZIP_ERROR-32
46} zzip_error_t;
47
48/*
49 * zzip_open flags.
50 */
51#define ZZIP_CASEINSENSITIVE    O_APPEND /* do not use anymore. use CASLESS */
52#define ZZIP_IGNOREPATH         O_TRUNC  /* do not use anymore. use NOPATHS */
53#define ZZIP_EXTRAFLAGS         (ZZIP_CASEINSENSITIVE|ZZIP_IGNOREPATH)
54
55/* zzip_open_ext_io o_modes flags : new style. use these from now on! */
56#define ZZIP_CASELESS           (1<<12) /* ignore filename case inside zips */
57#define ZZIP_NOPATHS            (1<<13) /* ignore subdir paths, just filename*/
58#define ZZIP_PREFERZIP          (1<<14) /* try first zipped file, then real*/
59#define ZZIP_ONLYZIP            (1<<16) /* try _only_ zipped file, skip real*/
60#define ZZIP_FACTORY            (1<<17) /* old file handle is not closed */
61#define ZZIP_ALLOWREAL          (1<<18) /* real files use default_io (magic) */
62#define ZZIP_THREADED           (1<<19) /* try to be safe for multithreading */
63
64/*
65 * zzip largefile renames
66 */
67#ifdef ZZIP_LARGEFILE_RENAME
68#define zzip_telldir zzip_telldir64
69#define zzip_seekdir zzip_seekdir64
70#endif
71
72/*
73 * zzip typedefs
74 */
75/* zzip_strings_t ext[] = { ".zip", ".jar", ".pk3", 0 } */
76typedef  char _zzip_const * _zzip_const zzip_strings_t;
77typedef  char _zzip_const       zzip_char_t;
78typedef struct zzip_dir         ZZIP_DIR;
79typedef struct zzip_file        ZZIP_FILE;
80typedef struct zzip_dirent      ZZIP_DIRENT;
81typedef struct zzip_dirent      ZZIP_STAT;
82
83struct zzip_dirent
84{
85    int         d_compr;        /* compression method */
86    int         d_csize;        /* compressed size */
87    int         st_size;        /* file size / decompressed size */
88    char *      d_name;         /* file name / strdupped name */
89};
90
91/*
92 * Getting error strings
93 * zzip/err.c
94 */
95_zzip_export    /* error in _opendir : */
96zzip_char_t*    zzip_strerror(int errcode);
97_zzip_export    /* error in other functions : */
98zzip_char_t*    zzip_strerror_of(ZZIP_DIR * dir);
99_zzip_export    /* error mapped to errno.h defines : */
100int             zzip_errno(int errcode);
101
102
103/*
104 * Functions to grab information from ZZIP_DIR/ZZIP_FILE structure
105 * (if ever needed)
106 * zzip/info.c
107 */
108_zzip_export
109int             zzip_error(ZZIP_DIR * dir);
110_zzip_export
111void            zzip_seterror(ZZIP_DIR * dir, int errcode);
112_zzip_export
113zzip_char_t*    zzip_compr_str(int compr);
114
115_zzip_export
116ZZIP_DIR *      zzip_dirhandle(ZZIP_FILE * fp);
117_zzip_export
118int             zzip_dirfd(ZZIP_DIR * dir);
119_zzip_export
120int             zzip_dir_real(ZZIP_DIR * dir);
121_zzip_export
122int             zzip_file_real(ZZIP_FILE * fp);
123_zzip_export
124void*           zzip_realdir(ZZIP_DIR * dir);
125_zzip_export
126int             zzip_realfd(ZZIP_FILE * fp);
127
128/*
129 * zip handle management
130 * zzip/zip.c
131 */
132_zzip_export
133ZZIP_DIR *      zzip_dir_alloc(zzip_strings_t* fileext);
134_zzip_export
135int             zzip_dir_free(ZZIP_DIR *);
136
137/*
138 * Opening/closing a zip archive
139 * zzip-zip.c
140 */
141_zzip_export
142ZZIP_DIR *      zzip_dir_fdopen(int fd, zzip_error_t * errcode_p);
143_zzip_export
144ZZIP_DIR *      zzip_dir_open(zzip_char_t* filename, zzip_error_t * errcode_p);
145_zzip_export
146int             zzip_dir_close(ZZIP_DIR * dir);
147_zzip_export
148int             zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * dirent);
149
150
151/*
152 * Scanning files in zip archive
153 * zzip/dir.c
154 * zzip/zip.c
155 */
156_zzip_export
157ZZIP_DIR *      zzip_opendir(zzip_char_t* filename);
158_zzip_export
159int             zzip_closedir(ZZIP_DIR * dir);
160_zzip_export
161ZZIP_DIRENT *   zzip_readdir(ZZIP_DIR * dir);
162_zzip_export
163void            zzip_rewinddir(ZZIP_DIR * dir);
164_zzip_export
165zzip_off_t      zzip_telldir(ZZIP_DIR * dir);
166_zzip_export
167void            zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset);
168
169/*
170 * 'opening', 'closing' and reading invidual files in zip archive.
171 * zzip/file.c
172 */
173_zzip_export
174ZZIP_FILE *     zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int flags);
175_zzip_export
176int             zzip_file_close(ZZIP_FILE * fp);
177_zzip_export
178zzip_ssize_t    zzip_file_read(ZZIP_FILE * fp, char* buf, zzip_size_t len);
179
180_zzip_export
181ZZIP_FILE *     zzip_open(zzip_char_t* name, int flags);
182_zzip_export
183int             zzip_close(ZZIP_FILE * fp);
184_zzip_export
185zzip_ssize_t    zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len);
186
187/*
188 * the stdc variant to open/read/close files. - Take note of the freopen()
189 * call as it may reuse an existing preparsed copy of a zip central directory
190 */
191_zzip_export
192ZZIP_FILE*      zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*);
193_zzip_export
194ZZIP_FILE*      zzip_fopen(zzip_char_t* name, zzip_char_t* mode);
195_zzip_export
196zzip_size_t     zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb,
197                           ZZIP_FILE * file);
198_zzip_export
199int             zzip_fclose(ZZIP_FILE * fp);
200
201/*
202 *  seek and tell functions
203 */
204_zzip_export
205int             zzip_rewind(ZZIP_FILE *fp);
206_zzip_export
207zzip_off_t      zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence);
208_zzip_export
209zzip_off_t      zzip_tell(ZZIP_FILE * fp);
210
211/*
212 * reading info of a single file
213 * zzip/stat.c
214 */
215_zzip_export
216int             zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name,
217                              ZZIP_STAT * zs, int flags);
218_zzip_export
219int             zzip_file_stat(ZZIP_FILE * fp, ZZIP_STAT * zs);
220_zzip_export
221int             zzip_fstat(ZZIP_FILE * fp, ZZIP_STAT * zs);
222
223#ifdef ZZIP_LARGEFILE_RENAME
224#define zzip_open_shared_io  zzip_open_shared_io64
225#define zzip_open_ext_io     zzip_open_ext_io64
226#define zzip_opendir_ext_io  zzip_opendir_ext_io64
227#define zzip_dir_open_ext_io zzip_dir_open_ext_io64
228#define zzip_plugin_io_t     zzip_plugin_io64_t
229#endif
230
231/*
232 * all ext_io functions can be called with a default of ext/io == zero/zero
233 * which will default to a ".zip" extension and posix io of the system.
234 */
235typedef union _zzip_plugin_io _zzip_const * zzip_plugin_io_t;
236
237_zzip_export
238ZZIP_FILE * zzip_open_shared_io(ZZIP_FILE* stream,
239                                zzip_char_t* name, int o_flags, int o_modes,
240                                zzip_strings_t* ext, zzip_plugin_io_t io);
241
242_zzip_export
243ZZIP_FILE * zzip_open_ext_io(zzip_char_t* name, int o_flags, int o_modes,
244                             zzip_strings_t* ext, zzip_plugin_io_t io);
245
246_zzip_export
247ZZIP_DIR *  zzip_opendir_ext_io(zzip_char_t* name, int o_modes,
248                                zzip_strings_t* ext, zzip_plugin_io_t io);
249
250_zzip_export
251ZZIP_DIR *  zzip_dir_open_ext_io(zzip_char_t* filename,
252                                 zzip_error_t* errcode_p,
253                                 zzip_strings_t* ext, zzip_plugin_io_t io);
254
255/* zzip_file_open_ext_io => zzip_dir_open_ext_io + zzip_file_open */
256
257#if defined _ZZIP_WRITE_SOURCE
258/* ........................................................................
259 * write support is not yet implemented
260 * zzip/write.c
261 */
262#define ZZIP_NO_CREAT 1
263
264ZZIP_DIR*    zzip_dir_creat_ext_io(zzip_char_t* name, int o_mode,
265                                   zzip_strings_t* ext, zzip_plugin_io_t io);
266ZZIP_DIR*    zzip_dir_creat(zzip_char_t* name, int o_mode);
267int          zzip_file_mkdir(ZZIP_DIR* dir, zzip_char_t* name, int o_mode);
268ZZIP_FILE*   zzip_file_creat(ZZIP_DIR* dir, zzip_char_t* name, int o_mode);
269zzip_ssize_t zzip_file_write(ZZIP_FILE* file,
270                             const void* ptr, zzip_size_t len);
271
272ZZIP_DIR*    zzip_createdir(zzip_char_t* name, int o_mode);
273zzip_ssize_t zzip_write(ZZIP_FILE* file, const void* ptr, zzip_size_t len);
274zzip_size_t  zzip_fwrite(const void* ptr, zzip_size_t len,
275                         zzip_size_t multiply, ZZIP_FILE* file);
276#ifndef zzip_savefile
277#define zzip_savefile 0
278#define zzip_savefile_is_null
279#endif
280
281#ifdef _ZZIP_NO_INLINE
282#define zzip_mkdir(_name_,_mode_) \
283        zzip_file_mkdir((zzip_savefile),(_name_),(_mode_))
284#define zzip_creat(_name_,_mode_) \
285        zzip_file_creat((zzip_savefile),(_name_),(_mode_))
286#define zzip_sync() \
287      { zzip_closedir((zzip_savefile)); (zzip_savefile) = 0; }
288#define zzip_start(_name_,_mode_,_ext_) \
289      { if ((zzip_savefile)) zzip_closedir((zzip_savefile));
290         zzip_savefile = zzip_dir_creat(_name_, _mode_,_ext_); }
291
292#else
293
294_zzip_inline static int         zzip_mkdir(zzip_char_t* name, int o_mode)
295{                   return zzip_file_mkdir(zzip_savefile, name, o_mode); }
296_zzip_inline static ZZIP_FILE*  zzip_creat(zzip_char_t* name, int o_mode)
297{                   return zzip_file_creat(zzip_savefile, name, o_mode); }
298
299#ifndef zzip_savefile_is_null
300_zzip_inline static void        zzip_sync(void)
301{                           zzip_closedir(zzip_savefile); zzip_savefile = 0; }
302_zzip_inline static void        zzip_mkfifo(zzip_char_t* name, int o_mode)
303{       if ((zzip_savefile)) zzip_closedir (zzip_savefile);
304             zzip_savefile = zzip_createdir(_name_,_mode_); }
305#else
306_zzip_inline static void        zzip_sync(void) {}
307_zzip_inline static void        zzip_mkfifo(zzip_char_t* name, int o_mode) {}
308#endif
309#endif /* _ZZIP_NO_INLINE */
310#endif /* _ZZIP_WRITE_SOURCE */
311
312#ifdef __cplusplus
313};
314#endif
315
316#endif /* _ZZIPLIB_H */
317
318/*
319 * Local variables:
320 * c-file-style: "stroustrup"
321 * End:
322 */
Note: See TracBrowser for help on using the repository browser.