uzlib.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
  3. *
  4. * Copyright (c) 2003 by Joergen Ibsen / Jibz
  5. * All Rights Reserved
  6. * http://www.ibsensoftware.com/
  7. *
  8. * Copyright (c) 2014-2016 by Paul Sokolovsky
  9. */
  10. #ifndef UZLIB_INFLATE_H
  11. #define UZLIB_INFLATE_H
  12. #include <setjmp.h>
  13. #include <stdint.h>
  14. #include <stdlib.h>
  15. #define uz_malloc malloc
  16. #define uz_free free
  17. #if defined(__XTENSA__)
  18. #include "mem.h"
  19. #define UZLIB_THROW(v) longjmp(unwindAddr, (v))
  20. #define UZLIB_SETJMP setjmp
  21. #else /* Host */
  22. extern int dbg_break(void);
  23. #if defined(_MSC_VER) || defined(__MINGW32__) //msvc requires old name for longjmp
  24. #define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));}
  25. #define UZLIB_SETJMP(n) setjmp(n)
  26. #else
  27. #define UZLIB_THROW(v) {dbg_break();_longjmp(unwindAddr, (v));}
  28. #define UZLIB_SETJMP(n) _setjmp(n)
  29. #endif
  30. #endif /* defined(__XTENSA__) */
  31. extern jmp_buf unwindAddr;
  32. /* ok status, more data produced */
  33. #define UZLIB_OK 0
  34. /* end of compressed stream reached */
  35. #define UZLIB_DONE 1
  36. #define UZLIB_DATA_ERROR (-3)
  37. #define UZLIB_CHKSUM_ERROR (-4)
  38. #define UZLIB_DICT_ERROR (-5)
  39. #define UZLIB_MEMORY_ERROR (-6)
  40. /* checksum types */
  41. #define UZLIB_CHKSUM_NONE 0
  42. #define UZLIB_CHKSUM_ADLER 1
  43. #define UZLIB_CHKSUM_CRC 2
  44. /* Gzip header codes */
  45. #define UZLIB_FTEXT 1
  46. #define UZLIB_FHCRC 2
  47. #define UZLIB_FEXTRA 4
  48. #define UZLIB_FNAME 8
  49. #define UZLIB_FCOMMENT 16
  50. /* Compression API */
  51. typedef struct uzlib_data UZLIB_DATA;
  52. int uzlib_inflate (uint8_t (*)(void), void (*)(uint8_t),
  53. uint8_t (*)(uint32_t), uint32_t len, uint32_t *crc, void **state);
  54. int uzlib_compress (uint8_t **dest, uint32_t *destLen,
  55. const uint8_t *src, uint32_t srcLen);
  56. /* Checksum API */
  57. /* crc is previous value for incremental computation, 0xffffffff initially */
  58. uint32_t uzlib_crc32(const void *data, uint32_t length, uint32_t crc);
  59. #endif /* UZLIB_INFLATE_H */