summaryrefslogtreecommitdiff
path: root/libs/zlib/src/zutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/zlib/src/zutil.c')
-rw-r--r--libs/zlib/src/zutil.c375
1 files changed, 189 insertions, 186 deletions
diff --git a/libs/zlib/src/zutil.c b/libs/zlib/src/zutil.c
index f0fef231f2..ac3c9871ba 100644
--- a/libs/zlib/src/zutil.c
+++ b/libs/zlib/src/zutil.c
@@ -14,105 +14,106 @@
struct internal_state {int dummy;}; /* for buggy compilers */
#endif
-z_const char * const z_errmsg[10] = {
-"need dictionary", /* Z_NEED_DICT 2 */
-"stream end", /* Z_STREAM_END 1 */
-"", /* Z_OK 0 */
-"file error", /* Z_ERRNO (-1) */
-"stream error", /* Z_STREAM_ERROR (-2) */
-"data error", /* Z_DATA_ERROR (-3) */
-"insufficient memory", /* Z_MEM_ERROR (-4) */
-"buffer error", /* Z_BUF_ERROR (-5) */
-"incompatible version",/* Z_VERSION_ERROR (-6) */
-""};
-
+z_const char * const z_errmsg[10] =
+{
+ "need dictionary", /* Z_NEED_DICT 2 */
+ "stream end", /* Z_STREAM_END 1 */
+ "", /* Z_OK 0 */
+ "file error", /* Z_ERRNO (-1) */
+ "stream error", /* Z_STREAM_ERROR (-2) */
+ "data error", /* Z_DATA_ERROR (-3) */
+ "insufficient memory", /* Z_MEM_ERROR (-4) */
+ "buffer error", /* Z_BUF_ERROR (-5) */
+ "incompatible version",/* Z_VERSION_ERROR (-6) */
+ ""
+};
const char * ZEXPORT zlibVersion()
{
- return ZLIB_VERSION;
+ return ZLIB_VERSION;
}
uLong ZEXPORT zlibCompileFlags()
{
- uLong flags;
-
- flags = 0;
- switch (sizeof(uInt)) {
- case 2: break;
- case 4: flags += 1; break;
- case 8: flags += 2; break;
- default: flags += 3;
- }
- switch (sizeof(uLong)) {
- case 2: break;
- case 4: flags += 1 << 2; break;
- case 8: flags += 2 << 2; break;
- default: flags += 3 << 2;
- }
- switch (sizeof(voidpf)) {
- case 2: break;
- case 4: flags += 1 << 4; break;
- case 8: flags += 2 << 4; break;
- default: flags += 3 << 4;
- }
- switch (sizeof(z_off_t)) {
- case 2: break;
- case 4: flags += 1 << 6; break;
- case 8: flags += 2 << 6; break;
- default: flags += 3 << 6;
- }
-#ifdef DEBUG
- flags += 1 << 8;
-#endif
-#if defined(ASMV) || defined(ASMINF)
- flags += 1 << 9;
-#endif
-#ifdef ZLIB_WINAPI
- flags += 1 << 10;
-#endif
-#ifdef BUILDFIXED
- flags += 1 << 12;
-#endif
-#ifdef DYNAMIC_CRC_TABLE
- flags += 1 << 13;
-#endif
-#ifdef NO_GZCOMPRESS
- flags += 1L << 16;
-#endif
-#ifdef NO_GZIP
- flags += 1L << 17;
-#endif
-#ifdef PKZIP_BUG_WORKAROUND
- flags += 1L << 20;
-#endif
-#ifdef FASTEST
- flags += 1L << 21;
-#endif
-#if defined(STDC) || defined(Z_HAVE_STDARG_H)
-# ifdef NO_vsnprintf
- flags += 1L << 25;
-# ifdef HAS_vsprintf_void
- flags += 1L << 26;
-# endif
-# else
-# ifdef HAS_vsnprintf_void
- flags += 1L << 26;
-# endif
-# endif
-#else
- flags += 1L << 24;
-# ifdef NO_snprintf
- flags += 1L << 25;
-# ifdef HAS_sprintf_void
- flags += 1L << 26;
-# endif
-# else
-# ifdef HAS_snprintf_void
- flags += 1L << 26;
-# endif
-# endif
-#endif
- return flags;
+ uLong flags;
+
+ flags = 0;
+ switch (sizeof(uInt)) {
+ case 2: break;
+ case 4: flags += 1; break;
+ case 8: flags += 2; break;
+ default: flags += 3;
+ }
+ switch (sizeof(uLong)) {
+ case 2: break;
+ case 4: flags += 1 << 2; break;
+ case 8: flags += 2 << 2; break;
+ default: flags += 3 << 2;
+ }
+ switch (sizeof(voidpf)) {
+ case 2: break;
+ case 4: flags += 1 << 4; break;
+ case 8: flags += 2 << 4; break;
+ default: flags += 3 << 4;
+ }
+ switch (sizeof(z_off_t)) {
+ case 2: break;
+ case 4: flags += 1 << 6; break;
+ case 8: flags += 2 << 6; break;
+ default: flags += 3 << 6;
+ }
+ #ifdef DEBUG
+ flags += 1 << 8;
+ #endif
+ #if defined(ASMV) || defined(ASMINF)
+ flags += 1 << 9;
+ #endif
+ #ifdef ZLIB_WINAPI
+ flags += 1 << 10;
+ #endif
+ #ifdef BUILDFIXED
+ flags += 1 << 12;
+ #endif
+ #ifdef DYNAMIC_CRC_TABLE
+ flags += 1 << 13;
+ #endif
+ #ifdef NO_GZCOMPRESS
+ flags += 1L << 16;
+ #endif
+ #ifdef NO_GZIP
+ flags += 1L << 17;
+ #endif
+ #ifdef PKZIP_BUG_WORKAROUND
+ flags += 1L << 20;
+ #endif
+ #ifdef FASTEST
+ flags += 1L << 21;
+ #endif
+ #if defined(STDC) || defined(Z_HAVE_STDARG_H)
+ # ifdef NO_vsnprintf
+ flags += 1L << 25;
+ # ifdef HAS_vsprintf_void
+ flags += 1L << 26;
+ # endif
+ # else
+ # ifdef HAS_vsnprintf_void
+ flags += 1L << 26;
+ # endif
+ # endif
+ #else
+ flags += 1L << 24;
+ # ifdef NO_snprintf
+ flags += 1L << 25;
+ # ifdef HAS_sprintf_void
+ flags += 1L << 26;
+ # endif
+ # else
+ # ifdef HAS_snprintf_void
+ flags += 1L << 26;
+ # endif
+ # endif
+ #endif
+ return flags;
}
#ifdef DEBUG
@@ -122,11 +123,11 @@ uLong ZEXPORT zlibCompileFlags()
# endif
int ZLIB_INTERNAL z_verbose = verbose;
-void ZLIB_INTERNAL z_error (m)
- char *m;
+void ZLIB_INTERNAL z_error(m)
+char *m;
{
- fprintf(stderr, "%s\n", m);
- exit(1);
+ fprintf(stderr, "%s\n", m);
+ exit(1);
}
#endif
@@ -134,53 +135,53 @@ void ZLIB_INTERNAL z_error (m)
* uncompress()
*/
const char * ZEXPORT zError(err)
- int err;
+int err;
{
- return ERR_MSG(err);
+ return ERR_MSG(err);
}
#if defined(_WIN32_WCE)
- /* The Microsoft C Run-Time Library for Windows CE doesn't have
- * errno. We define it as a global variable to simplify porting.
- * Its value is always 0 and should not be used.
- */
- int errno = 0;
+/* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used.
+ */
+int errno = 0;
#endif
#ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(dest, source, len)
- Bytef* dest;
- const Bytef* source;
- uInt len;
+Bytef* dest;
+const Bytef* source;
+uInt len;
{
- if (len == 0) return;
- do {
- *dest++ = *source++; /* ??? to be unrolled */
- } while (--len != 0);
+ if (len == 0) return;
+ do {
+ *dest++ = *source++; /* ??? to be unrolled */
+ } while (--len != 0);
}
int ZLIB_INTERNAL zmemcmp(s1, s2, len)
- const Bytef* s1;
- const Bytef* s2;
- uInt len;
+const Bytef* s1;
+const Bytef* s2;
+uInt len;
{
- uInt j;
+ uInt j;
- for (j = 0; j < len; j++) {
- if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
- }
- return 0;
+ for (j = 0; j < len; j++) {
+ if (s1[j] != s2[j]) return 2 * (s1[j] > s2[j]) - 1;
+ }
+ return 0;
}
void ZLIB_INTERNAL zmemzero(dest, len)
- Bytef* dest;
- uInt len;
+Bytef* dest;
+uInt len;
{
- if (len == 0) return;
- do {
- *dest++ = 0; /* ??? to be unrolled */
- } while (--len != 0);
+ if (len == 0) return;
+ do {
+ *dest++ = 0; /* ??? to be unrolled */
+ } while (--len != 0);
}
#endif
@@ -200,13 +201,14 @@ void ZLIB_INTERNAL zmemzero(dest, len)
*/
#define MAX_PTR 10
-/* 10*64K = 640K */
+ /* 10*64K = 640K */
local int next_ptr = 0;
-typedef struct ptr_table_s {
- voidpf org_ptr;
- voidpf new_ptr;
+typedef struct ptr_table_s
+{
+ voidpf org_ptr;
+ voidpf new_ptr;
} ptr_table;
local ptr_table table[MAX_PTR];
@@ -217,50 +219,51 @@ local ptr_table table[MAX_PTR];
* 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 */
- ulg bsize = (ulg)items*size;
-
- /* If we allocate less than 65520 bytes, we assume that farmalloc
- * will return a usable pointer which doesn't have to be normalized.
- */
- if (bsize < 65520L) {
- buf = farmalloc(bsize);
- if (*(ush*)&buf != 0) return buf;
- } else {
- buf = farmalloc(bsize + 16L);
- }
- if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
- table[next_ptr].org_ptr = buf;
-
- /* Normalize the pointer to seg:0 */
- *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
- *(ush*)&buf = 0;
- table[next_ptr++].new_ptr = buf;
- return buf;
+ voidpf buf = opaque; /* just to make some compilers happy */
+ ulg bsize = (ulg)items*size;
+
+ /* If we allocate less than 65520 bytes, we assume that farmalloc
+ * will return a usable pointer which doesn't have to be normalized.
+ */
+ if (bsize < 65520L) {
+ buf = farmalloc(bsize);
+ if (*(ush*)&buf != 0) return buf;
+ }
+ else {
+ buf = farmalloc(bsize + 16L);
+ }
+ if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+ table[next_ptr].org_ptr = buf;
+
+ /* Normalize the pointer to seg:0 */
+ *((ush*)&buf + 1) += ((ush)((uch*)buf - 0) + 15) >> 4;
+ *(ush*)&buf = 0;
+ table[next_ptr++].new_ptr = buf;
+ return buf;
}
-void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
+void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
{
- int n;
- if (*(ush*)&ptr != 0) { /* object < 64K */
- farfree(ptr);
- return;
- }
- /* Find the original pointer */
- for (n = 0; n < next_ptr; n++) {
- if (ptr != table[n].new_ptr) continue;
-
- farfree(table[n].org_ptr);
- while (++n < next_ptr) {
- table[n-1] = table[n];
- }
- next_ptr--;
- return;
- }
- ptr = opaque; /* just to make some compilers happy */
- Assert(0, "zcfree: ptr not found");
+ int n;
+ if (*(ush*)&ptr != 0) { /* object < 64K */
+ farfree(ptr);
+ return;
+ }
+ /* Find the original pointer */
+ for (n = 0; n < next_ptr; n++) {
+ if (ptr != table[n].new_ptr) continue;
+
+ farfree(table[n].org_ptr);
+ while (++n < next_ptr) {
+ table[n - 1] = table[n];
+ }
+ next_ptr--;
+ return;
+ }
+ ptr = opaque; /* just to make some compilers happy */
+ Assert(0, "zcfree: ptr not found");
}
#endif /* __TURBOC__ */
@@ -276,16 +279,16 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
# define _hfree hfree
#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 */
- return _halloc((long)items, size);
+ if (opaque) opaque = 0; /* to make compiler happy */
+ 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 */
- _hfree(ptr);
+ if (opaque) opaque = 0; /* to make compiler happy */
+ _hfree(ptr);
}
#endif /* M_I86 */
@@ -301,22 +304,22 @@ extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr));
#endif
-voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
- voidpf opaque;
- unsigned items;
- unsigned size;
+voidpf ZLIB_INTERNAL zcalloc(opaque, items, size)
+voidpf opaque;
+unsigned items;
+unsigned size;
{
- if (opaque) items += size - size; /* make compiler happy */
- return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
- (voidpf)calloc(items, size);
+ if (opaque) items += size - size; /* make compiler happy */
+ return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
+ (voidpf)calloc(items, size);
}
-void ZLIB_INTERNAL zcfree (opaque, ptr)
- voidpf opaque;
- voidpf ptr;
+void ZLIB_INTERNAL zcfree(opaque, ptr)
+voidpf opaque;
+voidpf ptr;
{
- free(ptr);
- if (opaque) return; /* make compiler happy */
+ free(ptr);
+ if (opaque) return; /* make compiler happy */
}
#endif /* MY_ZCALLOC */