kusano fc6ab3
/* ioapi.h -- IO base function header for compress/uncompress .zip
kusano fc6ab3
   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
kusano fc6ab3
kusano fc6ab3
         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
kusano fc6ab3
kusano fc6ab3
         Modifications for Zip64 support
kusano fc6ab3
         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
kusano fc6ab3
kusano fc6ab3
         For more info read MiniZip_info.txt
kusano fc6ab3
kusano fc6ab3
         Changes
kusano fc6ab3
kusano fc6ab3
    Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
kusano fc6ab3
    Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
kusano fc6ab3
               More if/def section may be needed to support other platforms
kusano fc6ab3
    Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
kusano fc6ab3
                          (but you should use iowin32.c for windows instead)
kusano fc6ab3
kusano fc6ab3
*/
kusano fc6ab3
kusano fc6ab3
#ifndef _ZLIBIOAPI64_H
kusano fc6ab3
#define _ZLIBIOAPI64_H
kusano fc6ab3
kusano fc6ab3
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
kusano fc6ab3
kusano fc6ab3
  // Linux needs this to support file operation on files larger then 4+GB
kusano fc6ab3
  // But might need better if/def to select just the platforms that needs them.
kusano fc6ab3
kusano fc6ab3
        #ifndef __USE_FILE_OFFSET64
kusano fc6ab3
                #define __USE_FILE_OFFSET64
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef __USE_LARGEFILE64
kusano fc6ab3
                #define __USE_LARGEFILE64
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef _LARGEFILE64_SOURCE
kusano fc6ab3
                #define _LARGEFILE64_SOURCE
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef _FILE_OFFSET_BIT
kusano fc6ab3
                #define _FILE_OFFSET_BIT 64
kusano fc6ab3
        #endif
kusano fc6ab3
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#include <stdio.h></stdio.h>
kusano fc6ab3
#include <stdlib.h></stdlib.h>
kusano fc6ab3
#include "zlib.h"
kusano fc6ab3
kusano fc6ab3
#if defined(USE_FILE32API)
kusano fc6ab3
#define fopen64 fopen
kusano fc6ab3
#define ftello64 ftell
kusano fc6ab3
#define fseeko64 fseek
kusano fc6ab3
#else
kusano fc6ab3
#ifdef __FreeBSD__
kusano fc6ab3
#define fopen64 fopen
kusano fc6ab3
#define ftello64 ftello
kusano fc6ab3
#define fseeko64 fseeko
kusano fc6ab3
#endif
kusano fc6ab3
#ifdef _MSC_VER
kusano fc6ab3
 #define fopen64 fopen
kusano fc6ab3
 #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
kusano fc6ab3
  #define ftello64 _ftelli64
kusano fc6ab3
  #define fseeko64 _fseeki64
kusano fc6ab3
 #else // old MSC
kusano fc6ab3
  #define ftello64 ftell
kusano fc6ab3
  #define fseeko64 fseek
kusano fc6ab3
 #endif
kusano fc6ab3
#endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
#ifndef ZPOS64_T
kusano fc6ab3
  #ifdef _WIN32
kusano fc6ab3
                #define ZPOS64_T fpos_t
kusano fc6ab3
  #else
kusano fc6ab3
    #include <stdint.h></stdint.h>
kusano fc6ab3
    #define ZPOS64_T uint64_t
kusano fc6ab3
  #endif
