zutil.c (muscle7.61) | : | zutil.c (muscle7.62) | ||
---|---|---|---|---|
/* zutil.c -- target dependent utility functions for the compression library | /* zutil.c -- target dependent utility functions for the compression library | |||
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. | * Copyright (C) 1995-2017 Jean-loup Gailly | |||
* For conditions of distribution and use, see copyright notice in zlib.h | * For conditions of distribution and use, see copyright notice in zlib.h | |||
*/ | */ | |||
/* @(#) $Id$ */ | /* @(#) $Id$ */ | |||
#include "zutil.h" | #include "zutil.h" | |||
#ifndef Z_SOLO | #ifndef Z_SOLO | |||
# include "gzguts.h" | # include "gzguts.h" | |||
#endif | #endif | |||
#ifndef NO_DUMMY_DECL | ||||
struct internal_state {int dummy;}; /* for buggy compilers */ | ||||
#endif | ||||
z_const char * const z_errmsg[10] = { | z_const char * const z_errmsg[10] = { | |||
"need dictionary", /* Z_NEED_DICT 2 */ | (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ | |||
"stream end", /* Z_STREAM_END 1 */ | (z_const char *)"stream end", /* Z_STREAM_END 1 */ | |||
"", /* Z_OK 0 */ | (z_const char *)"", /* Z_OK 0 */ | |||
"file error", /* Z_ERRNO (-1) */ | (z_const char *)"file error", /* Z_ERRNO (-1) */ | |||
"stream error", /* Z_STREAM_ERROR (-2) */ | (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ | |||
"data error", /* Z_DATA_ERROR (-3) */ | (z_const char *)"data error", /* Z_DATA_ERROR (-3) */ | |||
"insufficient memory", /* Z_MEM_ERROR (-4) */ | (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ | |||
"buffer error", /* Z_BUF_ERROR (-5) */ | (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ | |||
"incompatible version",/* Z_VERSION_ERROR (-6) */ | (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ | |||
""}; | (z_const char *)"" | |||
}; | ||||
const char * ZEXPORT zlibVersion() | const char * ZEXPORT zlibVersion() | |||
{ | { | |||
return ZLIB_VERSION; | return ZLIB_VERSION; | |||
} | } | |||
uLong ZEXPORT zlibCompileFlags() | uLong ZEXPORT zlibCompileFlags() | |||
{ | { | |||
uLong flags; | uLong flags; | |||
skipping to change at line 63 | skipping to change at line 60 | |||
case 4: flags += 1 << 4; break; | case 4: flags += 1 << 4; break; | |||
case 8: flags += 2 << 4; break; | case 8: flags += 2 << 4; break; | |||
default: flags += 3 << 4; | default: flags += 3 << 4; | |||
} | } | |||
switch ((int)(sizeof(z_off_t))) { | switch ((int)(sizeof(z_off_t))) { | |||
case 2: break; | case 2: break; | |||
case 4: flags += 1 << 6; break; | case 4: flags += 1 << 6; break; | |||
case 8: flags += 2 << 6; break; | case 8: flags += 2 << 6; break; | |||
default: flags += 3 << 6; | default: flags += 3 << 6; | |||
} | } | |||
#ifdef DEBUG | #ifdef ZLIB_DEBUG | |||
flags += 1 << 8; | flags += 1 << 8; | |||
#endif | #endif | |||
#if defined(ASMV) || defined(ASMINF) | #if defined(ASMV) || defined(ASMINF) | |||
flags += 1 << 9; | flags += 1 << 9; | |||
#endif | #endif | |||
#ifdef ZLIB_WINAPI | #ifdef ZLIB_WINAPI | |||
flags += 1 << 10; | flags += 1 << 10; | |||
#endif | #endif | |||
#ifdef BUILDFIXED | #ifdef BUILDFIXED | |||
flags += 1 << 12; | flags += 1 << 12; | |||
skipping to change at line 117 | skipping to change at line 114 | |||
# endif | # endif | |||
# else | # else | |||
# ifdef HAS_snprintf_void | # ifdef HAS_snprintf_void | |||
flags += 1L << 26; | flags += 1L << 26; | |||
# endif | # endif | |||
# endif | # endif | |||
#endif | #endif | |||
return flags; | return flags; | |||
} | } | |||
#ifdef DEBUG | #ifdef ZLIB_DEBUG | |||
#include <stdlib.h> | ||||
# ifndef verbose | # ifndef verbose | |||
# define verbose 0 | # define verbose 0 | |||
# endif | # endif | |||
int ZLIB_INTERNAL z_verbose = verbose; | int ZLIB_INTERNAL z_verbose = verbose; | |||
void ZLIB_INTERNAL z_error (m) | void ZLIB_INTERNAL z_error (m) | |||
char *m; | char *m; | |||
{ | { | |||
fprintf(stderr, "%s\n", m); | fprintf(stderr, "%s\n", m); | |||
exit(1); | exit(1); | |||
skipping to change at line 221 | skipping to change at line 218 | |||
local ptr_table table[MAX_PTR]; | local ptr_table table[MAX_PTR]; | |||
/* This table is used to remember the original form of pointers | /* This table is used to remember the original form of pointers | |||
* to large buffers (64K). Such pointers are normalized with a zero offset. | * to large buffers (64K). Such pointers are normalized with a zero offset. | |||
* Since MSDOS is not a preemptive multitasking OS, this table is not | * Since MSDOS is not a preemptive multitasking OS, this table is not | |||
* protected from concurrent access. This hack doesn't work anyway on | * protected from concurrent access. This hack doesn't work anyway on | |||
* a protected system like OS/2. Use Microsoft C instead. | * a protected system like OS/2. Use Microsoft C instead. | |||
*/ | */ | |||
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) | |||
{ | { | |||
voidpf buf = opaque; /* just to make some compilers happy */ | voidpf buf; | |||
ulg bsize = (ulg)items*size; | ulg bsize = (ulg)items*size; | |||
(void)opaque; | ||||
/* If we allocate less than 65520 bytes, we assume that farmalloc | /* If we allocate less than 65520 bytes, we assume that farmalloc | |||
* will return a usable pointer which doesn't have to be normalized. | * will return a usable pointer which doesn't have to be normalized. | |||
*/ | */ | |||
if (bsize < 65520L) { | if (bsize < 65520L) { | |||
buf = farmalloc(bsize); | buf = farmalloc(bsize); | |||
if (*(ush*)&buf != 0) return buf; | if (*(ush*)&buf != 0) return buf; | |||
} else { | } else { | |||
buf = farmalloc(bsize + 16L); | buf = farmalloc(bsize + 16L); | |||
} | } | |||
if (buf == NULL || next_ptr >= MAX_PTR) return NULL; | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; | |||
skipping to change at line 246 | skipping to change at line 245 | |||
/* Normalize the pointer to seg:0 */ | /* Normalize the pointer to seg:0 */ | |||
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; | |||
*(ush*)&buf = 0; | *(ush*)&buf = 0; | |||
table[next_ptr++].new_ptr = buf; | table[next_ptr++].new_ptr = buf; | |||
return buf; | return buf; | |||
} | } | |||
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | |||
{ | { | |||
int n; | int n; | |||
(void)opaque; | ||||
if (*(ush*)&ptr != 0) { /* object < 64K */ | if (*(ush*)&ptr != 0) { /* object < 64K */ | |||
farfree(ptr); | farfree(ptr); | |||
return; | return; | |||
} | } | |||
/* Find the original pointer */ | /* Find the original pointer */ | |||
for (n = 0; n < next_ptr; n++) { | for (n = 0; n < next_ptr; n++) { | |||
if (ptr != table[n].new_ptr) continue; | if (ptr != table[n].new_ptr) continue; | |||
farfree(table[n].org_ptr); | farfree(table[n].org_ptr); | |||
while (++n < next_ptr) { | while (++n < next_ptr) { | |||
table[n-1] = table[n]; | table[n-1] = table[n]; | |||
} | } | |||
next_ptr--; | next_ptr--; | |||
return; | return; | |||
} | } | |||
ptr = opaque; /* just to make some compilers happy */ | ||||
Assert(0, "zcfree: ptr not found"); | Assert(0, "zcfree: ptr not found"); | |||
} | } | |||
#endif /* __TURBOC__ */ | #endif /* __TURBOC__ */ | |||
#ifdef M_I86 | #ifdef M_I86 | |||
/* Microsoft C in 16-bit mode */ | /* Microsoft C in 16-bit mode */ | |||
# define MY_ZCALLOC | # define MY_ZCALLOC | |||
#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) | |||
# define _halloc halloc | # define _halloc halloc | |||
# define _hfree hfree | # define _hfree hfree | |||
#endif | #endif | |||
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) | |||
{ | { | |||
if (opaque) opaque = 0; /* to make compiler happy */ | (void)opaque; | |||
return _halloc((long)items, size); | return _halloc((long)items, size); | |||
} | } | |||
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | |||
{ | { | |||
if (opaque) opaque = 0; /* to make compiler happy */ | (void)opaque; | |||
_hfree(ptr); | _hfree(ptr); | |||
} | } | |||
#endif /* M_I86 */ | #endif /* M_I86 */ | |||
#endif /* SYS16BIT */ | #endif /* SYS16BIT */ | |||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ | |||
#ifndef STDC | #ifndef STDC | |||
extern voidp malloc OF((uInt size)); | extern voidp malloc OF((uInt size)); | |||
extern voidp calloc OF((uInt items, uInt size)); | extern voidp calloc OF((uInt items, uInt size)); | |||
extern void free OF((voidpf ptr)); | extern void free OF((voidpf ptr)); | |||
#endif | #endif | |||
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) | |||
voidpf opaque; | voidpf opaque; | |||
unsigned items; | unsigned items; | |||
unsigned size; | unsigned size; | |||
{ | { | |||
if (opaque) items += size - size; /* make compiler happy */ | (void)opaque; | |||
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : | |||
(voidpf)calloc(items, size); | (voidpf)calloc(items, size); | |||
} | } | |||
void ZLIB_INTERNAL zcfree (opaque, ptr) | void ZLIB_INTERNAL zcfree (opaque, ptr) | |||
voidpf opaque; | voidpf opaque; | |||
voidpf ptr; | voidpf ptr; | |||
{ | { | |||
(void)opaque; | ||||
free(ptr); | free(ptr); | |||
if (opaque) return; /* make compiler happy */ | ||||
} | } | |||
#endif /* MY_ZCALLOC */ | #endif /* MY_ZCALLOC */ | |||
#endif /* !Z_SOLO */ | #endif /* !Z_SOLO */ | |||
End of changes. 14 change blocks. | ||||
24 lines changed or deleted | 25 lines changed or added |