diff options
Diffstat (limited to 'main/zlib/zutil.c')
-rw-r--r-- | main/zlib/zutil.c | 156 |
1 files changed, 89 insertions, 67 deletions
diff --git a/main/zlib/zutil.c b/main/zlib/zutil.c index 1819bd6..1a30236 100644 --- a/main/zlib/zutil.c +++ b/main/zlib/zutil.c @@ -1,30 +1,33 @@ /* zutil.c -- target dependent utility functions for the compression library * Copyright (C) 1995-1998 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 */ #include "zutil.h" -struct internal_state {int dummy;}; /* for buggy compilers */ +struct internal_state { + int dummy; +}; /* for buggy compilers */ #ifndef STDC extern void exit OF((int)); #endif const char *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() + "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; } @@ -36,8 +39,8 @@ const char * ZEXPORT zlibVersion() # endif int z_verbose = verbose; -void z_error (m) - char *m; +void z_error(m) +char *m; { fprintf(stderr, "%s\n", m); exit(1); @@ -47,8 +50,8 @@ void z_error (m) /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError(err) - int err; +const char *ZEXPORT zError(err) +int err; { return ERR_MSG(err); } @@ -58,37 +61,43 @@ const char * ZEXPORT zError(err) void zmemcpy(dest, source, len) -Bytef* dest; -const Bytef* source; +Bytef *dest; +const Bytef *source; uInt len; { - if (len == 0) return; + if(len == 0) { + return; + } do { *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); + } while(--len != 0); } int zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; +const Bytef *s1; +const Bytef *s2; +uInt len; { uInt j; - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + for(j = 0; j < len; j++) { + if(s1[j] != s2[j]) { + return 2*(s1[j] > s2[j])-1; + } } return 0; } void zmemzero(dest, len) - Bytef* dest; - uInt len; +Bytef *dest; +uInt len; { - if (len == 0) return; + if(len == 0) { + return; + } do { *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); + } while(--len != 0); } #endif @@ -123,7 +132,7 @@ local ptr_table table[MAX_PTR]; * a protected system like OS/2. Use Microsoft C instead. */ -voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +voidpf zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf buf = opaque; /* just to make some compilers happy */ ulg bsize = (ulg)items*size; @@ -131,35 +140,41 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned 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) { + if(bsize < 65520L) { buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; + if(*(ush *)&buf != 0) { + return buf; + } } else { buf = farmalloc(bsize + 16L); } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + 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; + *((ush *)&buf+1) += ((ush)((uch *)buf-0) + 15) >> 4; + *(ush *)&buf = 0; table[next_ptr++].new_ptr = buf; return buf; } -void zcfree (voidpf opaque, voidpf ptr) +void zcfree(voidpf opaque, voidpf ptr) { int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ + 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; + for(n = 0; n < next_ptr; n++) { + if(ptr != table[n].new_ptr) { + continue; + } farfree(table[n].org_ptr); - while (++n < next_ptr) { + while(++n < next_ptr) { table[n-1] = table[n]; } next_ptr--; @@ -182,15 +197,19 @@ void zcfree (voidpf opaque, voidpf ptr) # define _hfree hfree #endif -voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +voidpf zcalloc(voidpf opaque, unsigned items, unsigned size) { - if (opaque) opaque = 0; /* to make compiler happy */ + if(opaque) { + opaque = 0; /* to make compiler happy */ + } return _halloc((long)items, size); } -void zcfree (voidpf opaque, voidpf ptr) +void zcfree(voidpf opaque, voidpf ptr) { - if (opaque) opaque = 0; /* to make compiler happy */ + if(opaque) { + opaque = 0; /* to make compiler happy */ + } _hfree(ptr); } @@ -204,33 +223,36 @@ extern voidp calloc OF((uInt items, uInt size)); extern void free OF((voidpf ptr)); #endif -voidpf zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; +voidpf zcalloc(opaque, items, size) +voidpf opaque; +unsigned items; +unsigned size; { - extern char *malloc(int); - extern int memset(char *,int,int); - char *cp; - - if (opaque) - items += size - size; /* make compiler happy */ - cp = malloc(items*size); - if (cp) { - memset(cp,0,items*size); - return((voidpf)cp); - } + extern char *malloc(int); + extern int memset(char *,int,int); + char *cp; + + if(opaque) { + items += size - size; /* make compiler happy */ + } + cp = malloc(items*size); + if(cp) { + memset(cp,0,items*size); + return((voidpf)cp); + } return((voidpf)0); } -void zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; +void zcfree(opaque, ptr) +voidpf opaque; +voidpf ptr; { - extern void free(char *); + extern void free(char *); free((char *)ptr); - if (opaque) return; /* make compiler happy */ + if(opaque) { + return; /* make compiler happy */ + } } #endif /* MY_ZCALLOC */ |