~ubuntu-branches/ubuntu/dapper/zziplib/dapper

« back to all changes in this revision

Viewing changes to zziplib/zziplib.h

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno
  • Date: 2004-03-29 12:41:28 UTC
  • Revision ID: james.westby@ubuntu.com-20040329124128-hf9y5elywpavuh5y
Tags: upstream-0.10.82
ImportĀ upstreamĀ versionĀ 0.10.82

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 Guido Draheim
 
7
 *          All rights reserved, 
 
8
 *          usage allowed under the restrictions of the
 
9
 *          Lesser GNU General Public License 
 
10
 *          note the additional license information 
 
11
 *          that can be found in COPYING.ZZIP
 
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-conf.h>
 
23
 
 
24
#include <fcntl.h>
 
25
#include <stddef.h> /* size_t and friends */
 
26
/* msvc6 has neither ssize_t (we assume "int") nor off_t (assume "long") */
 
27
 
 
28
#ifdef __cplusplus
 
29
extern "C" {
 
30
#endif
 
31
 
 
32
/* the zzip_error_t is also used to pass back ZLIB errors... */
 
33
#define ZZIP_ERROR -4096
 
34
 
 
35
typedef enum 
 
36
{
 
37
    ZZIP_NO_ERROR = 0,  /* no error, may be used if user sets it. */
 
38
    ZZIP_OUTOFMEM =     ZZIP_ERROR-20, /* out of memory */
 
39
    ZZIP_DIR_OPEN =      ZZIP_ERROR-21, /* failed to open zipfile, see errno for details */
 
40
    ZZIP_DIR_STAT =      ZZIP_ERROR-22, /* failed to fstat zipfile, see errno for details */
 
41
    ZZIP_DIR_SEEK =      ZZIP_ERROR-23, /* failed to lseek zipfile, see errno for details */
 
42
    ZZIP_DIR_READ =      ZZIP_ERROR-24, /* failed to read zipfile, see errno for details */
 
43
    ZZIP_DIR_TOO_SHORT = ZZIP_ERROR-25,
 
44
    ZZIP_DIR_EDH_MISSING = ZZIP_ERROR-26,
 
45
    ZZIP_DIRSIZE =      ZZIP_ERROR-27,
 
46
    ZZIP_ENOENT =       ZZIP_ERROR-28,
 
47
    ZZIP_UNSUPP_COMPR = ZZIP_ERROR-29,
 
48
    ZZIP_CORRUPTED =    ZZIP_ERROR-31,
 
49
    ZZIP_UNDEF =        ZZIP_ERROR-32,
 
50
} zzip_error_t;
 
51
 
 
52
/*
 
53
 * zzip_open flags.
 
54
 */
 
55
#define ZZIP_CASEINSENSITIVE    O_APPEND /* do not use anymore. use CASLESS */
 
56
#define ZZIP_IGNOREPATH         O_TRUNC  /* do not use anymore. use NOPATHS */
 
57
#define ZZIP_EXTRAFLAGS         (ZZIP_CASEINSENSITIVE|ZZIP_IGNOREPATH)
 
58
 
 
59
/* zzip_open_ext_io o_modes flags : new style. use these from now on! */
 
60
#define ZZIP_CASELESS           (1<<12) /* ignore filename case inside zips */
 
61
#define ZZIP_NOPATHS            (1<<13) /* ignore subdir paths, just filename*/
 
62
#define ZZIP_PREFERZIP          (1<<14) /* try first zipped file, then real*/
 
63
#define ZZIP_ONLYZIP            (1<<16) /* try _only_ zipped file, skip real*/
 
64
#define ZZIP_FACTORY            (1<<17) /* old file handle is not closed */
 
65
#define ZZIP_ALLOWREAL          (1<<18) /* real files use default_io (magic) */
 
66
 
 
67
/*
 
68
 * zzip largefile renames
 
69
 */
 
70
#ifdef ZZIP_LARGEFILE_RENAME
 
71
#define zzip_telldir zzip_telldir64
 
72
#define zzip_seekdir zzip_seekdir64
 
73
#endif
 
74
 
 
75
/*
 
76
 * zzip typedefs
 
77
 */
 
78
/* zzip_strings_t ext[] = { ".zip", ".jar", ".pk3", 0 } */
 
79
typedef  char _zzip_const * _zzip_const zzip_strings_t;
 
80
typedef  char _zzip_const       zzip_char_t;
 
81
typedef       _zzip_off_t       zzip_off_t;
 
82
typedef       _zzip_size_t      zzip_size_t;
 
83
typedef       _zzip_ssize_t     zzip_ssize_t;
 
84
typedef struct zzip_dir         ZZIP_DIR;
 
85
typedef struct zzip_file        ZZIP_FILE;
 
86
typedef struct zzip_dirent      ZZIP_DIRENT;
 
87
typedef struct zzip_dirent      ZZIP_STAT;
 
88
 
 
89
struct zzip_dirent
 
90
{
 
91
    int         d_compr;        /* compression method */
 
92
    int         d_csize;        /* compressed size */
 
93
    int         st_size;        /* file size / decompressed size */
 
94
    char *      d_name;         /* file name / strdupped name */
 
95
};
 
96
 
 
97
/*
 
98
 * Getting error strings 
 
99
 * zzip-err.c
 
100
 */
 
101
_zzip_export    /* error in _opendir : */
 
102
zzip_char_t*    zzip_strerror(int errcode); 
 
103
_zzip_export    /* error in other functions : */
 
104
zzip_char_t*    zzip_strerror_of(ZZIP_DIR * dir); 
 
105
_zzip_export    /* error mapped to errno.h defines : */
 
106
int             zzip_errno(int errcode); 
 
107
 
 
108
 
 
109
/*
 
110
 * Functions to grab information from ZZIP_DIR/ZZIP_FILE structure 
 
111
 * (if ever needed)
 
112
 * zzip-info.c
 
113
 */
 
114
_zzip_export
 
115
int             zzip_error(ZZIP_DIR * dir);
 
116
_zzip_export
 
117
void            zzip_seterror(ZZIP_DIR * dir, int errcode);
 
118
_zzip_export
 
119
zzip_char_t*    zzip_compr_str(int compr);
 
120
 
 
121
_zzip_export
 
122
ZZIP_DIR *      zzip_dirhandle(ZZIP_FILE * fp);
 
123
_zzip_export
 
124
int             zzip_dirfd(ZZIP_DIR * dir);
 
125
_zzip_export
 
126
int             zzip_dir_real(ZZIP_DIR * dir);
 
127
_zzip_export
 
128
int             zzip_file_real(ZZIP_FILE * fp);
 
129
_zzip_export
 
130
void*           zzip_realdir(ZZIP_DIR * dir);
 
131
_zzip_export
 
132
int             zzip_realfd(ZZIP_FILE * fp);
 
133
 
 
134
/*
 
135
 * zip handle management
 
136
 * zzip-zip.c
 
137
 */
 
138
_zzip_export
 
139
ZZIP_DIR *      zzip_dir_alloc(zzip_strings_t* fileext);
 
140
_zzip_export
 
141
int             zzip_dir_free(ZZIP_DIR *);
 
142
 
 
143
/*
 
144
 * Opening/closing a zip archive
 
145
 * zzip-zip.c
 
146
 */
 
147
_zzip_export
 
148
ZZIP_DIR *      zzip_dir_fdopen(int fd, zzip_error_t * errcode_p);
 
149
_zzip_export
 
150
ZZIP_DIR *      zzip_dir_open(zzip_char_t* filename, zzip_error_t * errcode_p);
 
151
_zzip_export
 
152
int             zzip_dir_close(ZZIP_DIR * dir);
 
153
_zzip_export
 
154
int             zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * dirent);
 