kusano fc6ab3
#endif
kusano fc6ab3
*/
kusano fc6ab3
kusano fc6ab3
#ifdef HAVE_MINIZIP64_CONF_H
kusano fc6ab3
#include "mz64conf.h"
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
/* a type choosen by DEFINE */
kusano fc6ab3
#ifdef HAVE_64BIT_INT_CUSTOM
kusano fc6ab3
typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T;
kusano fc6ab3
#else
kusano fc6ab3
#ifdef HAS_STDINT_H
kusano fc6ab3
#include "stdint.h"
kusano fc6ab3
typedef uint64_t ZPOS64_T;
kusano fc6ab3
#else
kusano fc6ab3
kusano fc6ab3
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
kusano fc6ab3
#define MAXU32 0xffffffff
kusano fc6ab3
kusano fc6ab3
#if defined(_MSC_VER) || defined(__BORLANDC__)
kusano fc6ab3
typedef unsigned __int64 ZPOS64_T;
kusano fc6ab3
#else
kusano fc6ab3
typedef unsigned long long int ZPOS64_T;
kusano fc6ab3
#endif
kusano fc6ab3
#endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#ifdef __cplusplus
kusano fc6ab3
extern "C" {
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#define ZLIB_FILEFUNC_SEEK_CUR (1)
kusano fc6ab3
#define ZLIB_FILEFUNC_SEEK_END (2)
kusano fc6ab3
#define ZLIB_FILEFUNC_SEEK_SET (0)
kusano fc6ab3
kusano fc6ab3
#define ZLIB_FILEFUNC_MODE_READ      (1)
kusano fc6ab3
#define ZLIB_FILEFUNC_MODE_WRITE     (2)
kusano fc6ab3
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
kusano fc6ab3
kusano fc6ab3
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
kusano fc6ab3
#define ZLIB_FILEFUNC_MODE_CREATE   (8)
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#ifndef ZCALLBACK
kusano fc6ab3
 #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
kusano fc6ab3
   #define ZCALLBACK CALLBACK
kusano fc6ab3
 #else
kusano fc6ab3
   #define ZCALLBACK
kusano fc6ab3
 #endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
kusano fc6ab3
typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
kusano fc6ab3
typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
kusano fc6ab3
typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
kusano fc6ab3
typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
kusano fc6ab3
kusano fc6ab3
typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
kusano fc6ab3
typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
/* here is the "old" 32 bits structure structure */
kusano fc6ab3
typedef struct zlib_filefunc_def_s
kusano fc6ab3
{
kusano fc6ab3
    open_file_func      zopen_file;
kusano fc6ab3
    read_file_func      zread_file;
kusano fc6ab3
    write_file_func     zwrite_file;
kusano fc6ab3
    tell_file_func      ztell_file;
kusano fc6ab3
    seek_file_func      zseek_file;
kusano fc6ab3
    close_file_func     zclose_file;
kusano fc6ab3
    testerror_file_func zerror_file;
kusano fc6ab3
    voidpf              opaque;
kusano fc6ab3
} zlib_filefunc_def;
kusano fc6ab3
kusano fc6ab3
typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
kusano fc6ab3
typedef long     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
kusano fc6ab3
typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, const void* filename, int mode));
kusano fc6ab3
kusano fc6ab3
typedef struct zlib_filefunc64_def_s
kusano fc6ab3
{
kusano fc6ab3
    open64_file_func    zopen64_file;
kusano fc6ab3
    read_file_func      zread_file;
kusano fc6ab3
    write_file_func     zwrite_file;
kusano fc6ab3
    tell64_file_func    ztell64_file;
kusano fc6ab3
    seek64_file_func    zseek64_file;
kusano fc6ab3
    close_file_func     zclose_file;
kusano fc6ab3
    testerror_file_func zerror_file;
kusano fc6ab3
    voidpf              opaque;
kusano fc6ab3
} zlib_filefunc64_def;
kusano fc6ab3
kusano fc6ab3
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
kusano fc6ab3
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
kusano fc6ab3
kusano fc6ab3
/* now internal definition, only for zip.c and unzip.h */
kusano fc6ab3
typedef struct zlib_filefunc64_32_def_s
kusano fc6ab3
{
kusano fc6ab3
    zlib_filefunc64_def zfile_func64;
kusano fc6ab3
    open_file_func      zopen32_file;
kusano fc6ab3
    tell_file_func      ztell32_file;
kusano fc6ab3
    seek_file_func      zseek32_file;
kusano fc6ab3
} zlib_filefunc64_32_def;
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
kusano fc6ab3
#define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
kusano fc6ab3
//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
kusano fc6ab3
//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
kusano fc6ab3
#define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
kusano fc6ab3
#define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
kusano fc6ab3
kusano fc6ab3
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
kusano fc6ab3
long    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
kusano fc6ab3
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
kusano fc6ab3
kusano fc6ab3
void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
kusano fc6ab3
kusano fc6ab3
#define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode)))
kusano fc6ab3
#define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream)))
kusano fc6ab3
#define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
kusano fc6ab3
kusano fc6ab3
#ifdef __cplusplus
kusano fc6ab3
}
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#endif