Path: blob/master/src/java.base/share/native/libzip/zlib/zutil.h
41153 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* zutil.h -- internal interface and configuration of the compression library25* Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler26* For conditions of distribution and use, see copyright notice in zlib.h27*/2829/* WARNING: this file should *not* be used by applications. It is30part of the implementation of the compression library and is31subject to change. Applications should only use zlib.h.32*/3334/* @(#) $Id$ */3536#ifndef ZUTIL_H37#define ZUTIL_H3839#ifdef HAVE_HIDDEN40# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))41#else42# define ZLIB_INTERNAL43#endif4445#include "zlib.h"4647#if defined(STDC) && !defined(Z_SOLO)48# if !(defined(_WIN32_WCE) && defined(_MSC_VER))49# include <stddef.h>50# endif51# include <string.h>52# include <stdlib.h>53#endif5455#ifdef Z_SOLO56typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */57#endif5859#ifndef local60# define local static61#endif62/* since "static" is used to mean two completely different things in C, we63define "local" for the non-static meaning of "static", for readability64(compile with -Dlocal if your debugger can't find static symbols) */6566typedef unsigned char uch;67typedef uch FAR uchf;68typedef unsigned short ush;69typedef ush FAR ushf;70typedef unsigned long ulg;7172extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */73/* (size given to avoid silly warnings with Visual C++) */7475#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]7677#define ERR_RETURN(strm,err) \78return (strm->msg = ERR_MSG(err), (err))79/* To be used only when the state is known to be valid */8081/* common constants */8283#ifndef DEF_WBITS84# define DEF_WBITS MAX_WBITS85#endif86/* default windowBits for decompression. MAX_WBITS is for compression only */8788#if MAX_MEM_LEVEL >= 889# define DEF_MEM_LEVEL 890#else91# define DEF_MEM_LEVEL MAX_MEM_LEVEL92#endif93/* default memLevel */9495#define STORED_BLOCK 096#define STATIC_TREES 197#define DYN_TREES 298/* The three kinds of block type */99100#define MIN_MATCH 3101#define MAX_MATCH 258102/* The minimum and maximum match lengths */103104#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */105106/* target dependencies */107108#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))109# define OS_CODE 0x00110# ifndef Z_SOLO111# if defined(__TURBOC__) || defined(__BORLANDC__)112# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))113/* Allow compilation with ANSI keywords only enabled */114void _Cdecl farfree( void *block );115void *_Cdecl farmalloc( unsigned long nbytes );116# else117# include <alloc.h>118# endif119# else /* MSC or DJGPP */120# include <malloc.h>121# endif122# endif123#endif124125#ifdef AMIGA126# define OS_CODE 1127#endif128129#if defined(VAXC) || defined(VMS)130# define OS_CODE 2131# define F_OPEN(name, mode) \132fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")133#endif134135#ifdef __370__136# if __TARGET_LIB__ < 0x20000000137# define OS_CODE 4138# elif __TARGET_LIB__ < 0x40000000139# define OS_CODE 11140# else141# define OS_CODE 8142# endif143#endif144145#if defined(ATARI) || defined(atarist)146# define OS_CODE 5147#endif148149#ifdef OS2150# define OS_CODE 6151# if defined(M_I86) && !defined(Z_SOLO)152# include <malloc.h>153# endif154#endif155156#if defined(MACOS) || defined(TARGET_OS_MAC)157# define OS_CODE 7158# ifndef Z_SOLO159# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os160# include <unix.h> /* for fdopen */161# else162# ifndef fdopen163# define fdopen(fd,mode) NULL /* No fdopen() */164# endif165# endif166# endif167#endif168169#ifdef __acorn170# define OS_CODE 13171#endif172173#if defined(WIN32) && !defined(__CYGWIN__)174# define OS_CODE 10175#endif176177#ifdef _BEOS_178# define OS_CODE 16179#endif180181#ifdef __TOS_OS400__182# define OS_CODE 18183#endif184185#ifdef __APPLE__186# define OS_CODE 19187#endif188189#if defined(_BEOS_) || defined(RISCOS)190# define fdopen(fd,mode) NULL /* No fdopen() */191#endif192193#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX194# if defined(_WIN32_WCE)195# define fdopen(fd,mode) NULL /* No fdopen() */196# ifndef _PTRDIFF_T_DEFINED197typedef int ptrdiff_t;198# define _PTRDIFF_T_DEFINED199# endif200# else201# define fdopen(fd,type) _fdopen(fd,type)202# endif203#endif204205#if defined(__BORLANDC__) && !defined(MSDOS)206#pragma warn -8004207#pragma warn -8008208#pragma warn -8066209#endif210211/* provide prototypes for these when building zlib without LFS */212#if !defined(_WIN32) && \213(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)214ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));215ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));216#endif217218/* common defaults */219220#ifndef OS_CODE221# define OS_CODE 3 /* assume Unix */222#endif223224#ifndef F_OPEN225# define F_OPEN(name, mode) fopen((name), (mode))226#endif227228/* functions */229230#if defined(pyr) || defined(Z_SOLO)231# define NO_MEMCPY232#endif233#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)234/* Use our own functions for small and medium model with MSC <= 5.0.235* You may have to use the same strategy for Borland C (untested).236* The __SC__ check is for Symantec.237*/238# define NO_MEMCPY239#endif240#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)241# define HAVE_MEMCPY242#endif243#ifdef HAVE_MEMCPY244# ifdef SMALL_MEDIUM /* MSDOS small or medium model */245# define zmemcpy _fmemcpy246# define zmemcmp _fmemcmp247# define zmemzero(dest, len) _fmemset(dest, 0, len)248# else249# define zmemcpy memcpy250# define zmemcmp memcmp251# define zmemzero(dest, len) memset(dest, 0, len)252# endif253#else254void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));255int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));256void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));257#endif258259/* Diagnostic functions */260#ifdef ZLIB_DEBUG261# include <stdio.h>262extern int ZLIB_INTERNAL z_verbose;263extern void ZLIB_INTERNAL z_error OF((char *m));264# define Assert(cond,msg) {if(!(cond)) z_error(msg);}265# define Trace(x) {if (z_verbose>=0) fprintf x ;}266# define Tracev(x) {if (z_verbose>0) fprintf x ;}267# define Tracevv(x) {if (z_verbose>1) fprintf x ;}268# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}269# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}270#else271# define Assert(cond,msg)272# define Trace(x)273# define Tracev(x)274# define Tracevv(x)275# define Tracec(c,x)276# define Tracecv(c,x)277#endif278279#ifndef Z_SOLO280voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,281unsigned size));282void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));283#endif284285#define ZALLOC(strm, items, size) \286(*((strm)->zalloc))((strm)->opaque, (items), (size))287#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))288#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}289290/* Reverse the bytes in a 32-bit value */291#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \292(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))293294#endif /* ZUTIL_H */295296297