(Szlib) cleanup

This commit is contained in:
TwinAphex51224 2012-03-06 17:49:49 +01:00
parent f7c2bfe530
commit 4365b77577
4 changed files with 80 additions and 134 deletions

View File

@ -1255,12 +1255,12 @@ const char *z_errmsg[10] =
"" ""
}; };
const char * ZEXPORT zlibVersion (void) const char * zlibVersion (void)
{ {
return ZLIB_VERSION; return ZLIB_VERSION;
} }
const char * ZEXPORT zError(int err) const char * zError(int err)
{ {
return z_errmsg[Z_NEED_DICT-(err)]; return z_errmsg[Z_NEED_DICT-(err)];
} }
@ -1343,7 +1343,7 @@ static const uLongf crc_table[256] = {
#define DO4_CRC32(buf) DO2_CRC32(buf); DO2_CRC32(buf); #define DO4_CRC32(buf) DO2_CRC32(buf); DO2_CRC32(buf);
#define DO8_CRC32(buf) DO4_CRC32(buf); DO4_CRC32(buf); #define DO8_CRC32(buf) DO4_CRC32(buf); DO4_CRC32(buf);
uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len) uLong crc32(uLong crc, const Bytef *buf, uInt len)
{ {
if (buf == 0) return 0L; if (buf == 0) return 0L;
crc = crc ^ 0xffffffffL; crc = crc ^ 0xffffffffL;
@ -1364,7 +1364,7 @@ uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len)
*/ */
int ZEXPORT inflateReset(z_streamp z) int inflateReset(z_streamp z)
{ {
if (z == 0 || z->state == 0) if (z == 0 || z->state == 0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
@ -1375,7 +1375,7 @@ int ZEXPORT inflateReset(z_streamp z)
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateEnd(z_streamp z) int inflateEnd(z_streamp z)
{ {
if (z == 0 || z->state == 0 || z->zfree == 0) if (z == 0 || z->state == 0 || z->zfree == 0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
@ -1386,7 +1386,7 @@ int ZEXPORT inflateEnd(z_streamp z)
return Z_OK; return Z_OK;
} }
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) uLong adler32(uLong adler, const Bytef *buf, uInt len)
{ {
unsigned long s1 = adler & 0xffff; unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff; unsigned long s2 = (adler >> 16) & 0xffff;
@ -1413,7 +1413,7 @@ uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
} }
int ZEXPORT inflateInit2_(z_streamp z, int w, const char * version, int stream_size) int inflateInit2_(z_streamp z, int w, const char * version, int stream_size)
{ {
if (version == 0 || version[0] != ZLIB_VERSION[0] || if (version == 0 || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream)) stream_size != sizeof(z_stream))
@ -1465,7 +1465,7 @@ int ZEXPORT inflateInit2_(z_streamp z, int w, const char * version, int stream_s
} }
int ZEXPORT inflateInit_(z_streamp z, const char * version, int stream_size) int inflateInit_(z_streamp z, const char * version, int stream_size)
{ {
return inflateInit2_(z, DEF_WBITS, version, stream_size); return inflateInit2_(z, DEF_WBITS, version, stream_size);
} }
@ -1473,7 +1473,7 @@ int ZEXPORT inflateInit_(z_streamp z, const char * version, int stream_size)
#define NEEDBYTE_INFLATE {if(z->avail_in==0)return r;r=f;} #define NEEDBYTE_INFLATE {if(z->avail_in==0)return r;r=f;}
#define NEXTBYTE_INFLATE (z->avail_in--,z->total_in++,*z->next_in++) #define NEXTBYTE_INFLATE (z->avail_in--,z->total_in++,*z->next_in++)
int ZEXPORT inflate(z_streamp z, int f) int inflate(z_streamp z, int f)
{ {
int r; int r;
uInt b; uInt b;
@ -1646,7 +1646,7 @@ static void check_header OF((gz_stream *s));
static int destroy OF((gz_stream *s)); static int destroy OF((gz_stream *s));
static uLong getLong OF((gz_stream *s)); static uLong getLong OF((gz_stream *s));
static gzFile gz_open (const char * path, const char *mode, int fd) static voidp gz_open (const char * path, const char *mode, int fd)
{ {
int err; int err;
char *p = (char*)mode; char *p = (char*)mode;
@ -1674,7 +1674,7 @@ static gzFile gz_open (const char * path, const char *mode, int fd)
s->path = (char*)malloc(strlen(path)+1); s->path = (char*)malloc(strlen(path)+1);
if (s->path == NULL) { if (s->path == NULL) {
return destroy(s), (gzFile)0; return destroy(s), (voidp)0;
} }
strcpy(s->path, path); /* do this early for debugging */ strcpy(s->path, path); /* do this early for debugging */
@ -1689,12 +1689,12 @@ static gzFile gz_open (const char * path, const char *mode, int fd)
*m++ = *p; /* copy the mode */ *m++ = *p; /* copy the mode */
} }
} while (*p++ && m != fmode + sizeof(fmode)); } while (*p++ && m != fmode + sizeof(fmode));
if (s->mode == '\0') return destroy(s), (gzFile)0; if (s->mode == '\0') return destroy(s), (voidp)0;
if (s->mode == 'w') { if (s->mode == 'w') {
err = Z_STREAM_ERROR; err = Z_STREAM_ERROR;
if (err != Z_OK || s->outbuf == 0) { if (err != Z_OK || s->outbuf == 0) {
return destroy(s), (gzFile)0; return destroy(s), (voidp)0;
} }
} else { } else {
s->stream.next_in = s->inbuf = (Byte*)malloc(Z_BUFSIZE); s->stream.next_in = s->inbuf = (Byte*)malloc(Z_BUFSIZE);
@ -1707,7 +1707,7 @@ static gzFile gz_open (const char * path, const char *mode, int fd)
* present after the compressed stream. * present after the compressed stream.
*/ */
if (err != Z_OK || s->inbuf == 0) { if (err != Z_OK || s->inbuf == 0) {
return destroy(s), (gzFile)0; return destroy(s), (voidp)0;
} }
} }
s->stream.avail_out = Z_BUFSIZE; s->stream.avail_out = Z_BUFSIZE;
@ -1715,7 +1715,7 @@ static gzFile gz_open (const char * path, const char *mode, int fd)
errno = 0; errno = 0;
s->file = fopen((path), (fmode)); s->file = fopen((path), (fmode));
if (s->file == NULL) { if (s->file == NULL) {
return destroy(s), (gzFile)0; return destroy(s), (voidp)0;
} }
if (s->mode == 'w') { if (s->mode == 'w') {
/* Write a very simple .gz header: /* Write a very simple .gz header:
@ -1733,19 +1733,19 @@ static gzFile gz_open (const char * path, const char *mode, int fd)
s->startpos = (ftell(s->file) - s->stream.avail_in); s->startpos = (ftell(s->file) - s->stream.avail_in);
} }
return (gzFile)s; return (voidp)s;
} }
gzFile ZEXPORT gzopen (const char * path, const char * mode) voidp gzopen (const char * path, const char * mode)
{ {
return gz_open (path, mode, -1); return gz_open (path, mode, -1);
} }
gzFile ZEXPORT gzdopen (int fd, const char * mode) voidp gzdopen (int fd, const char * mode)
{ {
char name[20]; char name[20];
if (fd < 0) return (gzFile)0; if (fd < 0) return (voidp)0;
sprintf(name, "<fd:%d>", fd); /* for debugging */ sprintf(name, "<fd:%d>", fd); /* for debugging */
return gz_open (name, mode, fd); return gz_open (name, mode, fd);
@ -1848,7 +1848,7 @@ static int destroy (gz_stream *s)
return err; return err;
} }
int ZEXPORT gzread (gzFile file, voidp buf, unsigned len) int gzread (voidp file, voidp buf, unsigned len)
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
Bytef *start = (Bytef*)buf; /* starting point for crc computation */ Bytef *start = (Bytef*)buf; /* starting point for crc computation */
@ -1934,14 +1934,14 @@ int ZEXPORT gzread (gzFile file, voidp buf, unsigned len)
return (int)(len - s->stream.avail_out); return (int)(len - s->stream.avail_out);
} }
int ZEXPORT gzgetc(gzFile file) int gzgetc(voidp file)
{ {
unsigned char c; unsigned char c;
return gzread(file, &c, 1) == 1 ? c : -1; return gzread(file, &c, 1) == 1 ? c : -1;
} }
char * ZEXPORT gzgets(gzFile file, char *buf, int len) char * gzgets(voidp file, char *buf, int len)
{ {
char *b = buf; char *b = buf;
if (buf == 0 || len <= 0) return 0; if (buf == 0 || len <= 0) return 0;
@ -1951,7 +1951,7 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len)
return b == buf && len > 0 ? 0 : b; return b == buf && len > 0 ? 0 : b;
} }
z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence) z_off_t gzseek (voidp file, z_off_t offset, int whence)
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
@ -2002,7 +2002,7 @@ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence)
return (z_off_t)s->stream.total_out; return (z_off_t)s->stream.total_out;
} }
int ZEXPORT gzrewind (gzFile file) int gzrewind (voidp file)
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
@ -2023,12 +2023,12 @@ int ZEXPORT gzrewind (gzFile file)
return fseek(s->file, s->startpos, SEEK_SET); return fseek(s->file, s->startpos, SEEK_SET);
} }
z_off_t ZEXPORT gztell (gzFile file) z_off_t gztell (voidp file)
{ {
return gzseek(file, 0L, SEEK_CUR); return gzseek(file, 0L, SEEK_CUR);
} }
int ZEXPORT gzeof (gzFile file) int gzeof (voidp file)
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
@ -2048,7 +2048,7 @@ static uLong getLong (gz_stream *s)
return x; return x;
} }
int ZEXPORT gzclose (gzFile file) int gzclose (voidp file)
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
@ -2060,7 +2060,7 @@ int ZEXPORT gzclose (gzFile file)
return destroy((gz_stream*)file); return destroy((gz_stream*)file);
} }
const char* ZEXPORT gzerror (gzFile file, int *errnum) const char* gzerror (voidp file, int *errnum)
{ {
char *m; char *m;
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;

View File

@ -180,7 +180,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
# define zstrerror(errnum) "" # define zstrerror(errnum) ""
#endif #endif
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, typedef uLong ( *check_func) OF((uLong check, const Bytef *buf,
uInt len)); uInt len));
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr)); void zcfree OF((voidpf opaque, voidpf ptr));
@ -347,60 +347,40 @@ struct inflate_blocks_state {
#define LOAD {LOADIN LOADOUT} #define LOAD {LOADIN LOADOUT}
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */ /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
extern uInt inflate_mask[17]; extern uInt inflate_mask[17];
/* copy as much as possible from the sliding window to the output area */ /* copy as much as possible from the sliding window to the output area */
extern int inflate_flush OF((inflate_blocks_statef *, z_streamp , int)); extern int inflate_flush OF((inflate_blocks_statef *, z_streamp , int));
// utility functions // utility functions
typedef voidp gzFile; extern voidp gzopen OF((const char *path, const char *mode));
extern voidp gzdopen OF((int fd, const char *mode));
extern int gzread OF((voidp file, voidp buf, unsigned len));
extern int gzwrite OF((voidp file, const voidp buf, unsigned len));
extern int gzprintf OF((voidp file, const char *format, ...));
extern int gzputs OF((voidp file, const char *s));
extern char * gzgets OF((voidp file, char *buf, int len));
extern int gzputc OF((voidp file, int c));
extern int gzgetc OF((voidp file));
extern int gzflush OF((voidp file, int flush));
extern z_off_t gzseek OF((voidp file, z_off_t offset, int whence));
extern int gzrewind OF((voidp file));
extern z_off_t gztell OF((voidp file));
extern int gzeof OF((voidp file));
extern int gzclose OF((voidp file));
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); extern const char * gzerror OF((voidp file, int *errnum));
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); /* checksum functions */
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); extern uLong adler32 OF((uLong adler, const Bytef *buf, uInt len));
extern uLong crc32 OF((uLong crc, const Bytef *buf, uInt len));
ZEXTERN int ZEXPORT gzwrite OF((gzFile file, /* various hacks, don't look :) */
const voidp buf, unsigned len));
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); extern int inflateInit_ OF((z_streamp strm, const char * version, int stream_size));
extern int inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size));
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/* checksum functions */
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* various hacks, don't look :) */
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define inflateInit(strm) \ #define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))

