Debian Codegraph @

libs/zziplib/zziplib-src/zzip/zzip.h

raw
1 /*
2 * Author:
3 * Guido Draheim <[email protected]>
4 * Tomi Ollila <[email protected]>
5 *
6 * Copyright (c) Guido Draheim, use under copyleft (LPGL,MPL)
7 *
8 * if you see "unknown symbol" errors, check first that `-I ..` is part of
9 * your compiler options - a special hint to VC/IDE users who tend to make up
10 * their own workspace files. All includes look like #include <zzip|*.h>, so
11 * you need to add an include path to the dir containing (!!) the ./zzip/ dir
12 */
13
14 #ifndef _ZZIP_ZZIP_H /* zziplib.h */
15 #define _ZZIP_ZZIP_H
16
17 #include <zzip/types.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /* the zzip_error_t is also used to pass back ZLIB errors... */
24 #define ZZIP_ERROR -4096
25
26 typedef enum
27 {
28 ZZIP_NO_ERROR = 0, /* no error, may be used if user sets it. */
29 ZZIP_OUTOFMEM = ZZIP_ERROR-20, /* out of memory */
30 ZZIP_DIR_OPEN = ZZIP_ERROR-21, /* failed to open zipfile, see errno for details */
31 ZZIP_DIR_STAT = ZZIP_ERROR-22, /* failed to fstat zipfile, see errno for details */
32 ZZIP_DIR_SEEK = ZZIP_ERROR-23, /* failed to lseek zipfile, see errno for details */
33 ZZIP_DIR_READ = ZZIP_ERROR-24, /* failed to read zipfile, see errno for details */
34 ZZIP_DIR_TOO_SHORT = ZZIP_ERROR-25,
35 ZZIP_DIR_EDH_MISSING = ZZIP_ERROR-26,
36 ZZIP_DIRSIZE = ZZIP_ERROR-27,
37 ZZIP_ENOENT = ZZIP_ERROR-28,
38 ZZIP_UNSUPP_COMPR = ZZIP_ERROR-29,
39 ZZIP_CORRUPTED = ZZIP_ERROR-31,
40 ZZIP_UNDEF = ZZIP_ERROR-32,
41 ZZIP_DIR_LARGEFILE = ZZIP_ERROR-33
42 } zzip_error_t;
43
44 /*
45 * zzip_open flags.
46 */
47 #define ZZIP_CASEINSENSITIVE O_APPEND /* do not use anymore. use CASLESS */
48 #define ZZIP_IGNOREPATH O_TRUNC /* do not use anymore. use NOPATHS */
49 #define ZZIP_EXTRAFLAGS (ZZIP_CASEINSENSITIVE|ZZIP_IGNOREPATH)
50
51 /* zzip_open_ext_io o_modes flags : new style. use these from now on! */
52 #define ZZIP_CASELESS (1<<12) /* ignore filename case inside zips */
53 #define ZZIP_NOPATHS (1<<13) /* ignore subdir paths, just filename*/
54 #define ZZIP_PREFERZIP (1<<14) /* try first zipped file, then real*/
55 #define ZZIP_ONLYZIP (1<<16) /* try _only_ zipped file, skip real*/
56 #define ZZIP_FACTORY (1<<17) /* old file handle is not closed */
57 #define ZZIP_ALLOWREAL (1<<18) /* real files use default_io (magic) */
58 #define ZZIP_THREADED (1<<19) /* try to be safe for multithreading */
59
60 /*
61 * zzip largefile renames
62 */
63 #ifdef ZZIP_LARGEFILE_RENAME
64 #define zzip_telldir zzip_telldir64
65 #define zzip_seekdir zzip_seekdir64
66 #endif
67
68 /*
69 * zzip typedefs
70 */
71 /* zzip_strings_t ext[] = { ".zip", ".jar", ".pk3", 0 } */
72 typedef char _zzip_const * _zzip_const zzip_strings_t;
73 typedef char _zzip_const zzip_char_t;
74 typedef struct zzip_dir ZZIP_DIR;
75 typedef struct zzip_file ZZIP_FILE;
76 typedef struct zzip_dirent ZZIP_DIRENT;
77 typedef struct zzip_dirent ZZIP_STAT;
78
79 struct zzip_dirent
80 {
81 int d_compr; /* compression method */
82 int d_csize; /* compressed size */
83 int st_size; /* file size / decompressed size */
84 char * d_name; /* file name / strdupped name */
85 };
86
87 /*
88 * Getting error strings
89 * zzip/err.c
90 */
91 _zzip_export /* error in _opendir : */
92 zzip_char_t* zzip_strerror(int errcode);
93 _zzip_export /* error in other functions : */
94 zzip_char_t* zzip_strerror_of(ZZIP_DIR * dir);
95 _zzip_export /* error mapped to errno.h defines : */
96 int zzip_errno(int errcode);
97
98
99 /*
100 * Functions to grab information from ZZIP_DIR/ZZIP_FILE structure
101 * (if ever needed)
102 * zzip/info.c
103 */
104 _zzip_export
105 int zzip_error(ZZIP_DIR * dir);
106 _zzip_export
107 void zzip_seterror(ZZIP_DIR * dir, int errcode);
108 _zzip_export
109 zzip_char_t* zzip_compr_str(int compr);
110
111 _zzip_export
112 ZZIP_DIR * zzip_dirhandle(ZZIP_FILE * fp);
113 _zzip_export
114 int zzip_dirfd(ZZIP_DIR * dir);
115 _zzip_export
116 int zzip_dir_real(ZZIP_DIR * dir);
117 _zzip_export
118 int zzip_file_real(ZZIP_FILE * fp);
119 _zzip_export
120 void* zzip_realdir(ZZIP_DIR * dir);
121 _zzip_export
122 int zzip_realfd(ZZIP_FILE * fp);
123
124 /*
125 * zip handle management
126 * zzip/zip.c
127 */
128 _zzip_export
129 ZZIP_DIR * zzip_dir_alloc(zzip_strings_t* fileext);
130 _zzip_export
131 int zzip_dir_free(ZZIP_DIR *);
132
133 /*
134 * Opening/closing a zip archive
135 * zzip-zip.c
136 */
137 _zzip_export
138 ZZIP_DIR * zzip_dir_fdopen(int fd, zzip_error_t * errcode_p);
139 _zzip_export
140 ZZIP_DIR * zzip_dir_open(zzip_char_t* filename, zzip_error_t * errcode_p);
141 _zzip_export
142 int zzip_dir_close(ZZIP_DIR * dir);
143 _zzip_export
144 int zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * dirent);
145
146
147 /*
148 * Scanning files in zip archive
149 * zzip/dir.c
150 * zzip/zip.c
151 */
152 _zzip_export
153 ZZIP_DIR * zzip_opendir(zzip_char_t* filename);
154 _zzip_export
155 int zzip_closedir(ZZIP_DIR * dir);
156 _zzip_export
157 ZZIP_DIRENT * zzip_readdir(ZZIP_DIR * dir);
158 _zzip_export
159 void zzip_rewinddir(ZZIP_DIR * dir);
160 _zzip_export
161 zzip_off_t zzip_telldir(ZZIP_DIR * dir);
162 _zzip_export
163 void zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset);
164
165 /*
166 * 'opening', 'closing' and reading individual files in zip archive.
167 * zzip/file.c
168 */
169 _zzip_export
170 ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int flags);
171 _zzip_export
172 int zzip_file_close(ZZIP_FILE * fp);
173 _zzip_export
174 zzip_ssize_t zzip_file_read(ZZIP_FILE * fp, void* buf, zzip_size_t len);
175
176 _zzip_export
177 ZZIP_FILE * zzip_open(zzip_char_t* name, int flags);
178 _zzip_export
179 int zzip_close(ZZIP_FILE * fp);
180 _zzip_export
181 zzip_ssize_t zzip_read(ZZIP_FILE * fp, void * buf, zzip_size_t len);
182
183 /*
184 * Read data from the specified offset. Depending on the
185 * implementation, this may or may not move the file pointer.
186 */
187 _zzip_export
188 zzip_size_t
189 zzip_pread(ZZIP_FILE *file, void *ptr, zzip_size_t size, zzip_off_t offset);
190
191 /*
192 * the stdc variant to open/read/close files. - Take note of the freopen()
193 * call as it may reuse an existing preparsed copy of a zip central directory
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 * reading info of a single file
217 * zzip/stat.c
218 */
219 _zzip_export
220 int zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name,
221 ZZIP_STAT * zs, int flags);
222 _zzip_export
223 int zzip_file_stat(ZZIP_FILE * fp, ZZIP_STAT * zs);
224 _zzip_export
225 int zzip_fstat(ZZIP_FILE * fp, ZZIP_STAT * zs);
226
227 #ifdef ZZIP_LARGEFILE_RENAME
228 #define zzip_open_shared_io zzip_open_shared_io64
229 #define zzip_open_ext_io zzip_open_ext_io64
230 #define zzip_opendir_ext_io zzip_opendir_ext_io64
231 #define zzip_dir_open_ext_io zzip_dir_open_ext_io64
232 #define zzip_plugin_io_t zzip_plugin_io64_t
233 #endif
234
235 /*
236 * all ext_io functions can be called with a default of ext/io == zero/zero
237 * which will default to a ".zip" extension and posix io of the system.
238 */
239 typedef union _zzip_plugin_io _zzip_const * zzip_plugin_io_t;
240
241 _zzip_export
242 ZZIP_FILE * zzip_open_shared_io(ZZIP_FILE* stream,
243 zzip_char_t* name, int o_flags, int o_modes,
244 zzip_strings_t* ext, zzip_plugin_io_t io);
245
246 _zzip_export
247 ZZIP_FILE * zzip_open_ext_io(zzip_char_t* name, int o_flags, int o_modes,
248 zzip_strings_t* ext, zzip_plugin_io_t io);
249
250 _zzip_export
251 ZZIP_DIR * zzip_opendir_ext_io(zzip_char_t* name, int o_modes,
252 zzip_strings_t* ext, zzip_plugin_io_t io);
253
254 _zzip_export
255 ZZIP_DIR * zzip_dir_open_ext_io(zzip_char_t* filename,
256 zzip_error_t* errcode_p,
257 zzip_strings_t* ext, zzip_plugin_io_t io);
258
259 /* zzip_file_open_ext_io => zzip_dir_open_ext_io + zzip_file_open */
260
261 #ifdef __cplusplus
262 }
263 #endif
264
265 #endif /* _ZZIPLIB_H */
266
267 /*
268 * Local variables:
269 * c-file-style: "stroustrup"
270 * End:
271 */