155
 
 
156
 
 
157
/*
 
158
 * Scanning files in zip archive
 
159
 * zzip-dir.c
 
160
 * zzip-zip.c
 
161
 */
 
162
_zzip_export
 
163
ZZIP_DIR *      zzip_opendir(zzip_char_t* filename);
 
164
_zzip_export
 
165
int             zzip_closedir(ZZIP_DIR * dir);
 
166
_zzip_export
 
167
ZZIP_DIRENT *   zzip_readdir(ZZIP_DIR * dir);
 
168
_zzip_export
 
169
void            zzip_rewinddir(ZZIP_DIR * dir);
 
170
_zzip_export
 
171
zzip_off_t      zzip_telldir(ZZIP_DIR * dir);
 
172
_zzip_export
 
173
void            zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset);
 
174
 
 
175
/*
 
176
 * 'opening', 'closing' and reading invidual files in zip archive.
 
177
 * zzip-file.c
 
178
 */
 
179
 
 
180
_zzip_export
 
181
ZZIP_FILE *     zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int modes);
 
182
_zzip_export
 
183
int             zzip_file_close(ZZIP_FILE * fp);
 
184
_zzip_export
 
185
zzip_ssize_t    zzip_file_read(ZZIP_FILE * fp, char* buf, zzip_size_t len);
 