View File

@ -50,40 +50,6 @@
#define OF(args) args #define OF(args) args
#endif #endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR #ifndef FAR
# define FAR # define FAR
#endif #endif

View File

@ -117,64 +117,64 @@ typedef z_stream FAR *z_streamp;
// basic functions // basic functions
ZEXTERN const char * ZEXPORT zlibVersion OF((void)); typedef voidp gzFile;
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); extern const char * zlibVersion OF((void));
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); extern int inflate OF((z_streamp strm, int flush));
extern int inflateEnd OF((z_streamp strm));
// The following functions are needed only in some special applications. // The following functions are needed only in some special applications.
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); extern int inflateReset OF((z_streamp strm));
// utility functions // utility functions
typedef voidp gzFile; extern gzFile gzopen OF((const char *path, const char *mode));
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); extern gzFile gzdopen OF((int fd, const char *mode));
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); extern int gzread OF((gzFile file, voidp buf, unsigned len));
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); extern int gzwrite OF((gzFile file,
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
const voidp buf, unsigned len)); const voidp buf, unsigned len));
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); extern int VA gzprintf OF((gzFile file, const char *format, ...));
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); extern int gzputs OF((gzFile file, const char *s));
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); extern char * gzgets OF((gzFile file, char *buf, int len));
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); extern int gzputc OF((gzFile file, int c));
ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); extern int gzgetc OF((gzFile file));
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); extern int gzflush OF((gzFile file, int flush));
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, extern z_off_t gzseek OF((gzFile file,
z_off_t offset, int whence)); z_off_t offset, int whence));
ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); extern int gzrewind OF((gzFile file));
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); extern z_off_t gztell OF((gzFile file));
ZEXTERN int ZEXPORT gzeof OF((gzFile file)); extern int gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzclose OF((gzFile file)); extern int gzclose OF((gzFile file));
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); extern const char * gzerror OF((gzFile file, int *errnum));
/* checksum functions */ /* checksum functions */
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); extern uLong adler32 OF((uLong adler, const Bytef *buf, uInt len));
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); extern uLong crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* various hacks, don't look :) */ /* various hacks, don't look :) */
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, extern int inflateInit_ OF((z_streamp strm,
const char *version, int stream_size)); const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, extern int inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size)); const char *version, int stream_size));
#define inflateInit(strm) \ #define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
@ -186,7 +186,7 @@ ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
struct internal_state {int dummy;}; /* hack for buggy compilers */ struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif #endif
ZEXTERN const char * ZEXPORT zError OF((int err)); extern const char * zError OF((int err));
#ifdef __cplusplus #ifdef __cplusplus
} }