external/zlib-1.2.11/zutil.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 26 Oct 2018 14:58:01 -0700
changeset 617 d64228a395fc
parent 521 9ed2f7d4a251
permissions -rw-r--r--
Fixed webp library detection when cross-compiling for Windows
slouken@521
     1
/* zutil.h -- internal interface and configuration of the compression library
slouken@521
     2
 * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
slouken@521
     3
 * For conditions of distribution and use, see copyright notice in zlib.h
slouken@521
     4
 */
slouken@521
     5
slouken@521
     6
/* WARNING: this file should *not* be used by applications. It is
slouken@521
     7
   part of the implementation of the compression library and is
slouken@521
     8
   subject to change. Applications should only use zlib.h.
slouken@521
     9
 */
slouken@521
    10
slouken@521
    11
/* @(#) $Id$ */
slouken@521
    12
slouken@521
    13
#ifndef ZUTIL_H
slouken@521
    14
#define ZUTIL_H
slouken@521
    15
slouken@521
    16
#ifdef HAVE_HIDDEN
slouken@521
    17
#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
slouken@521
    18
#else
slouken@521
    19
#  define ZLIB_INTERNAL
slouken@521
    20
#endif
slouken@521
    21
slouken@521
    22
#include "zlib.h"
slouken@521
    23
slouken@521
    24
#if defined(STDC) && !defined(Z_SOLO)
slouken@521
    25
#  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
slouken@521
    26
#    include <stddef.h>
slouken@521
    27
#  endif
slouken@521
    28
#  include <string.h>
slouken@521
    29
#  include <stdlib.h>
slouken@521
    30
#endif
slouken@521
    31
slouken@521
    32
#ifdef Z_SOLO
slouken@521
    33
   typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
slouken@521
    34
#endif
slouken@521
    35
slouken@521
    36
#ifndef local
slouken@521
    37
#  define local static
slouken@521
    38
#endif
slouken@521
    39
/* since "static" is used to mean two completely different things in C, we
slouken@521
    40
   define "local" for the non-static meaning of "static", for readability
slouken@521
    41
   (compile with -Dlocal if your debugger can't find static symbols) */
slouken@521
    42
slouken@521
    43
typedef unsigned char  uch;
slouken@521
    44
typedef uch FAR uchf;
slouken@521
    45
typedef unsigned short ush;
slouken@521
    46
typedef ush FAR ushf;
slouken@521
    47
typedef unsigned long  ulg;
slouken@521
    48
slouken@521
    49
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
slouken@521
    50
/* (size given to avoid silly warnings with Visual C++) */
slouken@521
    51
slouken@521
    52
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
slouken@521
    53
slouken@521
    54
#define ERR_RETURN(strm,err) \
slouken@521
    55
  return (strm->msg = ERR_MSG(err), (err))
slouken@521
    56
/* To be used only when the state is known to be valid */
slouken@521
    57
slouken@521
    58
        /* common constants */
slouken@521
    59
slouken@521
    60
#ifndef DEF_WBITS
slouken@521
    61
#  define DEF_WBITS MAX_WBITS
slouken@521
    62
#endif
slouken@521
    63
/* default windowBits for decompression. MAX_WBITS is for compression only */
slouken@521
    64
slouken@521
    65
#if MAX_MEM_LEVEL >= 8
slouken@521
    66
#  define DEF_MEM_LEVEL 8
slouken@521
    67
#else
slouken@521
    68
#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
slouken@521
    69
#endif
slouken@521
    70
/* default memLevel */
slouken@521
    71
slouken@521
    72
#define STORED_BLOCK 0
slouken@521
    73
#define STATIC_TREES 1
slouken@521
    74
#define DYN_TREES    2
slouken@521
    75
/* The three kinds of block type */
slouken@521
    76
slouken@521
    77
#define MIN_MATCH  3
slouken@521
    78
#define MAX_MATCH  258
slouken@521
    79
/* The minimum and maximum match lengths */
slouken@521
    80
slouken@521
    81
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
slouken@521
    82
slouken@521
    83
        /* target dependencies */
slouken@521
    84
slouken@521
    85
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
slouken@521
    86
#  define OS_CODE  0x00
slouken@521
    87
#  ifndef Z_SOLO
slouken@521
    88
