/src/zziplib/zzip/zzip.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 268 lines · 159 code · 33 blank · 76 comment · 0 complexity · e1ce75a998e75f347208c2a43f6c5fc5 MD5 · raw file

  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. #ifndef _ZZIP_ZZIP_H /* zziplib.h */
  19. #define _ZZIP_ZZIP_H
  20. #include <zzip/types.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* the zzip_error_t is also used to pass back ZLIB errors... */
  25. #define ZZIP_ERROR -4096
  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. * zzip_open flags.
  45. */
  46. #define ZZIP_CASEINSENSITIVE O_APPEND /* do not use anymore. use CASLESS */
  47. #define ZZIP_IGNOREPATH O_TRUNC /* do not use anymore. use NOPATHS */
  48. #define ZZIP_EXTRAFLAGS (ZZIP_CASEINSENSITIVE|ZZIP_IGNOREPATH)
  49. /* zzip_open_ext_io o_modes flags : new style. use these from now on! */
  50. #define ZZIP_CASELESS (1<<12) /* ignore filename case inside zips */
  51. #define ZZIP_NOPATHS (1<<13) /* ignore subdir paths, just filename*/
  52. #define ZZIP_PREFERZIP (1<<14) /* try first zipped file, then real*/
  53. #define ZZIP_ONLYZIP (1<<16) /* try _only_ zipped file, skip real*/
  54. #define ZZIP_FACTORY (1<<17) /* old file handle is not closed */
  55. #define ZZIP_ALLOWREAL (1<<18) /* real files use default_io (magic) */
  56. #define ZZIP_THREADED (1<<19) /* try to be safe for multithreading */
  57. /*
  58. * zzip largefile renames
  59. */
  60. #ifdef ZZIP_LARGEFILE_RENAME
  61. #define zzip_telldir zzip_telldir64
  62. #define zzip_seekdir zzip_seekdir64
  63. #endif
  64. /*
  65. * zzip typedefs
  66. */
  67. /* zzip_strings_t ext[] = { ".zip", ".jar", ".pk3", 0 } */
  68. typedef char _zzip_const * _zzip_const zzip_strings_t;
  69. typedef char _zzip_const zzip_char_t;
  70. typedef struct zzip_dir ZZIP_DIR;
  71. typedef struct zzip_file ZZIP_FILE;
  72. typedef struct zzip_dirent ZZIP_DIRENT;
  73. typedef struct zzip_dirent ZZIP_STAT;
  74. struct zzip_dirent
  75. {
  76. int d_compr; /* compression method */
  77. int d_csize; /* compressed size */
  78. int st_size; /* file size / decompressed size */
  79. char * d_name; /* file name / strdupped name */
  80. };
  81. /*
  82. * Getting error strings
  83. * zzip/err.c
  84. */
  85. _zzip_export /* error in _opendir : */
  86. zzip_char_t* zzip_strerror(int errcode);
  87. _zzip_export /* error in other functions : */
  88. zzip_char_t* zzip_strerror_of(ZZIP_DIR * dir);
  89. _zzip_export /* error mapped to errno.h defines : */
  90. int zzip_errno(int errcode);
  91. /*
  92. * Functions to grab information from ZZIP_DIR/ZZIP_FILE structure
  93. * (if ever needed)
  94. * zzip/info.c
  95. */
  96. _zzip_export
  97. int zzip_error(ZZIP_DIR * dir);
  98. _zzip_export
  99. void zzip_seterror(ZZIP_DIR * dir, int errcode);
  100. _zzip_export
  101. zzip_char_t* zzip_compr_str(int compr);
  102. _zzip_export
  103. ZZIP_DIR * zzip_dirhandle(ZZIP_FILE * fp);
  104. _zzip_export
  105. int zzip_dirfd(ZZIP_DIR * dir);
  106. _zzip_export
  107. int zzip_dir_real(ZZIP_DIR * dir);
  108. _zzip_export
  109. int zzip_file_real(ZZIP_FILE * fp);
  110. _zzip_export
  111. void* zzip_realdir(ZZIP_DIR * dir);
  112. _zzip_export
  113. int zzip_realfd(ZZIP_FILE * fp);
  114. /*
  115. * zip handle management
  116. * zzip/zip.c
  117. */
  118. _zzip_export
  119. ZZIP_DIR * zzip_dir_alloc(zzip_strings_t* fileext);
  120. _zzip_export
  121. int zzip_dir_free(ZZIP_DIR *);
  122. /*
  123. * Opening/closing a zip archive
  124. * zzip-zip.c
  125. */
  126. _zzip_export
  127. ZZIP_DIR * zzip_dir_fdopen(int fd, zzip_error_t * errcode_p);
  128. _zzip_export
  129. ZZIP_DIR * zzip_dir_open(zzip_char_t* filename, zzip_error_t * errcode_p);
  130. _zzip_export
  131. int zzip_dir_close(ZZIP_DIR * dir);
  132. _zzip_export
  133. int zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * dirent);
  134. /*
  135. * Scanning files in zip archive
  136. * zzip/dir.c
  137. * zzip/zip.c
  138. */
  139. _zzip_export
  140. ZZIP_DIR * zzip_opendir(zzip_char_t* filename);
  141. _zzip_export
  142. int zzip_closedir(ZZIP_DIR * dir);
  143. _zzip_export
  144. ZZIP_DIRENT * zzip_readdir(ZZIP_DIR * dir);
  145. _zzip_export
  146. void zzip_rewinddir(ZZIP_DIR * dir);
  147. _zzip_export
  148. zzip_off_t zzip_telldir(ZZIP_DIR * dir);
  149. _zzip_export
  150. void zzip_seekdir(ZZIP_DIR * dir, zzip_off_t offset);
  151. /*
  152. * 'opening', 'closing' and reading invidual files in zip archive.
  153. * zzip/file.c
  154. */
  155. _zzip_export
  156. ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int flags);
  157. _zzip_export
  158. int zzip_file_close(ZZIP_FILE * fp);
  159. _zzip_export
  160. zzip_ssize_t zzip_file_read(ZZIP_FILE * fp, void* buf, zzip_size_t len);
  161. _zzip_export
  162. ZZIP_FILE * zzip_open(zzip_char_t* name, int flags);
  163. _zzip_export
  164. int zzip_close(ZZIP_FILE * fp);
  165. _zzip_export
  166. zzip_ssize_t zzip_read(ZZIP_FILE * fp, void * buf, zzip_size_t len);
  167. /*
  168. * the stdc variant to open/read/close files. - Take note of the freopen()
  169. * call as it may reuse an existing preparsed copy of a zip central directory
  170. */
  171. _zzip_export
  172. ZZIP_FILE* zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*);
  173. _zzip_export
  174. ZZIP_FILE* zzip_fopen(zzip_char_t* name, zzip_char_t* mode);
  175. _zzip_export
  176. zzip_size_t zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb,
  177. ZZIP_FILE * file);
  178. _zzip_export
  179. int zzip_fclose(ZZIP_FILE * fp);
  180. /*
  181. * seek and tell functions
  182. */
  183. _zzip_export
  184. int zzip_rewind(ZZIP_FILE *fp);
  185. _zzip_export
  186. zzip_off_t zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence);
  187. _zzip_export
  188. zzip_off_t zzip_tell(ZZIP_FILE * fp);
  189. /*
  190. * reading info of a single file
  191. * zzip/stat.c
  192. */
  193. _zzip_export
  194. int zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name,
  195. ZZIP_STAT * zs, int flags);
  196. _zzip_export
  197. int zzip_file_stat(ZZIP_FILE * fp, ZZIP_STAT * zs);
  198. _zzip_export
  199. int zzip_fstat(ZZIP_FILE * fp, ZZIP_STAT * zs);
  200. #ifdef ZZIP_LARGEFILE_RENAME
  201. #define zzip_open_shared_io zzip_open_shared_io64
  202. #define zzip_open_ext_io zzip_open_ext_io64
  203. #define zzip_opendir_ext_io zzip_opendir_ext_io64
  204. #define zzip_dir_open_ext_io zzip_dir_open_ext_io64
  205. #define zzip_plugin_io_t zzip_plugin_io64_t
  206. #endif
  207. /*
  208. * all ext_io functions can be called with a default of ext/io == zero/zero
  209. * which will default to a ".zip" extension and posix io of the system.
  210. */
  211. typedef union _zzip_plugin_io _zzip_const * zzip_plugin_io_t;
  212. _zzip_export
  213. ZZIP_FILE * zzip_open_shared_io(ZZIP_FILE* stream,
  214. zzip_char_t* name, int o_flags, int o_modes,
  215. zzip_strings_t* ext, zzip_plugin_io_t io);
  216. _zzip_export
  217. ZZIP_FILE * zzip_open_ext_io(zzip_char_t* name, int o_flags, int o_modes,
  218. zzip_strings_t* ext, zzip_plugin_io_t io);
  219. _zzip_export
  220. ZZIP_DIR * zzip_opendir_ext_io(zzip_char_t* name, int o_modes,
  221. zzip_strings_t* ext, zzip_plugin_io_t io);
  222. _zzip_export
  223. ZZIP_DIR * zzip_dir_open_ext_io(zzip_char_t* filename,
  224. zzip_error_t* errcode_p,
  225. zzip_strings_t* ext, zzip_plugin_io_t io);
  226. /* zzip_file_open_ext_io => zzip_dir_open_ext_io + zzip_file_open */
  227. #ifdef __cplusplus
  228. };
  229. #endif
  230. #endif /* _ZZIPLIB_H */
  231. /*
  232. * Local variables:
  233. * c-file-style: "stroustrup"
  234. * End:
  235. */