jdk/src/java.base/share/native/libzip/zlib-1.2.8/zutil.h
changeset 43880 b5015f742ba6
parent 43879 a6dc784b18a8
parent 43854 76c52ad1e6c7
child 43881 4d99ca794b88
equal deleted inserted replaced
43879:a6dc784b18a8 43880:b5015f742ba6
     1 /*
       
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.  Oracle designates this
       
     7  * particular file as subject to the "Classpath" exception as provided
       
     8  * by Oracle in the LICENSE file that accompanied this code.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  */
       
    24 
       
    25 /* zutil.h -- internal interface and configuration of the compression library
       
    26  * Copyright (C) 1995-2013 Jean-loup Gailly.
       
    27  * For conditions of distribution and use, see copyright notice in zlib.h
       
    28  */
       
    29 
       
    30 /* WARNING: this file should *not* be used by applications. It is
       
    31    part of the implementation of the compression library and is
       
    32    subject to change. Applications should only use zlib.h.
       
    33  */
       
    34 
       
    35 /* @(#) $Id$ */
       
    36 
       
    37 #ifndef ZUTIL_H
       
    38 #define ZUTIL_H
       
    39 
       
    40 #ifdef HAVE_HIDDEN
       
    41 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
       
    42 #else
       
    43 #  define ZLIB_INTERNAL
       
    44 #endif
       
    45 
       
    46 #include "zlib.h"
       
    47 
       
    48 #if defined(STDC) && !defined(Z_SOLO)
       
    49 #  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
       
    50 #    include <stddef.h>
       
    51 #  endif
       
    52 #  include <string.h>
       
    53 #  include <stdlib.h>
       
    54 #endif
       
    55 
       
    56 #ifdef Z_SOLO
       
    57    typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
       
    58 #endif
       
    59 
       
    60 #ifndef local
       
    61 #  define local static
       
    62 #endif
       
    63 /* compile with -Dlocal if your debugger can't find static symbols */
       
    64 
       
    65 typedef unsigned char  uch;
       
    66 typedef uch FAR uchf;
       
    67 typedef unsigned short ush;
       
    68 typedef ush FAR ushf;
       
    69 typedef unsigned long  ulg;
       
    70 
       
    71 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
       
    72 /* (size given to avoid silly warnings with Visual C++) */
       
    73 
       
    74 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
       
    75 
       
    76 #define ERR_RETURN(strm,err) \
       
    77   return (strm->msg = ERR_MSG(err), (err))
       
    78 /* To be used only when the state is known to be valid */
       
    79 
       
    80         /* common constants */
       
    81 
       
    82 #ifndef DEF_WBITS
       
    83 #  define DEF_WBITS MAX_WBITS
       
    84 #endif
       
    85 /* default windowBits for decompression. MAX_WBITS is for compression only */
       
    86 
       
    87 #if MAX_MEM_LEVEL >= 8
       
    88 #  define DEF_MEM_LEVEL 8
       
    89 #else
       
    90 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
       
    91 #endif
       
    92 /* default memLevel */
       
    93 
       
    94 #define STORED_BLOCK 0
       
    95 #define STATIC_TREES 1
       
    96 #define DYN_TREES    2
       
    97 /* The three kinds of block type */
       
    98 
       
    99 #define MIN_MATCH  3
       
   100 #define MAX_MATCH  258
       
   101 /* The minimum and maximum match lengths */
       
   102 
       
   103 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
       
   104 
       
   105         /* target dependencies */
       
   106 
       
   107 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
       
   108 #  define OS_CODE  0x00
       
   109 #  ifndef Z_SOLO
       
   110 #    if defined(__TURBOC__) || defined(__BORLANDC__)
       
   111 #      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
       
   112          /* Allow compilation with ANSI keywords only enabled */
       
   113          void _Cdecl farfree( void *block );
       
   114          void *_Cdecl farmalloc( unsigned long nbytes );
       
   115 #      else
       
   116 #        include <alloc.h>
       
   117 #      endif
       
   118 #    else /* MSC or DJGPP */
       
   119 #      include <malloc.h>
       
   120 #    endif
       
   121 #  endif
       
   122 #endif
       
   123 
       
   124 #ifdef AMIGA
       
   125 #  define OS_CODE  0x01
       
   126 #endif
       
   127 
       
   128 #if defined(VAXC) || defined(VMS)
       
   129 #  define OS_CODE  0x02
       
   130 #  define F_OPEN(name, mode) \
       
   131      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
       
   132 #endif
       
   133 
       
   134 #if defined(ATARI) || defined(atarist)
       
   135 #  define OS_CODE  0x05
       
   136 #endif
       
   137 
       
   138 #ifdef OS2
       
   139 #  define OS_CODE  0x06
       
   140 #  if defined(M_I86) && !defined(Z_SOLO)
       
   141 #    include <malloc.h>
       
   142 #  endif
       
   143 #endif
       
   144 
       
   145 #if defined(MACOS) || defined(TARGET_OS_MAC)
       
   146 #  define OS_CODE  0x07
       
   147 #  ifndef Z_SOLO
       
   148 #    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
       
   149 #      include <unix.h> /* for fdopen */
       
   150 #    else
       
   151 #      ifndef fdopen
       
   152 #        define fdopen(fd,mode) NULL /* No fdopen() */
       
   153 #      endif
       
   154 #    endif
       
   155 #  endif
       
   156 #endif
       
   157 
       
   158 #ifdef TOPS20
       
   159 #  define OS_CODE  0x0a
       
   160 #endif
       
   161 
       
   162 #ifdef WIN32
       
   163 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
       
   164 #    define OS_CODE  0x0b
       
   165 #  endif
       
   166 #endif
       
   167 
       
   168 #ifdef __50SERIES /* Prime/PRIMOS */
       
   169 #  define OS_CODE  0x0f
       
   170 #endif
       
   171 
       
   172 #if defined(_BEOS_) || defined(RISCOS)
       
   173 #  define fdopen(fd,mode) NULL /* No fdopen() */
       
   174 #endif
       
   175 
       
   176 #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
       
   177 #  if defined(_WIN32_WCE)
       
   178 #    define fdopen(fd,mode) NULL /* No fdopen() */
       
   179 #    ifndef _PTRDIFF_T_DEFINED
       
   180        typedef int ptrdiff_t;
       
   181 #      define _PTRDIFF_T_DEFINED
       
   182 #    endif
       
   183 #  else
       
   184 #    define fdopen(fd,type)  _fdopen(fd,type)
       
   185 #  endif
       
   186 #endif
       
   187 
       
   188 #if defined(__BORLANDC__) && !defined(MSDOS)
       
   189   #pragma warn -8004
       
   190   #pragma warn -8008
       
   191   #pragma warn -8066
       
   192 #endif
       
   193 
       
   194 /* provide prototypes for these when building zlib without LFS */
       
   195 #if !defined(_WIN32) && \
       
   196     (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
       
   197     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
       
   198     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
       
   199 #endif
       
   200 
       
   201         /* common defaults */
       
   202 
       
   203 #ifndef OS_CODE
       
   204 #  define OS_CODE  0x03  /* assume Unix */
       
   205 #endif
       
   206 
       
   207 #ifndef F_OPEN
       
   208 #  define F_OPEN(name, mode) fopen((name), (mode))
       
   209 #endif
       
   210 
       
   211          /* functions */
       
   212 
       
   213 #if defined(pyr) || defined(Z_SOLO)
       
   214 #  define NO_MEMCPY
       
   215 #endif
       
   216 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
       
   217  /* Use our own functions for small and medium model with MSC <= 5.0.
       
   218   * You may have to use the same strategy for Borland C (untested).
       
   219   * The __SC__ check is for Symantec.
       
   220   */
       
   221 #  define NO_MEMCPY
       
   222 #endif
       
   223 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
       
   224 #  define HAVE_MEMCPY
       
   225 #endif
       
   226 #ifdef HAVE_MEMCPY
       
   227 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
       
   228 #    define zmemcpy _fmemcpy
       
   229 #    define zmemcmp _fmemcmp
       
   230 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
       
   231 #  else
       
   232 #    define zmemcpy memcpy
       
   233 #    define zmemcmp memcmp
       
   234 #    define zmemzero(dest, len) memset(dest, 0, len)
       
   235 #  endif
       
   236 #else
       
   237    void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
       
   238    int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
       
   239    void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
       
   240 #endif
       
   241 
       
   242 /* Diagnostic functions */
       
   243 #ifdef DEBUG
       
   244 #  include <stdio.h>
       
   245    extern int ZLIB_INTERNAL z_verbose;
       
   246    extern void ZLIB_INTERNAL z_error OF((char *m));
       
   247 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
       
   248 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
       
   249 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
       
   250 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
       
   251 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
       
   252 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
       
   253 #else
       
   254 #  define Assert(cond,msg)
       
   255 #  define Trace(x)
       
   256 #  define Tracev(x)
       
   257 #  define Tracevv(x)
       
   258 #  define Tracec(c,x)
       
   259 #  define Tracecv(c,x)
       
   260 #endif
       
   261 
       
   262 #ifndef Z_SOLO
       
   263    voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
       
   264                                     unsigned size));
       
   265    void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
       
   266 #endif
       
   267 
       
   268 #define ZALLOC(strm, items, size) \
       
   269            (*((strm)->zalloc))((strm)->opaque, (items), (size))
       
   270 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
       
   271 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
       
   272 
       
   273 /* Reverse the bytes in a 32-bit value */
       
   274 #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
       
   275                     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
       
   276 
       
   277 #endif /* ZUTIL_H */