mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 06:40:18 +00:00
(Szlib) Cleanups #3
This commit is contained in:
parent
cc476af1fe
commit
d9337a2589
@ -6,11 +6,9 @@
|
||||
/* This source as presented is a modified version of original zlib for use with SSNES,
|
||||
* and must not be confused with the original software. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "szlib.h"
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
|
||||
|
||||
/* And'ing with mask[n] masks the lower n bits */
|
||||
unsigned int inflate_mask[17] =
|
||||
{
|
||||
@ -1599,7 +1597,6 @@ int inflate(z_streamp z, int f)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4996)
|
||||
@ -1641,10 +1638,115 @@ typedef struct gz_stream {
|
||||
long startpos; /* start of compressed data in file (header skipped) */
|
||||
} gz_stream;
|
||||
|
||||
static int get_byte(gz_stream *s)
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->stream.avail_in--;
|
||||
return *(s->stream.next_in)++;
|
||||
}
|
||||
|
||||
static void check_header (gz_stream *s);
|
||||
static int destroy (gz_stream *s);
|
||||
static unsigned long getLong (gz_stream *s);
|
||||
static unsigned long getLong (gz_stream *s)
|
||||
{
|
||||
unsigned long x = (unsigned long)get_byte(s);
|
||||
int c;
|
||||
|
||||
x += ((unsigned long)get_byte(s))<<8;
|
||||
x += ((unsigned long)get_byte(s))<<16;
|
||||
c = get_byte(s);
|
||||
if (c == EOF) s->z_err = Z_DATA_ERROR;
|
||||
x += ((unsigned long)c)<<24;
|
||||
return x;
|
||||
}
|
||||
|
||||
static int destroy (gz_stream *s)
|
||||
{
|
||||
int err = Z_OK;
|
||||
|
||||
if (!s) return Z_STREAM_ERROR;
|
||||
|
||||
if(s->msg)
|
||||
free(s->msg);
|
||||
|
||||
if (s->stream.state != NULL) {
|
||||
if (s->mode == 'w') {
|
||||
err = Z_STREAM_ERROR;
|
||||
} else if (s->mode == 'r') {
|
||||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
}
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
if (s->z_err < 0) err = s->z_err;
|
||||
|
||||
if(s->inbuf)
|
||||
free(s->inbuf);
|
||||
if(s->outbuf)
|
||||
free(s->outbuf);
|
||||
if(s->path)
|
||||
free(s->path);
|
||||
if(s)
|
||||
free(s);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void check_header(gz_stream *s)
|
||||
{
|
||||
int method; /* method byte */
|
||||
int flags; /* flags byte */
|
||||
unsigned int len;
|
||||
int c;
|
||||
|
||||
/* Check the gzip magic header */
|
||||
for (len = 0; len < 2; len++) {
|
||||
c = get_byte(s);
|
||||
if (c != gz_magic[len]) {
|
||||
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
|
||||
if (c != EOF) {
|
||||
s->stream.avail_in++, s->stream.next_in--;
|
||||
s->transparent = 1;
|
||||
}
|
||||
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
|
||||
return;
|
||||
}
|
||||
}
|
||||
method = get_byte(s);
|
||||
flags = get_byte(s);
|
||||
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Discard time, xflags and OS code: */
|
||||
for (len = 0; len < 6; len++) (void)get_byte(s);
|
||||
|
||||
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
|
||||
len = (unsigned int)get_byte(s);
|
||||
len += ((unsigned int)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
}
|
||||
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
static voidp gz_open (const char * path, const char *mode, int fd)
|
||||
{
|
||||
@ -1751,103 +1853,6 @@ voidp gzdopen (int fd, const char * mode)
|
||||
return gz_open (name, mode, fd);
|
||||
}
|
||||
|
||||
static int get_byte(gz_stream *s)
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->stream.avail_in--;
|
||||
return *(s->stream.next_in)++;
|
||||
}
|
||||
|
||||
static void check_header(gz_stream *s)
|
||||
{
|
||||
int method; /* method byte */
|
||||
int flags; /* flags byte */
|
||||
unsigned int len;
|
||||
int c;
|
||||
|
||||
/* Check the gzip magic header */
|
||||
for (len = 0; len < 2; len++) {
|
||||
c = get_byte(s);
|
||||
if (c != gz_magic[len]) {
|
||||
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
|
||||
if (c != EOF) {
|
||||
s->stream.avail_in++, s->stream.next_in--;
|
||||
s->transparent = 1;
|
||||
}
|
||||
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
|
||||
return;
|
||||
}
|
||||
}
|
||||
method = get_byte(s);
|
||||
flags = get_byte(s);
|
||||
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Discard time, xflags and OS code: */
|
||||
for (len = 0; len < 6; len++) (void)get_byte(s);
|
||||
|
||||
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
|
||||
len = (unsigned int)get_byte(s);
|
||||
len += ((unsigned int)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
}
|
||||
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
static int destroy (gz_stream *s)
|
||||
{
|
||||
int err = Z_OK;
|
||||
|
||||
if (!s) return Z_STREAM_ERROR;
|
||||
|
||||
if(s->msg)
|
||||
free(s->msg);
|
||||
|
||||
if (s->stream.state != NULL) {
|
||||
if (s->mode == 'w') {
|
||||
err = Z_STREAM_ERROR;
|
||||
} else if (s->mode == 'r') {
|
||||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
}
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
if (s->z_err < 0) err = s->z_err;
|
||||
|
||||
if(s->inbuf)
|
||||
free(s->inbuf);
|
||||
if(s->outbuf)
|
||||
free(s->outbuf);
|
||||
if(s->path)
|
||||
free(s->path);
|
||||
if(s)
|
||||
free(s);
|
||||
return err;
|
||||
}
|
||||
|
||||
int gzread (voidp file, voidp buf, unsigned len)
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
@ -2035,18 +2040,6 @@ int gzeof (voidp file)
|
||||
return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
|
||||
}
|
||||
|
||||
static unsigned long getLong (gz_stream *s)
|
||||
{
|
||||
unsigned long x = (unsigned long)get_byte(s);
|
||||
int c;
|
||||
|
||||
x += ((unsigned long)get_byte(s))<<8;
|
||||
x += ((unsigned long)get_byte(s))<<16;
|
||||
c = get_byte(s);
|
||||
if (c == EOF) s->z_err = Z_DATA_ERROR;
|
||||
x += ((unsigned long)c)<<24;
|
||||
return x;
|
||||
}
|
||||
|
||||
int gzclose (voidp file)
|
||||
{
|
||||
|
@ -42,33 +42,33 @@ extern "C" {
|
||||
|
||||
#define ZLIB_VERSION "1.1.4"
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||
typedef voidpf (*alloc_func) (voidpf opaque, unsigned int items, unsigned int size);
|
||||
typedef void (*free_func) (voidpf opaque, voidpf address);
|
||||
|
||||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
unsigned int avail_in; /* number of bytes available at next_in */
|
||||
unsigned long total_in; /* total nb of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
unsigned int avail_out; /* remaining free space at next_out */
|
||||
unsigned long total_out; /* total nb of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
struct internal_state *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
unsigned long adler; /* adler32 value of the uncompressed data */
|
||||
unsigned long reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
typedef z_stream *z_streamp;
|
||||
|
||||
/* constants */
|
||||
|
||||
@ -119,74 +119,50 @@ typedef z_stream FAR *z_streamp;
|
||||
|
||||
typedef voidp gzFile;
|
||||
|
||||
extern const char * zlibVersion OF((void));
|
||||
extern const char * zlibVersion (void);
|
||||
|
||||
extern int inflate OF((z_streamp strm, int flush));
|
||||
extern int inflate (z_streamp strm, int flush);
|
||||
|
||||
extern int inflateEnd OF((z_streamp strm));
|
||||
extern int inflateEnd (z_streamp strm);
|
||||
|
||||
// The following functions are needed only in some special applications.
|
||||
|
||||
extern int inflateReset OF((z_streamp strm));
|
||||
extern int inflateReset (z_streamp strm);
|
||||
|
||||
// utility functions
|
||||
|
||||
extern gzFile gzopen OF((const char *path, const char *mode));
|
||||
extern gzFile gzopen (const char *path, const char *mode);
|
||||
extern gzFile gzdopen (int fd, const char *mode);
|
||||
extern int gzread (gzFile file, voidp buf, unsigned len);
|
||||
extern int gzwrite (gzFile file, const voidp buf, unsigned len);
|
||||
extern int gzprintf (gzFile file, const char *format, ...);
|
||||
extern int gzputs (gzFile file, const char *s);
|
||||
extern char * gzgets (gzFile file, char *buf, int len);
|
||||
extern int gzputc (gzFile file, int c);
|
||||
extern int gzgetc (gzFile file);
|
||||
extern int gzflush (gzFile file, int flush);
|
||||
extern z_off_t gzseek (gzFile file, z_off_t offset, int whence);
|
||||
extern int gzrewind (gzFile file);
|
||||
extern z_off_t gztell (gzFile file);
|
||||
extern int gzeof (gzFile file);
|
||||
extern int gzclose (gzFile file);
|
||||
extern const char * gzerror (gzFile file, int *errnum);
|
||||
|
||||
extern gzFile gzdopen OF((int fd, const char *mode));
|
||||
/* checksum functions */
|
||||
|
||||
extern int gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
extern unsigned long adler32 (unsigned long adler, const Bytef *buf, unsigned int len);
|
||||
extern unsigned long crc32 (unsigned long crc, const Bytef *buf, unsigned int len);
|
||||
|
||||
extern int gzwrite OF((gzFile file,
|
||||
const voidp buf, unsigned len));
|
||||
extern int VA gzprintf OF((gzFile file, const char *format, ...));
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
extern int gzputs OF((gzFile file, const char *s));
|
||||
|
||||
extern char * gzgets OF((gzFile file, char *buf, int len));
|
||||
|
||||
extern int gzputc OF((gzFile file, int c));
|
||||
|
||||
extern int gzgetc OF((gzFile file));
|
||||
|
||||
extern int gzflush OF((gzFile file, int flush));
|
||||
|
||||
extern z_off_t gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
|
||||
extern int gzrewind OF((gzFile file));
|
||||
|
||||
extern z_off_t gztell OF((gzFile file));
|
||||
|
||||
extern int gzeof OF((gzFile file));
|
||||
|
||||
extern int gzclose OF((gzFile file));
|
||||
|
||||
extern const char * gzerror OF((gzFile file, int *errnum));
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
extern uLong adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
extern uLong crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
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));
|
||||
extern int inflateInit_ (z_streamp strm, const char *version, int stream_size);
|
||||
extern int inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size);
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
|
||||
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
extern const char * zError OF((int err));
|
||||
extern const char * zError (int err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user