2009-10-01 01:10:58 +02:00
|
|
|
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
|
|
|
files using zlib + zip or unzip API
|
|
|
|
|
|
|
|
Version 1.01e, February 12th, 2005
|
|
|
|
|
|
|
|
Copyright (C) 1998-2005 Gilles Vollant
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "zlib.h"
|
|
|
|
#include "ioapi.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
|
|
|
|
|
|
|
#ifndef SEEK_CUR
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SEEK_END
|
|
|
|
#define SEEK_END 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SEEK_SET
|
|
|
|
#define SEEK_SET 0
|
|
|
|
#endif
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
voidpf ZCALLBACK fopen_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
const char* filename,
|
|
|
|
int mode ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
uLong ZCALLBACK fread_file_func OF( (
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream,
|
2010-09-19 01:16:05 +02:00
|
|
|
void* buf,
|
|
|
|
uLong size ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
uLong ZCALLBACK fwrite_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream,
|
|
|
|
const void* buf,
|
|
|
|
uLong size ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
long ZCALLBACK ftell_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
long ZCALLBACK fseek_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream,
|
|
|
|
uLong offset,
|
|
|
|
int origin ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ZCALLBACK fclose_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ZCALLBACK ferror_file_func OF( (
|
|
|
|
voidpf opaque,
|
|
|
|
voidpf stream ) );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
voidpf ZCALLBACK fopen_file_func ( opaque, filename, mode )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
const char* filename;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
FILE* file = NULL;
|
|
|
|
const char* mode_fopen = NULL;
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ( mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER ) == ZLIB_FILEFUNC_MODE_READ )
|
2009-10-01 01:10:58 +02:00
|
|
|
mode_fopen = "rb";
|
2010-09-19 01:16:05 +02:00
|
|
|
else if ( mode & ZLIB_FILEFUNC_MODE_EXISTING )
|
|
|
|
mode_fopen = "r+b";
|
|
|
|
else if ( mode & ZLIB_FILEFUNC_MODE_CREATE )
|
|
|
|
mode_fopen = "wb";
|
|
|
|
|
|
|
|
if ( ( filename != NULL ) && ( mode_fopen != NULL ) )
|
|
|
|
file = fopen( filename, mode_fopen );
|
2009-10-01 01:10:58 +02:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
uLong ZCALLBACK fread_file_func ( opaque, stream, buf, size )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
void* buf;
|
|
|
|
uLong size;
|
|
|
|
{
|
|
|
|
uLong ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = ( uLong )fread( buf, 1, ( size_t )size, ( FILE * )stream );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
uLong ZCALLBACK fwrite_file_func ( opaque, stream, buf, size )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
const void* buf;
|
|
|
|
uLong size;
|
|
|
|
{
|
|
|
|
uLong ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = ( uLong )fwrite( buf, 1, ( size_t )size, ( FILE * )stream );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
long ZCALLBACK ftell_file_func ( opaque, stream )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
{
|
|
|
|
long ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = ftell( ( FILE * )stream );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
long ZCALLBACK fseek_file_func ( opaque, stream, offset, origin )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
uLong offset;
|
|
|
|
int origin;
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
int fseek_origin = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
long ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
switch ( origin )
|
|
|
|
{
|
|
|
|
case ZLIB_FILEFUNC_SEEK_CUR :
|
|
|
|
fseek_origin = SEEK_CUR;
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_END :
|
|
|
|
fseek_origin = SEEK_END;
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_SET :
|
|
|
|
fseek_origin = SEEK_SET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
ret = 0;
|
2010-09-19 01:16:05 +02:00
|
|
|
fseek( ( FILE * )stream, offset, fseek_origin );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ZCALLBACK fclose_file_func ( opaque, stream )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
{
|
|
|
|
int ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = fclose( ( FILE * )stream );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ZCALLBACK ferror_file_func ( opaque, stream )
|
2009-10-01 01:10:58 +02:00
|
|
|
voidpf opaque;
|
|
|
|
voidpf stream;
|
|
|
|
{
|
|
|
|
int ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = ferror( ( FILE * )stream );
|
2009-10-01 01:10:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void fill_fopen_filefunc ( pzlib_filefunc_def )
|
2009-10-01 01:10:58 +02:00
|
|
|
zlib_filefunc_def* pzlib_filefunc_def;
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
|
|
|
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
|
|
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
|
|
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
|
|
|
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
|
|
|
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
|
|
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|