186
 
 
187
_zzip_export
 
188
ZZIP_FILE *     zzip_open(zzip_char_t* name, int flags);
 
189
_zzip_export
 
190
int             zzip_close(ZZIP_FILE * fp);
 
191
_zzip_export
 
192
zzip_ssize_t    zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len);
 
193
 
 
194
 
 
195
_zzip_export
 
196
ZZIP_FILE*      zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*);
 
197
_zzip_export
 
198
ZZIP_FILE*      zzip_fopen(zzip_char_t* name, zzip_char_t* mode);
 
199
_zzip_export
 
200
zzip_size_t     zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, 
 
201
                           ZZIP_FILE * file);
 
202
_zzip_export
 
203
int             zzip_fclose(ZZIP_FILE * fp);
 
204
 
 
205
/*
 
206
 *  seek and tell functions
 
207
 */
 
208
_zzip_export
 
209
int             zzip_rewind(ZZIP_FILE *fp);
 
210
_zzip_export
 
211
zzip_off_t      zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence);
 
212
_zzip_export
 
213
zzip_off_t      zzip_tell(ZZIP_FILE * fp);
 
214
 
 
215
 
 
216
/*
 
217
 * reading info of a single file 
 
218
 * zzip-stat.c
 
219
 */
 
220
_zzip_export
 
221
int             zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name, 
 
222
                              ZZIP_STAT * zs, int flags);
 
223
 
 
224
 
 
225
#ifdef ZZIP_LARGEFILE_RENAME
 
226
#define zzip_open_shared_io  zzip_open_shared_io64
 
227
#define zzip_open_ext_io     zzip_open_ext_io64
 
228
#define zzip_opendir_ext_io  zzip_opendir_ext_io64
 
229
#define zzip_dir_open_ext_io zzip_dir_open_ext_io64
 
230
#define zzip_plugin_io_t     zzip_plugin_io64_t
 
231
#endif
 
232
 
 
233
/*
 
234
 * all ext_io functions can be called with a default of ext/io == zero/zero
 
235
 * which will default to a ".zip" extension and posix io of the system.
 
236
 */
 
237
typedef struct zzip_plugin_io _zzip_const * zzip_plugin_io_t;
 
238
 
 
239
_zzip_export
 
240
ZZIP_FILE * zzip_open_shared_io(ZZIP_FILE* stream,
 
241
                                zzip_char_t* name, int o_flags, int o_modes,
 
242
                                zzip_strings_t* ext, zzip_plugin_io_t io);
 
243
 
 
244
_zzip_export
 
245
ZZIP_FILE * zzip_open_ext_io(zzip_char_t* name, int o_flags, int o_modes,
 
246
                             zzip_strings_t* ext, zzip_plugin_io_t io);
 
247
 
 
248
_zzip_export
 
249
ZZIP_DIR *  zzip_opendir_ext_io(zzip_char_t* name, int o_modes,
 
250
                                zzip_strings_t* ext, zzip_plugin_io_t io);
 
251
 
 
252
_zzip_export
 
253
ZZIP_FILE * zzip_file_open_ext_io(ZZIP_DIR * dir, 
 
254
                                  zzip_char_t* name, int flags,
 
255
                                  zzip_strings_t* ext, zzip_plugin_io_t io);
 
256
 
 
257
_zzip_export
 
258
ZZIP_DIR *  zzip_dir_open_ext_io(zzip_char_t* filename, 
 
259
                                 zzip_error_t* errcode_p,
 
260
                                 zzip_strings_t* ext, zzip_plugin_io_t io);
 
261
 
 
262
#ifdef __cplusplus
 
263
};
 
264
#endif
 
265
 
 
266
#endif /* _ZZIPLIB_H */
 
267