#    if defined(__TURBOC__) || defined(__BORLANDC__)
slouken@521
    89
#      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
slouken@521
    90
         /* Allow compilation with ANSI keywords only enabled */
slouken@521
    91
         void _Cdecl farfree( void *block );
slouken@521
    92
         void *_Cdecl farmalloc( unsigned long nbytes );
slouken@521
    93
#      else
slouken@521
    94
#        include <alloc.h>
slouken@521
    95
#      endif
slouken@521
    96
#    else /* MSC or DJGPP */
slouken@521
    97
#      include <malloc.h>
slouken@521
    98
#    endif
slouken@521
    99
#  endif
slouken@521
   100
#endif
slouken@521
   101
slouken@521
   102
#ifdef AMIGA
slouken@521
   103
#  define OS_CODE  1
slouken@521
   104
#endif
slouken@521
   105
slouken@521
   106
#if defined(VAXC) || defined(VMS)
slouken@521
   107
#  define OS_CODE  2
slouken@521
   108
#  define F_OPEN(name, mode) \
slouken@521
   109
     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
slouken@521
   110
#endif
slouken@521
   111
slouken@521
   112
#ifdef __370__
slouken@521
   113
#  if __TARGET_LIB__ < 0x20000000
slouken@521
   114
#    define OS_CODE 4
slouken@521
   115
#  elif __TARGET_LIB__ < 0x40000000
slouken@521
   116
#    define OS_CODE 11
slouken@521
   117
#  else
slouken@521
   118
#    define OS_CODE 8
slouken@521
   119
#  endif
slouken@521
   120
#endif
slouken@521
   121
slouken@521
   122
#if defined(ATARI) || defined(atarist)
slouken@521
   123
#  define OS_CODE  5
slouken@521
   124
#endif
slouken@521
   125
slouken@521
   126
#ifdef OS2
slouken@521
   127
#  define OS_CODE  6
slouken@521
   128
#  if defined(M_I86) && !defined(Z_SOLO)
slouken@521
   129
#    include <malloc.h>
slouken@521
   130
#  endif
slouken@521
   131
#endif
slouken@521
   132
slouken@521
   133
#if defined(MACOS) || defined(TARGET_OS_MAC)
slouken@521
   134
#  define OS_CODE  7
slouken@521
   135
#  ifndef Z_SOLO
slouken@521
   136
#    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
slouken@521
   137
#      include <unix.h> /* for fdopen */
slouken@521
   138
#    else
slouken@521
   139
#      ifndef fdopen
slouken@521
   140
#        define fdopen(fd,mode) NULL /* No fdopen() */
slouken@521
   141
#      endif
slouken@521
   142
#    endif
slouken@521
   143
#  endif
slouken@521
   144
#endif
slouken@521
   145
slouken@521
   146
#ifdef __acorn
slouken@521
   147
#  define OS_CODE 13
slouken@521
   148
#endif
slouken@521
   149
slouken@521
   150
#if defined(WIN32) && !defined(__CYGWIN__)
slouken@521
   151
#  define OS_CODE  10
slouken@521
   152
#endif
slouken@521
   153
slouken@521
   154
#ifdef _BEOS_
slouken@521
   155
#  define OS_CODE  16
slouken@521
   156
#endif
slouken@521
   157
slouken@521
   158
#ifdef __TOS_OS400__
slouken@521
   159
#  define OS_CODE 18
slouken@521
   160
#endif
slouken@521
   161
slouken@521
   162
#ifdef __APPLE__
slouken@521
   163
#  define OS_CODE 19
slouken@521
   164
#endif
slouken@521
   165
slouken@521
   166
#if defined(_BEOS_) || defined(RISCOS)
slouken@521
   167
#  define fdopen(fd,mode) NULL /* No fdopen() */
slouken@521
   168
#endif
slouken@521
   169
slouken@521
   170
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
slouken@521
   171
#  if defined(_WIN32_WCE)
slouken@521
   172
#    define fdopen(fd,mode) NULL /* No fdopen() */
slouken@521
   173
#    ifndef _PTRDIFF_T_DEFINED
slouken@521
   174
       typedef int ptrdiff_t;
slouken@521
   175
#      define _PTRDIFF_T_DEFINED
slouken@521
   176
#    endif
slouken@521
   177
#  else
slouken@521
   178
