1275793eaSopenharmony_ci/* zutil.h -- internal interface and configuration of the compression library
2275793eaSopenharmony_ci * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
3275793eaSopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h
4275793eaSopenharmony_ci */
5275793eaSopenharmony_ci
6275793eaSopenharmony_ci/* WARNING: this file should *not* be used by applications. It is
7275793eaSopenharmony_ci   part of the implementation of the compression library and is
8275793eaSopenharmony_ci   subject to change. Applications should only use zlib.h.
9275793eaSopenharmony_ci */
10275793eaSopenharmony_ci
11275793eaSopenharmony_ci/* @(#) $Id$ */
12275793eaSopenharmony_ci
13275793eaSopenharmony_ci#ifndef ZUTIL_H
14275793eaSopenharmony_ci#define ZUTIL_H
15275793eaSopenharmony_ci
16275793eaSopenharmony_ci#ifdef HAVE_HIDDEN
17275793eaSopenharmony_ci#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
18275793eaSopenharmony_ci#else
19275793eaSopenharmony_ci#  define ZLIB_INTERNAL
20275793eaSopenharmony_ci#endif
21275793eaSopenharmony_ci
22275793eaSopenharmony_ci#include "zlib.h"
23275793eaSopenharmony_ci
24275793eaSopenharmony_ci#if defined(STDC) && !defined(Z_SOLO)
25275793eaSopenharmony_ci#  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26275793eaSopenharmony_ci#    include <stddef.h>
27275793eaSopenharmony_ci#  endif
28275793eaSopenharmony_ci#  include <string.h>
29275793eaSopenharmony_ci#  include <stdlib.h>
30275793eaSopenharmony_ci#endif
31275793eaSopenharmony_ci
32275793eaSopenharmony_ci#ifndef local
33275793eaSopenharmony_ci#  define local static
34275793eaSopenharmony_ci#endif
35275793eaSopenharmony_ci/* since "static" is used to mean two completely different things in C, we
36275793eaSopenharmony_ci   define "local" for the non-static meaning of "static", for readability
37275793eaSopenharmony_ci   (compile with -Dlocal if your debugger can't find static symbols) */
38275793eaSopenharmony_ci
39275793eaSopenharmony_citypedef unsigned char  uch;
40275793eaSopenharmony_citypedef uch FAR uchf;
41275793eaSopenharmony_citypedef unsigned short ush;
42275793eaSopenharmony_citypedef ush FAR ushf;
43275793eaSopenharmony_citypedef unsigned long  ulg;
44275793eaSopenharmony_ci
45275793eaSopenharmony_ci#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
46275793eaSopenharmony_ci#  include <limits.h>
47275793eaSopenharmony_ci#  if (ULONG_MAX == 0xffffffffffffffff)
48275793eaSopenharmony_ci#    define Z_U8 unsigned long
49275793eaSopenharmony_ci#  elif (ULLONG_MAX == 0xffffffffffffffff)
50275793eaSopenharmony_ci#    define Z_U8 unsigned long long
51275793eaSopenharmony_ci#  elif (UINT_MAX == 0xffffffffffffffff)
52275793eaSopenharmony_ci#    define Z_U8 unsigned
53275793eaSopenharmony_ci#  endif
54275793eaSopenharmony_ci#endif
55275793eaSopenharmony_ci
56275793eaSopenharmony_ciextern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
57275793eaSopenharmony_ci/* (size given to avoid silly warnings with Visual C++) */
58275793eaSopenharmony_ci
59275793eaSopenharmony_ci#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
60275793eaSopenharmony_ci
61275793eaSopenharmony_ci#define ERR_RETURN(strm,err) \
62275793eaSopenharmony_ci  return (strm->msg = ERR_MSG(err), (err))
63275793eaSopenharmony_ci/* To be used only when the state is known to be valid */
64275793eaSopenharmony_ci
65275793eaSopenharmony_ci        /* common constants */
66275793eaSopenharmony_ci
67275793eaSopenharmony_ci#ifndef DEF_WBITS
68275793eaSopenharmony_ci#  define DEF_WBITS MAX_WBITS
69275793eaSopenharmony_ci#endif
70275793eaSopenharmony_ci/* default windowBits for decompression. MAX_WBITS is for compression only */
71275793eaSopenharmony_ci
72275793eaSopenharmony_ci#if MAX_MEM_LEVEL >= 8
73275793eaSopenharmony_ci#  define DEF_MEM_LEVEL 8
74275793eaSopenharmony_ci#else
75275793eaSopenharmony_ci#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
76275793eaSopenharmony_ci#endif
77275793eaSopenharmony_ci/* default memLevel */
78275793eaSopenharmony_ci
79275793eaSopenharmony_ci#define STORED_BLOCK 0
80275793eaSopenharmony_ci#define STATIC_TREES 1
81275793eaSopenharmony_ci#define DYN_TREES    2
82275793eaSopenharmony_ci/* The three kinds of block type */
83275793eaSopenharmony_ci
84275793eaSopenharmony_ci#define MIN_MATCH  3
85275793eaSopenharmony_ci#define MAX_MATCH  258
86275793eaSopenharmony_ci/* The minimum and maximum match lengths */
87275793eaSopenharmony_ci
88275793eaSopenharmony_ci#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
89275793eaSopenharmony_ci
90275793eaSopenharmony_ci        /* target dependencies */
91275793eaSopenharmony_ci
92275793eaSopenharmony_ci#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
93275793eaSopenharmony_ci#  define OS_CODE  0x00
94275793eaSopenharmony_ci#  ifndef Z_SOLO
95275793eaSopenharmony_ci#    if defined(__TURBOC__) || defined(__BORLANDC__)
96275793eaSopenharmony_ci#      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
97275793eaSopenharmony_ci         /* Allow compilation with ANSI keywords only enabled */
98275793eaSopenharmony_ci         void _Cdecl farfree( void *block );
99275793eaSopenharmony_ci         void *_Cdecl farmalloc( unsigned long nbytes );
100275793eaSopenharmony_ci#      else
101275793eaSopenharmony_ci#        include <alloc.h>
102275793eaSopenharmony_ci#      endif
103275793eaSopenharmony_ci#    else /* MSC or DJGPP */
104275793eaSopenharmony_ci#      include <malloc.h>
105275793eaSopenharmony_ci#    endif
106275793eaSopenharmony_ci#  endif
107275793eaSopenharmony_ci#endif
108275793eaSopenharmony_ci
109275793eaSopenharmony_ci#ifdef AMIGA
110275793eaSopenharmony_ci#  define OS_CODE  1
111275793eaSopenharmony_ci#endif
112275793eaSopenharmony_ci
113275793eaSopenharmony_ci#if defined(VAXC) || defined(VMS)
114275793eaSopenharmony_ci#  define OS_CODE  2
115275793eaSopenharmony_ci#  define F_OPEN(name, mode) \
116275793eaSopenharmony_ci     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
117275793eaSopenharmony_ci#endif
118275793eaSopenharmony_ci
119275793eaSopenharmony_ci#ifdef __370__
120275793eaSopenharmony_ci#  if __TARGET_LIB__ < 0x20000000
121275793eaSopenharmony_ci#    define OS_CODE 4
122275793eaSopenharmony_ci#  elif __TARGET_LIB__ < 0x40000000
123275793eaSopenharmony_ci#    define OS_CODE 11
124275793eaSopenharmony_ci#  else
125275793eaSopenharmony_ci#    define OS_CODE 8
126275793eaSopenharmony_ci#  endif
127275793eaSopenharmony_ci#endif
128275793eaSopenharmony_ci
129275793eaSopenharmony_ci#if defined(ATARI) || defined(atarist)
130275793eaSopenharmony_ci#  define OS_CODE  5
131275793eaSopenharmony_ci#endif
132275793eaSopenharmony_ci
133275793eaSopenharmony_ci#ifdef OS2
134275793eaSopenharmony_ci#  define OS_CODE  6
135275793eaSopenharmony_ci#  if defined(M_I86) && !defined(Z_SOLO)
136275793eaSopenharmony_ci#    include <malloc.h>
137275793eaSopenharmony_ci#  endif
138275793eaSopenharmony_ci#endif
139275793eaSopenharmony_ci
140275793eaSopenharmony_ci#if defined(MACOS)
141275793eaSopenharmony_ci#  define OS_CODE  7
142275793eaSopenharmony_ci#endif
143275793eaSopenharmony_ci
144275793eaSopenharmony_ci#ifdef __acorn
145275793eaSopenharmony_ci#  define OS_CODE 13
146275793eaSopenharmony_ci#endif
147275793eaSopenharmony_ci
148275793eaSopenharmony_ci#if defined(WIN32) && !defined(__CYGWIN__)
149275793eaSopenharmony_ci#  define OS_CODE  10
150275793eaSopenharmony_ci#endif
151275793eaSopenharmony_ci
152275793eaSopenharmony_ci#ifdef _BEOS_
153275793eaSopenharmony_ci#  define OS_CODE  16
154275793eaSopenharmony_ci#endif
155275793eaSopenharmony_ci
156275793eaSopenharmony_ci#ifdef __TOS_OS400__
157275793eaSopenharmony_ci#  define OS_CODE 18
158275793eaSopenharmony_ci#endif
159275793eaSopenharmony_ci
160275793eaSopenharmony_ci#ifdef __APPLE__
161275793eaSopenharmony_ci#  define OS_CODE 19
162275793eaSopenharmony_ci#endif
163275793eaSopenharmony_ci
164275793eaSopenharmony_ci#if defined(__BORLANDC__) && !defined(MSDOS)
165275793eaSopenharmony_ci  #pragma warn -8004
166275793eaSopenharmony_ci  #pragma warn -8008
167275793eaSopenharmony_ci  #pragma warn -8066
168275793eaSopenharmony_ci#endif
169275793eaSopenharmony_ci
170275793eaSopenharmony_ci/* provide prototypes for these when building zlib without LFS */
171275793eaSopenharmony_ci#if !defined(_WIN32) && \
172275793eaSopenharmony_ci    (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
173275793eaSopenharmony_ci    ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
174275793eaSopenharmony_ci    ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
175275793eaSopenharmony_ci    ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
176275793eaSopenharmony_ci#endif
177275793eaSopenharmony_ci
178275793eaSopenharmony_ci        /* common defaults */
179275793eaSopenharmony_ci
180275793eaSopenharmony_ci#ifndef OS_CODE
181275793eaSopenharmony_ci#  define OS_CODE  3     /* assume Unix */
182275793eaSopenharmony_ci#endif
183275793eaSopenharmony_ci
184275793eaSopenharmony_ci#ifndef F_OPEN
185275793eaSopenharmony_ci#  define F_OPEN(name, mode) fopen((name), (mode))
186275793eaSopenharmony_ci#endif
187275793eaSopenharmony_ci
188275793eaSopenharmony_ci         /* functions */
189275793eaSopenharmony_ci
190275793eaSopenharmony_ci#if defined(pyr) || defined(Z_SOLO)
191275793eaSopenharmony_ci#  define NO_MEMCPY
192275793eaSopenharmony_ci#endif
193275793eaSopenharmony_ci#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
194275793eaSopenharmony_ci /* Use our own functions for small and medium model with MSC <= 5.0.
195275793eaSopenharmony_ci  * You may have to use the same strategy for Borland C (untested).
196275793eaSopenharmony_ci  * The __SC__ check is for Symantec.
197275793eaSopenharmony_ci  */
198275793eaSopenharmony_ci#  define NO_MEMCPY
199275793eaSopenharmony_ci#endif
200275793eaSopenharmony_ci#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
201275793eaSopenharmony_ci#  define HAVE_MEMCPY
202275793eaSopenharmony_ci#endif
203275793eaSopenharmony_ci#ifdef HAVE_MEMCPY
204275793eaSopenharmony_ci#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
205275793eaSopenharmony_ci#    define zmemcpy _fmemcpy
206275793eaSopenharmony_ci#    define zmemcmp _fmemcmp
207275793eaSopenharmony_ci#    define zmemzero(dest, len) _fmemset(dest, 0, len)
208275793eaSopenharmony_ci#  else
209275793eaSopenharmony_ci#    define zmemcpy memcpy
210275793eaSopenharmony_ci#    define zmemcmp memcmp
211275793eaSopenharmony_ci#    define zmemzero(dest, len) memset(dest, 0, len)
212275793eaSopenharmony_ci#  endif
213275793eaSopenharmony_ci#else
214275793eaSopenharmony_ci   void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
215275793eaSopenharmony_ci   int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
216275793eaSopenharmony_ci   void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
217275793eaSopenharmony_ci#endif
218275793eaSopenharmony_ci
219275793eaSopenharmony_ci/* Diagnostic functions */
220275793eaSopenharmony_ci#ifdef ZLIB_DEBUG
221275793eaSopenharmony_ci#  include <stdio.h>
222275793eaSopenharmony_ci   extern int ZLIB_INTERNAL z_verbose;
223275793eaSopenharmony_ci   extern void ZLIB_INTERNAL z_error(char *m);
224275793eaSopenharmony_ci#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
225275793eaSopenharmony_ci#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
226275793eaSopenharmony_ci#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
227275793eaSopenharmony_ci#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
228275793eaSopenharmony_ci#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
229275793eaSopenharmony_ci#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
230275793eaSopenharmony_ci#else
231275793eaSopenharmony_ci#  define Assert(cond,msg)
232275793eaSopenharmony_ci#  define Trace(x)
233275793eaSopenharmony_ci#  define Tracev(x)
234275793eaSopenharmony_ci#  define Tracevv(x)
235275793eaSopenharmony_ci#  define Tracec(c,x)
236275793eaSopenharmony_ci#  define Tracecv(c,x)
237275793eaSopenharmony_ci#endif
238275793eaSopenharmony_ci
239275793eaSopenharmony_ci#ifndef Z_SOLO
240275793eaSopenharmony_ci   voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
241275793eaSopenharmony_ci                                unsigned size);
242275793eaSopenharmony_ci   void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
243275793eaSopenharmony_ci#endif
244275793eaSopenharmony_ci
245275793eaSopenharmony_ci#define ZALLOC(strm, items, size) \
246275793eaSopenharmony_ci           (*((strm)->zalloc))((strm)->opaque, (items), (size))
247275793eaSopenharmony_ci#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
248275793eaSopenharmony_ci#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
249275793eaSopenharmony_ci
250275793eaSopenharmony_ci/* Reverse the bytes in a 32-bit value */
251275793eaSopenharmony_ci#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
252275793eaSopenharmony_ci                    (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
253275793eaSopenharmony_ci
254275793eaSopenharmony_ci#endif /* ZUTIL_H */
255