zutil.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef ZUTIL_H_
  2. #define ZUTIL_H_
  3. /* zutil.h -- internal interface and configuration of the compression library
  4. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
  5. * For conditions of distribution and use, see copyright notice in zlib.h
  6. */
  7. /* WARNING: this file should *not* be used by applications. It is
  8. part of the implementation of the compression library and is
  9. subject to change. Applications should only use zlib.h.
  10. */
  11. #include "zbuild.h"
  12. #ifdef ZLIB_COMPAT
  13. # include "zlib.h"
  14. #else
  15. # include "zlib-ng.h"
  16. #endif
  17. typedef unsigned char uch; /* Included for compatibility with external code only */
  18. typedef uint16_t ush; /* Included for compatibility with external code only */
  19. typedef unsigned long ulg;
  20. extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
  21. /* (size given to avoid silly warnings with Visual C++) */
  22. #define ERR_MSG(err) PREFIX(z_errmsg)[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
  23. #define ERR_RETURN(strm, err) return (strm->msg = ERR_MSG(err), (err))
  24. /* To be used only when the state is known to be valid */
  25. /* common constants */
  26. #ifndef DEF_WBITS
  27. # define DEF_WBITS MAX_WBITS
  28. #endif
  29. /* default windowBits for decompression. MAX_WBITS is for compression only */
  30. #define MAX_BITS 15
  31. /* all codes must not exceed MAX_BITS bits */
  32. #define MAX_DIST_EXTRA_BITS 13
  33. /* maximum number of extra distance bits */
  34. #if MAX_MEM_LEVEL >= 8
  35. # define DEF_MEM_LEVEL 8
  36. #else
  37. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  38. #endif
  39. /* default memLevel */
  40. #define STORED_BLOCK 0
  41. #define STATIC_TREES 1
  42. #define DYN_TREES 2
  43. /* The three kinds of block type */
  44. #define STD_MIN_MATCH 3
  45. #define STD_MAX_MATCH 258
  46. /* The minimum and maximum match lengths mandated by the deflate standard */
  47. #define WANT_MIN_MATCH 4
  48. /* The minimum wanted match length, affects deflate_quick, deflate_fast, deflate_medium and deflate_slow */
  49. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  50. #define ADLER32_INITIAL_VALUE 1 /* initial adler-32 hash value */
  51. #define CRC32_INITIAL_VALUE 0 /* initial crc-32 hash value */
  52. #define ZLIB_WRAPLEN 6 /* zlib format overhead */
  53. #define GZIP_WRAPLEN 18 /* gzip format overhead */
  54. #define DEFLATE_HEADER_BITS 3
  55. #define DEFLATE_EOBS_BITS 15
  56. #define DEFLATE_PAD_BITS 6
  57. #define DEFLATE_BLOCK_OVERHEAD ((DEFLATE_HEADER_BITS + DEFLATE_EOBS_BITS + DEFLATE_PAD_BITS) >> 3)
  58. /* deflate block overhead: 3 bits for block start + 15 bits for block end + padding to nearest byte */
  59. #define DEFLATE_QUICK_LIT_MAX_BITS 9
  60. #define DEFLATE_QUICK_OVERHEAD(x) ((x * (DEFLATE_QUICK_LIT_MAX_BITS - 8) + 7) >> 3)
  61. /* deflate_quick worst-case overhead: 9 bits per literal, round up to next byte (+7) */
  62. /* target dependencies */
  63. #ifdef AMIGA
  64. # define OS_CODE 1
  65. #endif
  66. #ifdef __370__
  67. # if __TARGET_LIB__ < 0x20000000
  68. # define OS_CODE 4
  69. # elif __TARGET_LIB__ < 0x40000000
  70. # define OS_CODE 11
  71. # else
  72. # define OS_CODE 8
  73. # endif
  74. #endif
  75. #if defined(ATARI) || defined(atarist)
  76. # define OS_CODE 5
  77. #endif
  78. #ifdef OS2
  79. # define OS_CODE 6
  80. #endif
  81. #if defined(MACOS)
  82. # define OS_CODE 7
  83. #endif
  84. #ifdef __acorn
  85. # define OS_CODE 13
  86. #endif
  87. #if defined(_WIN32) && !defined(__CYGWIN__)
  88. # define OS_CODE 10
  89. #endif
  90. #ifdef __APPLE__
  91. # define OS_CODE 19
  92. #endif
  93. /* common defaults */
  94. #ifndef OS_CODE
  95. # define OS_CODE 3 /* assume Unix */
  96. #endif
  97. /* macros */
  98. #define CHECK_VER_STSIZE(_ver,_stsize) ((_ver) == NULL || (_ver)[0] != PREFIX2(VERSION)[0] || (_stsize) != (int32_t)sizeof(PREFIX3(stream)))
  99. /* memory allocation functions */
  100. void Z_INTERNAL *PREFIX(zcalloc)(void *opaque, unsigned items, unsigned size);
  101. void Z_INTERNAL PREFIX(zcfree)(void *opaque, void *ptr);
  102. typedef void *zng_calloc_func(void *opaque, unsigned items, unsigned size);
  103. typedef void zng_cfree_func(void *opaque, void *ptr);
  104. #endif /* ZUTIL_H_ */