bzlib.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*-------------------------------------------------------------*/
  2. /*--- Public header file for the library. ---*/
  3. /*--- bzlib.h ---*/
  4. /*-------------------------------------------------------------*/
  5. /* ------------------------------------------------------------------
  6. This file is part of bzip2/libbzip2, a program and library for
  7. lossless, block-sorting data compression.
  8. bzip2/libbzip2 version 1.0.8 of 13 July 2019
  9. Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
  10. Please read the WARNING, DISCLAIMER and PATENTS sections in the
  11. README file.
  12. This program is released under the terms of the license contained
  13. in the file LICENSE.
  14. ------------------------------------------------------------------ */
  15. #ifndef _BZLIB_H
  16. #define _BZLIB_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define BZ_RUN 0
  21. #define BZ_FLUSH 1
  22. #define BZ_FINISH 2
  23. #define BZ_OK 0
  24. #define BZ_RUN_OK 1
  25. #define BZ_FLUSH_OK 2
  26. #define BZ_FINISH_OK 3
  27. #define BZ_STREAM_END 4
  28. #define BZ_SEQUENCE_ERROR (-1)
  29. #define BZ_PARAM_ERROR (-2)
  30. #define BZ_MEM_ERROR (-3)
  31. #define BZ_DATA_ERROR (-4)
  32. #define BZ_DATA_ERROR_MAGIC (-5)
  33. #define BZ_IO_ERROR (-6)
  34. #define BZ_UNEXPECTED_EOF (-7)
  35. #define BZ_OUTBUFF_FULL (-8)
  36. #define BZ_CONFIG_ERROR (-9)
  37. typedef
  38. struct {
  39. char *next_in;
  40. unsigned int avail_in;
  41. unsigned int total_in_lo32;
  42. unsigned int total_in_hi32;
  43. char *next_out;
  44. unsigned int avail_out;
  45. unsigned int total_out_lo32;
  46. unsigned int total_out_hi32;
  47. void *state;
  48. void *(*bzalloc)(void *,int,int);
  49. void (*bzfree)(void *,void *);
  50. void *opaque;
  51. }
  52. bz_stream;
  53. #ifndef BZ_IMPORT
  54. #define BZ_EXPORT
  55. #endif
  56. #ifndef BZ_NO_STDIO
  57. /* Need a definitition for FILE */
  58. #include <stdio.h>
  59. #endif
  60. #if defined(_WIN32) && !defined(__CYGWIN__)
  61. # include <windows.h>
  62. # ifdef small
  63. /* windows.h define small to char */
  64. # undef small
  65. # endif
  66. # ifndef __GNUC__
  67. /* Use these rules only for non-gcc native win32 */
  68. # ifdef BZ_EXPORT
  69. # define BZ_API(func) WINAPI func
  70. # define BZ_EXTERN extern
  71. # else
  72. /* import windows dll dynamically */
  73. # define BZ_API(func) (WINAPI * func)
  74. # define BZ_EXTERN
  75. # endif
  76. # else
  77. /* For gcc on native win32, use import library trampoline */
  78. /* functions on DLL import. This avoids requiring clients to */
  79. /* use special compilation flags depending on whether eventual */
  80. /* link will be against static libbz2 or against DLL, at the */
  81. /* expense of a small loss of efficiency. */
  82. /* Because libbz2 does not export any DATA items, GNU ld's */
  83. /* "auto-import" is not a factor; the MinGW-built DLL can be */
  84. /* used by other compilers, provided an import library suitable */
  85. /* for that compiler is (manually) constructed using the .def */
  86. /* file and the appropriate tool. */
  87. # define BZ_API(func) func
  88. # define BZ_EXTERN extern
  89. # endif
  90. #else
  91. /* non-win32 platforms, and cygwin */
  92. # define BZ_API(func) func
  93. # define BZ_EXTERN extern
  94. #endif
  95. /*-- Core (low-level) library functions --*/
  96. BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
  97. bz_stream* strm,
  98. int blockSize100k,
  99. int verbosity,
  100. int workFactor
  101. );
  102. BZ_EXTERN int BZ_API(BZ2_bzCompress) (
  103. bz_stream* strm,
  104. int action
  105. );
  106. BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
  107. bz_stream* strm
  108. );
  109. BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
  110. bz_stream *strm,
  111. int verbosity,
  112. int small
  113. );
  114. BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
  115. bz_stream* strm
  116. );
  117. BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
  118. bz_stream *strm
  119. );
  120. /*-- High(er) level library functions --*/
  121. #ifndef BZ_NO_STDIO
  122. #define BZ_MAX_UNUSED 5000
  123. typedef void BZFILE;
  124. BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
  125. int* bzerror,
  126. FILE* f,
  127. int verbosity,
  128. int small,
  129. void* unused,
  130. int nUnused
  131. );
  132. BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
  133. int* bzerror,
  134. BZFILE* b
  135. );
  136. BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
  137. int* bzerror,
  138. BZFILE* b,
  139. void** unused,
  140. int* nUnused
  141. );
  142. BZ_EXTERN int BZ_API(BZ2_bzRead) (
  143. int* bzerror,
  144. BZFILE* b,
  145. void* buf,
  146. int len
  147. );
  148. BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
  149. int* bzerror,
  150. FILE* f,
  151. int blockSize100k,
  152. int verbosity,
  153. int workFactor
  154. );
  155. BZ_EXTERN void BZ_API(BZ2_bzWrite) (
  156. int* bzerror,
  157. BZFILE* b,
  158. void* buf,
  159. int len
  160. );
  161. BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
  162. int* bzerror,
  163. BZFILE* b,
  164. int abandon,
  165. unsigned int* nbytes_in,
  166. unsigned int* nbytes_out
  167. );
  168. BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
  169. int* bzerror,
  170. BZFILE* b,
  171. int abandon,
  172. unsigned int* nbytes_in_lo32,
  173. unsigned int* nbytes_in_hi32,
  174. unsigned int* nbytes_out_lo32,
  175. unsigned int* nbytes_out_hi32
  176. );
  177. #endif
  178. /*-- Utility functions --*/
  179. BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
  180. char* dest,
  181. unsigned int* destLen,
  182. char* source,
  183. unsigned int sourceLen,
  184. int blockSize100k,
  185. int verbosity,
  186. int workFactor
  187. );
  188. BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
  189. char* dest,
  190. unsigned int* destLen,
  191. char* source,
  192. unsigned int sourceLen,
  193. int small,
  194. int verbosity
  195. );
  196. /*--
  197. Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
  198. to support better zlib compatibility.
  199. This code is not _officially_ part of libbzip2 (yet);
  200. I haven't tested it, documented it, or considered the
  201. threading-safeness of it.
  202. If this code breaks, please contact both Yoshioka and me.
  203. --*/
  204. BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
  205. void
  206. );
  207. #ifndef BZ_NO_STDIO
  208. BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
  209. const char *path,
  210. const char *mode
  211. );
  212. BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
  213. int fd,
  214. const char *mode
  215. );
  216. BZ_EXTERN int BZ_API(BZ2_bzread) (
  217. BZFILE* b,
  218. void* buf,
  219. int len
  220. );
  221. BZ_EXTERN int BZ_API(BZ2_bzwrite) (
  222. BZFILE* b,
  223. void* buf,
  224. int len
  225. );
  226. BZ_EXTERN int BZ_API(BZ2_bzflush) (
  227. BZFILE* b
  228. );
  229. BZ_EXTERN void BZ_API(BZ2_bzclose) (
  230. BZFILE* b
  231. );
  232. BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
  233. BZFILE *b,
  234. int *errnum
  235. );
  236. #endif
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif
  241. /*-------------------------------------------------------------*/
  242. /*--- end bzlib.h ---*/
  243. /*-------------------------------------------------------------*/