#    define fdopen(fd,type)  _fdopen(fd,type)
slouken@521
   179
#  endif
slouken@521
   180
#endif
slouken@521
   181
slouken@521
   182
#if defined(__BORLANDC__) && !defined(MSDOS)
slouken@521
   183
  #pragma warn -8004
slouken@521
   184
  #pragma warn -8008
slouken@521
   185
  #pragma warn -8066
slouken@521
   186
#endif
slouken@521
   187
slouken@521
   188
/* provide prototypes for these when building zlib without LFS */
slouken@521
   189
#if !defined(_WIN32) && \
slouken@521
   190
    (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
slouken@521
   191
    ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
slouken@521
   192
    ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
slouken@521
   193
#endif
slouken@521
   194
slouken@521
   195
        /* common defaults */
slouken@521
   196
slouken@521
   197
#ifndef OS_CODE
slouken@521
   198
#  define OS_CODE  3     /* assume Unix */
slouken@521
   199
#endif
slouken@521
   200
slouken@521
   201
#ifndef F_OPEN
slouken@521
   202
#  define F_OPEN(name, mode) fopen((name), (mode))
slouken@521
   203
#endif
slouken@521
   204
slouken@521
   205
         /* functions */
slouken@521
   206
slouken@521
   207
#if defined(pyr) || defined(Z_SOLO)
slouken@521
   208
#  define NO_MEMCPY
slouken@521
   209
#endif
slouken@521
   210
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
slouken@521
   211
 /* Use our own functions for small and medium model with MSC <= 5.0.
slouken@521
   212
  * You may have to use the same strategy for Borland C (untested).
slouken@521
   213
  * The __SC__ check is for Symantec.
slouken@521
   214
  */
slouken@521
   215
#  define NO_MEMCPY
slouken@521
   216
#endif
slouken@521
   217
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
slouken@521
   218
#  define HAVE_MEMCPY
slouken@521
   219
#endif
slouken@521
   220
#ifdef HAVE_MEMCPY
slouken@521
   221
#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
slouken@521
   222
#    define zmemcpy _fmemcpy
slouken@521
   223
#    define zmemcmp _fmemcmp
slouken@521
   224
#    define zmemzero(dest, len) _fmemset(dest, 0, len)
slouken@521
   225
#  else
slouken@521
   226
#    define zmemcpy memcpy
slouken@521
   227
#    define zmemcmp memcmp
slouken@521
   228
#    define zmemzero(dest, len) memset(dest, 0, len)
slouken@521
   229
#  endif
slouken@521
   230
#else
slouken@521
   231
   void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
slouken@521
   232
   int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
slouken@521
   233
   void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
slouken@521
   234
#endif
slouken@521
   235
slouken@521
   236
/* Diagnostic functions */
slouken@521
   237
#ifdef ZLIB_DEBUG
slouken@521
   238
#  include <stdio.h>
slouken@521
   239
   extern int ZLIB_INTERNAL z_verbose;
slouken@521
   240
   extern void ZLIB_INTERNAL z_error OF((char *m));
slouken@521
   241
#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
slouken@521
   242
#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
slouken@521
   243
#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
slouken@521
   244
#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
slouken@521
   245
#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
slouken@521
   246
#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
slouken@521
   247
#else
slouken@521
   248
#  define Assert(cond,msg)
slouken@521
   249
#  define Trace(x)
slouken@521
   250
#  define Tracev(x)
slouken@521
   251
#  define Tracevv(x)
slouken@521
   252
#  define Tracec(c,x)
slouken@521
   253
#  define Tracecv(c,x)
slouken@521
   254
#endif
slouken@521
   255
slouken@521
   256
#ifndef Z_SOLO
slouken@521
   257
   voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
slouken@521
   258
                                    unsigned size));
slouken@521
   259
   void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
slouken@521
   260
#endif
slouken@521
   261
slouken@521
   262
#define ZALLOC(strm, items, size) \
slouken@521
   263
           (*((strm)->zalloc))((strm)->opaque, (items), (size))
slouken@521
   264
#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
slouken@521
   265
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
slouken@521
   266
slouken@521
   267
/* Reverse the bytes in a 32-bit value */
slouken@521
   268
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
slouken@521
   269
                    (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
slouken@521
   270
slouken@521
   271
#endif /* ZUTIL_H */