11cb0ef41Sopenharmony_ci/* zutil.h -- internal interface and configuration of the compression library
21cb0ef41Sopenharmony_ci * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler
31cb0ef41Sopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h
41cb0ef41Sopenharmony_ci */
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci/* WARNING: this file should *not* be used by applications. It is
71cb0ef41Sopenharmony_ci   part of the implementation of the compression library and is
81cb0ef41Sopenharmony_ci   subject to change. Applications should only use zlib.h.
91cb0ef41Sopenharmony_ci */
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci/* @(#) $Id$ */
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#ifndef ZUTIL_H
141cb0ef41Sopenharmony_ci#define ZUTIL_H
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#ifdef HAVE_HIDDEN
171cb0ef41Sopenharmony_ci#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
181cb0ef41Sopenharmony_ci#else
191cb0ef41Sopenharmony_ci#  define ZLIB_INTERNAL
201cb0ef41Sopenharmony_ci#endif
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci#include "zlib.h"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci#if defined(STDC) && !defined(Z_SOLO)
251cb0ef41Sopenharmony_ci#  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
261cb0ef41Sopenharmony_ci#    include <stddef.h>
271cb0ef41Sopenharmony_ci#  endif
281cb0ef41Sopenharmony_ci#  include <string.h>
291cb0ef41Sopenharmony_ci#  include <stdlib.h>
301cb0ef41Sopenharmony_ci#endif
311cb0ef41Sopenharmony_ci#ifdef NO_ERRNO_H
321cb0ef41Sopenharmony_ci#   ifdef _WIN32_WCE
331cb0ef41Sopenharmony_ci      /* The Microsoft C Run-Time Library for Windows CE doesn't have
341cb0ef41Sopenharmony_ci       * errno.  We define it as a global variable to simplify porting.
351cb0ef41Sopenharmony_ci       * Its value is always 0 and should not be used.  We rename it to
361cb0ef41Sopenharmony_ci       * avoid conflict with other libraries that use the same workaround.
371cb0ef41Sopenharmony_ci       */
381cb0ef41Sopenharmony_ci#     define errno z_errno
391cb0ef41Sopenharmony_ci#   endif
401cb0ef41Sopenharmony_ci    extern int errno;
411cb0ef41Sopenharmony_ci#else
421cb0ef41Sopenharmony_ci#  ifndef _WIN32_WCE
431cb0ef41Sopenharmony_ci#    include <errno.h>
441cb0ef41Sopenharmony_ci#  endif
451cb0ef41Sopenharmony_ci#endif
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci#ifndef local
481cb0ef41Sopenharmony_ci#  define local static
491cb0ef41Sopenharmony_ci#endif
501cb0ef41Sopenharmony_ci/* since "static" is used to mean two completely different things in C, we
511cb0ef41Sopenharmony_ci   define "local" for the non-static meaning of "static", for readability
521cb0ef41Sopenharmony_ci   (compile with -Dlocal if your debugger can't find static symbols) */
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_citypedef unsigned char  uch;
551cb0ef41Sopenharmony_citypedef uch FAR uchf;
561cb0ef41Sopenharmony_citypedef unsigned short ush;
571cb0ef41Sopenharmony_citypedef ush FAR ushf;
581cb0ef41Sopenharmony_citypedef unsigned long  ulg;
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
611cb0ef41Sopenharmony_ci#  include <limits.h>
621cb0ef41Sopenharmony_ci#  if (ULONG_MAX == 0xffffffffffffffff)
631cb0ef41Sopenharmony_ci#    define Z_U8 unsigned long
641cb0ef41Sopenharmony_ci#  elif (ULLONG_MAX == 0xffffffffffffffff)
651cb0ef41Sopenharmony_ci#    define Z_U8 unsigned long long
661cb0ef41Sopenharmony_ci#  elif (UINT_MAX == 0xffffffffffffffff)
671cb0ef41Sopenharmony_ci#    define Z_U8 unsigned
681cb0ef41Sopenharmony_ci#  endif
691cb0ef41Sopenharmony_ci#endif
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ciextern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
721cb0ef41Sopenharmony_ci/* (size given to avoid silly warnings with Visual C++) */
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci#define ERR_RETURN(strm,err) \
771cb0ef41Sopenharmony_ci  return (strm->msg = ERR_MSG(err), (err))
781cb0ef41Sopenharmony_ci/* To be used only when the state is known to be valid */
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci        /* common constants */
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ci#ifndef DEF_WBITS
831cb0ef41Sopenharmony_ci#  define DEF_WBITS MAX_WBITS
841cb0ef41Sopenharmony_ci#endif
851cb0ef41Sopenharmony_ci/* default windowBits for decompression. MAX_WBITS is for compression only */
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci#if MAX_MEM_LEVEL >= 8
881cb0ef41Sopenharmony_ci#  define DEF_MEM_LEVEL 8
891cb0ef41Sopenharmony_ci#else
901cb0ef41Sopenharmony_ci#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
911cb0ef41Sopenharmony_ci#endif
921cb0ef41Sopenharmony_ci/* default memLevel */
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci#define STORED_BLOCK 0
951cb0ef41Sopenharmony_ci#define STATIC_TREES 1
961cb0ef41Sopenharmony_ci#define DYN_TREES    2
971cb0ef41Sopenharmony_ci/* The three kinds of block type */
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci#define MIN_MATCH  3
1001cb0ef41Sopenharmony_ci#define MAX_MATCH  258
1011cb0ef41Sopenharmony_ci/* The minimum and maximum match lengths */
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci        /* target dependencies */
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
1081cb0ef41Sopenharmony_ci#  define OS_CODE  0x00
1091cb0ef41Sopenharmony_ci#  ifndef Z_SOLO
1101cb0ef41Sopenharmony_ci#    if defined(__TURBOC__) || defined(__BORLANDC__)
1111cb0ef41Sopenharmony_ci#      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
1121cb0ef41Sopenharmony_ci         /* Allow compilation with ANSI keywords only enabled */
1131cb0ef41Sopenharmony_ci         void _Cdecl farfree( void *block );
1141cb0ef41Sopenharmony_ci         void *_Cdecl farmalloc( unsigned long nbytes );
1151cb0ef41Sopenharmony_ci#      else
1161cb0ef41Sopenharmony_ci#        include <alloc.h>
1171cb0ef41Sopenharmony_ci#      endif
1181cb0ef41Sopenharmony_ci#    else /* MSC or DJGPP */
1191cb0ef41Sopenharmony_ci#      include <malloc.h>
1201cb0ef41Sopenharmony_ci#    endif
1211cb0ef41Sopenharmony_ci#  endif
1221cb0ef41Sopenharmony_ci#endif
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci#ifdef AMIGA
1251cb0ef41Sopenharmony_ci#  define OS_CODE  1
1261cb0ef41Sopenharmony_ci#endif
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci#if defined(VAXC) || defined(VMS)
1291cb0ef41Sopenharmony_ci#  define OS_CODE  2
1301cb0ef41Sopenharmony_ci#  define F_OPEN(name, mode) \
1311cb0ef41Sopenharmony_ci     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
1321cb0ef41Sopenharmony_ci#endif
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci#ifdef __370__
1351cb0ef41Sopenharmony_ci#  if __TARGET_LIB__ < 0x20000000
1361cb0ef41Sopenharmony_ci#    define OS_CODE 4
1371cb0ef41Sopenharmony_ci#  elif __TARGET_LIB__ < 0x40000000
1381cb0ef41Sopenharmony_ci#    define OS_CODE 11
1391cb0ef41Sopenharmony_ci#  else
1401cb0ef41Sopenharmony_ci#    define OS_CODE 8
1411cb0ef41Sopenharmony_ci#  endif
1421cb0ef41Sopenharmony_ci#endif
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci#if defined(ATARI) || defined(atarist)
1451cb0ef41Sopenharmony_ci#  define OS_CODE  5
1461cb0ef41Sopenharmony_ci#endif
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci#ifdef OS2
1491cb0ef41Sopenharmony_ci#  define OS_CODE  6
1501cb0ef41Sopenharmony_ci#  if defined(M_I86) && !defined(Z_SOLO)
1511cb0ef41Sopenharmony_ci#    include <malloc.h>
1521cb0ef41Sopenharmony_ci#  endif
1531cb0ef41Sopenharmony_ci#endif
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci#if defined(MACOS) || defined(TARGET_OS_MAC)
1561cb0ef41Sopenharmony_ci#  define OS_CODE  7
1571cb0ef41Sopenharmony_ci#  ifndef Z_SOLO
1581cb0ef41Sopenharmony_ci#    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
1591cb0ef41Sopenharmony_ci#      include <unix.h> /* for fdopen */
1601cb0ef41Sopenharmony_ci#    else
1611cb0ef41Sopenharmony_ci#      ifndef fdopen
1621cb0ef41Sopenharmony_ci#        define fdopen(fd,mode) NULL /* No fdopen() */
1631cb0ef41Sopenharmony_ci#      endif
1641cb0ef41Sopenharmony_ci#    endif
1651cb0ef41Sopenharmony_ci#  endif
1661cb0ef41Sopenharmony_ci#endif
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci#ifdef __acorn
1691cb0ef41Sopenharmony_ci#  define OS_CODE 13
1701cb0ef41Sopenharmony_ci#endif
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci#if defined(WIN32) && !defined(__CYGWIN__)
1731cb0ef41Sopenharmony_ci#  define OS_CODE  10
1741cb0ef41Sopenharmony_ci#endif
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci#ifdef _BEOS_
1771cb0ef41Sopenharmony_ci#  define OS_CODE  16
1781cb0ef41Sopenharmony_ci#endif
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci#ifdef __TOS_OS400__
1811cb0ef41Sopenharmony_ci#  define OS_CODE 18
1821cb0ef41Sopenharmony_ci#endif
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci#ifdef __APPLE__
1851cb0ef41Sopenharmony_ci#  define OS_CODE 19
1861cb0ef41Sopenharmony_ci#endif
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci#if defined(_BEOS_) || defined(RISCOS)
1891cb0ef41Sopenharmony_ci#  define fdopen(fd,mode) NULL /* No fdopen() */
1901cb0ef41Sopenharmony_ci#endif
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
1931cb0ef41Sopenharmony_ci#  if defined(_WIN32_WCE)
1941cb0ef41Sopenharmony_ci#    define fdopen(fd,mode) NULL /* No fdopen() */
1951cb0ef41Sopenharmony_ci#  else
1961cb0ef41Sopenharmony_ci#    define fdopen(fd,type)  _fdopen(fd,type)
1971cb0ef41Sopenharmony_ci#  endif
1981cb0ef41Sopenharmony_ci#endif
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci#if defined(__BORLANDC__) && !defined(MSDOS)
2011cb0ef41Sopenharmony_ci  #pragma warn -8004
2021cb0ef41Sopenharmony_ci  #pragma warn -8008
2031cb0ef41Sopenharmony_ci  #pragma warn -8066
2041cb0ef41Sopenharmony_ci#endif
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ci/* provide prototypes for these when building zlib without LFS */
2071cb0ef41Sopenharmony_ci#if !defined(_WIN32) && \
2081cb0ef41Sopenharmony_ci    (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
2091cb0ef41Sopenharmony_ci    ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
2101cb0ef41Sopenharmony_ci    ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
2111cb0ef41Sopenharmony_ci    ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
2121cb0ef41Sopenharmony_ci#endif
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci        /* common defaults */
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci#ifndef OS_CODE
2171cb0ef41Sopenharmony_ci#  define OS_CODE  3     /* assume Unix */
2181cb0ef41Sopenharmony_ci#endif
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci#ifndef F_OPEN
2211cb0ef41Sopenharmony_ci#  define F_OPEN(name, mode) fopen((name), (mode))
2221cb0ef41Sopenharmony_ci#endif
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci         /* functions */
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci#if defined(pyr) || defined(Z_SOLO)
2271cb0ef41Sopenharmony_ci#  define NO_MEMCPY
2281cb0ef41Sopenharmony_ci#endif
2291cb0ef41Sopenharmony_ci#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
2301cb0ef41Sopenharmony_ci /* Use our own functions for small and medium model with MSC <= 5.0.
2311cb0ef41Sopenharmony_ci  * You may have to use the same strategy for Borland C (untested).
2321cb0ef41Sopenharmony_ci  * The __SC__ check is for Symantec.
2331cb0ef41Sopenharmony_ci  */
2341cb0ef41Sopenharmony_ci#  define NO_MEMCPY
2351cb0ef41Sopenharmony_ci#endif
2361cb0ef41Sopenharmony_ci#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
2371cb0ef41Sopenharmony_ci#  define HAVE_MEMCPY
2381cb0ef41Sopenharmony_ci#endif
2391cb0ef41Sopenharmony_ci#ifdef HAVE_MEMCPY
2401cb0ef41Sopenharmony_ci#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
2411cb0ef41Sopenharmony_ci#    define zmemcpy _fmemcpy
2421cb0ef41Sopenharmony_ci#    define zmemcmp _fmemcmp
2431cb0ef41Sopenharmony_ci#    define zmemzero(dest, len) _fmemset(dest, 0, len)
2441cb0ef41Sopenharmony_ci#  else
2451cb0ef41Sopenharmony_ci#    define zmemcpy memcpy
2461cb0ef41Sopenharmony_ci#    define zmemcmp memcmp
2471cb0ef41Sopenharmony_ci#    define zmemzero(dest, len) memset(dest, 0, len)
2481cb0ef41Sopenharmony_ci#  endif
2491cb0ef41Sopenharmony_ci#else
2501cb0ef41Sopenharmony_ci   void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
2511cb0ef41Sopenharmony_ci   int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
2521cb0ef41Sopenharmony_ci   void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
2531cb0ef41Sopenharmony_ci#endif
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci/* Diagnostic functions */
2561cb0ef41Sopenharmony_ci#ifdef ZLIB_DEBUG
2571cb0ef41Sopenharmony_ci#  include <stdio.h>
2581cb0ef41Sopenharmony_ci   extern int ZLIB_INTERNAL z_verbose;
2591cb0ef41Sopenharmony_ci   extern void ZLIB_INTERNAL z_error(char *m);
2601cb0ef41Sopenharmony_ci#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
2611cb0ef41Sopenharmony_ci#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
2621cb0ef41Sopenharmony_ci#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
2631cb0ef41Sopenharmony_ci#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
2641cb0ef41Sopenharmony_ci#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
2651cb0ef41Sopenharmony_ci#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
2661cb0ef41Sopenharmony_ci#else
2671cb0ef41Sopenharmony_ci#  define Assert(cond,msg)
2681cb0ef41Sopenharmony_ci#  define Trace(x)
2691cb0ef41Sopenharmony_ci#  define Tracev(x)
2701cb0ef41Sopenharmony_ci#  define Tracevv(x)
2711cb0ef41Sopenharmony_ci#  define Tracec(c,x)
2721cb0ef41Sopenharmony_ci#  define Tracecv(c,x)
2731cb0ef41Sopenharmony_ci#endif
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci#ifndef Z_SOLO
2761cb0ef41Sopenharmony_ci   voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
2771cb0ef41Sopenharmony_ci                                unsigned size);
2781cb0ef41Sopenharmony_ci   void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
2791cb0ef41Sopenharmony_ci#endif
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci#define ZALLOC(strm, items, size) \
2821cb0ef41Sopenharmony_ci           (*((strm)->zalloc))((strm)->opaque, (items), (size))
2831cb0ef41Sopenharmony_ci#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
2841cb0ef41Sopenharmony_ci#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci/* Reverse the bytes in a 32-bit value */
2871cb0ef41Sopenharmony_ci#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
2881cb0ef41Sopenharmony_ci                    (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci#ifdef _MSC_VER
2911cb0ef41Sopenharmony_ci#define zalign(x) __declspec(align(x))
2921cb0ef41Sopenharmony_ci#else
2931cb0ef41Sopenharmony_ci#define zalign(x) __attribute__((aligned((x))))
2941cb0ef41Sopenharmony_ci#endif
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci#endif /* ZUTIL_H */
297