199767f8919635c4928607450d9e0abb932109ceToomas Soome/* zutil.c -- target dependent utility functions for the compression library
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For conditions of distribution and use, see copyright notice in zlib.h
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* @(#) $Id$ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "zutil.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef Z_SOLO
199767f8919635c4928607450d9e0abb932109ceToomas Soome# include "gzguts.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO_DUMMY_DECL
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct internal_state {int dummy;}; /* for buggy compilers */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomez_const char * const z_errmsg[10] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome"need dictionary", /* Z_NEED_DICT 2 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"stream end", /* Z_STREAM_END 1 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"", /* Z_OK 0 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"file error", /* Z_ERRNO (-1) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"stream error", /* Z_STREAM_ERROR (-2) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"data error", /* Z_DATA_ERROR (-3) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"insufficient memory", /* Z_MEM_ERROR (-4) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"buffer error", /* Z_BUF_ERROR (-5) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome"incompatible version",/* Z_VERSION_ERROR (-6) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome""};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char * ZEXPORT zlibVersion()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ZLIB_VERSION;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeuLong ZEXPORT zlibCompileFlags()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome uLong flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch ((int)(sizeof(uInt))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 2: break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 4: flags += 1; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 8: flags += 2; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: flags += 3;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch ((int)(sizeof(uLong))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 2: break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 4: flags += 1 << 2; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 8: flags += 2 << 2; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: flags += 3 << 2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch ((int)(sizeof(voidpf))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 2: break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 4: flags += 1 << 4; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 8: flags += 2 << 4; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: flags += 3 << 4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch ((int)(sizeof(z_off_t))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 2: break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 4: flags += 1 << 6; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 8: flags += 2 << 6; break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: flags += 3 << 6;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1 << 8;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(ASMV) || defined(ASMINF)
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1 << 9;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef ZLIB_WINAPI
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1 << 10;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BUILDFIXED
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1 << 12;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef DYNAMIC_CRC_TABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1 << 13;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef NO_GZCOMPRESS
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 16;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef NO_GZIP
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 17;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef PKZIP_BUG_WORKAROUND
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 20;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef FASTEST
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 21;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(STDC) || defined(Z_HAVE_STDARG_H)
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef NO_vsnprintf
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 25;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef HAS_vsprintf_void
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 26;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome# else
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef HAS_vsnprintf_void
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 26;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 24;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef NO_snprintf
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 25;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef HAS_sprintf_void
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 26;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome# else
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifdef HAS_snprintf_void
199767f8919635c4928607450d9e0abb932109ceToomas Soome flags += 1L << 26;
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome return flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# ifndef verbose
199767f8919635c4928607450d9e0abb932109ceToomas Soome# define verbose 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome# endif
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint ZLIB_INTERNAL z_verbose = verbose;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL z_error (m)
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *m;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome fprintf(stderr, "%s\n", m);
199767f8919635c4928607450d9e0abb932109ceToomas Soome exit(1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* exported to allow conversion of error code to string for compress() and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * uncompress()
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char * ZEXPORT zError(err)
199767f8919635c4928607450d9e0abb932109ceToomas Soome int err;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ERR_MSG(err);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(_WIN32_WCE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* The Microsoft C Run-Time Library for Windows CE doesn't have
199767f8919635c4928607450d9e0abb932109ceToomas Soome * errno. We define it as a global variable to simplify porting.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Its value is always 0 and should not be used.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int errno = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef HAVE_MEMCPY
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL zmemcpy(dest, source, len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome Bytef* dest;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const Bytef* source;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uInt len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (len == 0) return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome do {
199767f8919635c4928607450d9e0abb932109ceToomas Soome *dest++ = *source++; /* ??? to be unrolled */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } while (--len != 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint ZLIB_INTERNAL zmemcmp(s1, s2, len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome const Bytef* s1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const Bytef* s2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uInt len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome uInt j;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; j < len; j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL zmemzero(dest, len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome Bytef* dest;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uInt len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (len == 0) return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome do {
199767f8919635c4928607450d9e0abb932109ceToomas Soome *dest++ = 0; /* ??? to be unrolled */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } while (--len != 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef Z_SOLO
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef SYS16BIT
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __TURBOC__
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Turbo C in 16-bit mode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# define MY_ZCALLOC
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and farmalloc(64K) returns a pointer with an offset of 8, so we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * must fix the pointer. Warning: the pointer must be put back to its
199767f8919635c4928607450d9e0abb932109ceToomas Soome * original form in order to free it, use zcfree().
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MAX_PTR 10
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* 10*64K = 640K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomelocal int next_ptr = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct ptr_table_s {
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf org_ptr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf new_ptr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} ptr_table;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomelocal ptr_table table[MAX_PTR];
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* This table is used to remember the original form of pointers
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to large buffers (64K). Such pointers are normalized with a zero offset.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Since MSDOS is not a preemptive multitasking OS, this table is not
199767f8919635c4928607450d9e0abb932109ceToomas Soome * protected from concurrent access. This hack doesn't work anyway on
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a protected system like OS/2. Use Microsoft C instead.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf buf = opaque; /* just to make some compilers happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ulg bsize = (ulg)items*size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* If we allocate less than 65520 bytes, we assume that farmalloc
199767f8919635c4928607450d9e0abb932109ceToomas Soome * will return a usable pointer which doesn't have to be normalized.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bsize < 65520L) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome buf = farmalloc(bsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*(ush*)&buf != 0) return buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome buf = farmalloc(bsize + 16L);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome table[next_ptr].org_ptr = buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Normalize the pointer to seg:0 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome *(ush*)&buf = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome table[next_ptr++].new_ptr = buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome return buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int n;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*(ush*)&ptr != 0) { /* object < 64K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome farfree(ptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Find the original pointer */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (n = 0; n < next_ptr; n++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (ptr != table[n].new_ptr) continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome farfree(table[n].org_ptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (++n < next_ptr) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome table[n-1] = table[n];
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome next_ptr--;
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome ptr = opaque; /* just to make some compilers happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome Assert(0, "zcfree: ptr not found");
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __TURBOC__ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef M_I86
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Microsoft C in 16-bit mode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# define MY_ZCALLOC
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
199767f8919635c4928607450d9e0abb932109ceToomas Soome# define _halloc halloc
199767f8919635c4928607450d9e0abb932109ceToomas Soome# define _hfree hfree
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (opaque) opaque = 0; /* to make compiler happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return _halloc((long)items, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (opaque) opaque = 0; /* to make compiler happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome _hfree(ptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* M_I86 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* SYS16BIT */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef MY_ZCALLOC /* Any system without a special alloc function */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef STDC
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern voidp malloc OF((uInt size));
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern voidp calloc OF((uInt items, uInt size));
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void free OF((voidpf ptr));
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf opaque;
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned items;
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (opaque) items += size - size; /* make compiler happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
199767f8919635c4928607450d9e0abb932109ceToomas Soome (voidpf)calloc(items, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid ZLIB_INTERNAL zcfree (opaque, ptr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf opaque;
199767f8919635c4928607450d9e0abb932109ceToomas Soome voidpf ptr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(ptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (opaque) return; /* make compiler happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* MY_ZCALLOC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !Z_SOLO */