ioapi.h 6.9 KB
Newer Older
M
Mark Adler 已提交
1
/* ioapi.h -- IO base function header for compress/uncompress .zip
M
Mark Adler 已提交
2
   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
M
Mark Adler 已提交
3

M
Mark Adler 已提交
4
         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
M
Mark Adler 已提交
5

M
Mark Adler 已提交
6 7
         Modifications for Zip64 support
         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
M
Mark Adler 已提交
8

M
Mark Adler 已提交
9
         For more info read MiniZip_info.txt
M
Mark Adler 已提交
10

M
Mark Adler 已提交
11
         Changes
M
Mark Adler 已提交
12 13 14 15

    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)
    Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
               More if/def section may be needed to support other platforms
M
Mark Adler 已提交
16
    Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
M
Mark Adler 已提交
17
                          (but you should use iowin32.c for windows instead)
M
Mark Adler 已提交
18 19 20

*/

M
Mark Adler 已提交
21 22 23
#ifndef _ZLIBIOAPI64_H
#define _ZLIBIOAPI64_H

M
Mark Adler 已提交
24
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
M
Mark Adler 已提交
25 26 27 28

  // Linux needs this to support file operation on files larger then 4+GB
  // But might need better if/def to select just the platforms that needs them.

M
Mark Adler 已提交
29 30 31 32 33 34 35 36 37 38 39 40
        #ifndef __USE_FILE_OFFSET64
                #define __USE_FILE_OFFSET64
        #endif
        #ifndef __USE_LARGEFILE64
                #define __USE_LARGEFILE64
        #endif
        #ifndef _LARGEFILE64_SOURCE
                #define _LARGEFILE64_SOURCE
        #endif
        #ifndef _FILE_OFFSET_BIT
                #define _FILE_OFFSET_BIT 64
        #endif
M
Mark Adler 已提交
41

M
Mark Adler 已提交
42 43 44 45 46 47
#endif

#include <stdio.h>
#include <stdlib.h>
#include "zlib.h"

M
Mark Adler 已提交
48 49 50 51 52
#if defined(USE_FILE32API)
#define fopen64 fopen
#define ftello64 ftell
#define fseeko64 fseek
#else
53 54 55 56 57
#ifdef __FreeBSD__
#define fopen64 fopen
#define ftello64 ftello
#define fseeko64 fseeko
#endif
M
Mark Adler 已提交
58 59
#ifdef _MSC_VER
 #define fopen64 fopen
M
Mark Adler 已提交
60
 #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
M
Mark Adler 已提交
61 62 63 64 65 66 67
  #define ftello64 _ftelli64
  #define fseeko64 _fseeki64
 #else // old MSC
  #define ftello64 ftell
  #define fseeko64 fseek
 #endif
#endif
M
Mark Adler 已提交
68
#endif
M
Mark Adler 已提交
69 70 71 72

/*
#ifndef ZPOS64_T
  #ifdef _WIN32
M
Mark Adler 已提交
73
                #define ZPOS64_T fpos_t
M
Mark Adler 已提交
74
  #else
M
Mark Adler 已提交
75
    #include <stdint.h>
M
Mark Adler 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    #define ZPOS64_T uint64_t
  #endif
#endif
*/

#ifdef HAVE_MINIZIP64_CONF_H
#include "mz64conf.h"
#endif

/* a type choosen by DEFINE */
#ifdef HAVE_64BIT_INT_CUSTOM
typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T;
#else
#ifdef HAS_STDINT_H
#include "stdint.h"
typedef uint64_t ZPOS64_T;
#else

94 95
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
#define MAXU32 0xffffffff
M
Mark Adler 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109

#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ZPOS64_T;
#else
typedef unsigned long long int ZPOS64_T;
#endif
#endif
#endif



#ifdef __cplusplus
extern "C" {
#endif
M
Mark Adler 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124


#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)

#define ZLIB_FILEFUNC_MODE_READ      (1)
#define ZLIB_FILEFUNC_MODE_WRITE     (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)

#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE   (8)


#ifndef ZCALLBACK
M
Mark Adler 已提交
125 126 127 128 129
 #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
   #define ZCALLBACK CALLBACK
 #else
   #define ZCALLBACK
 #endif
M
Mark Adler 已提交
130 131 132 133
#endif



M
Mark Adler 已提交
134 135 136 137 138 139 140 141 142 143 144 145

typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));

typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));


/* here is the "old" 32 bits structure structure */
M
Mark Adler 已提交
146 147 148 149 150 151 152 153 154 155 156 157
typedef struct zlib_filefunc_def_s
{
    open_file_func      zopen_file;
    read_file_func      zread_file;
    write_file_func     zwrite_file;
    tell_file_func      ztell_file;
    seek_file_func      zseek_file;
    close_file_func     zclose_file;
    testerror_file_func zerror_file;
    voidpf              opaque;
} zlib_filefunc_def;

M
Mark Adler 已提交
158 159 160
typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
typedef long     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, const void* filename, int mode));
M
Mark Adler 已提交
161

M
Mark Adler 已提交
162 163 164 165 166 167 168 169 170 171 172
typedef struct zlib_filefunc64_def_s
{
    open64_file_func    zopen64_file;
    read_file_func      zread_file;
    write_file_func     zwrite_file;
    tell64_file_func    ztell64_file;
    seek64_file_func    zseek64_file;
    close_file_func     zclose_file;
    testerror_file_func zerror_file;
    voidpf              opaque;
} zlib_filefunc64_def;
M
Mark Adler 已提交
173

M
Mark Adler 已提交
174
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
M
Mark Adler 已提交
175 176
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));

M
Mark Adler 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
/* now internal definition, only for zip.c and unzip.h */
typedef struct zlib_filefunc64_32_def_s
{
    zlib_filefunc64_def zfile_func64;
    open_file_func      zopen32_file;
    tell_file_func      ztell32_file;
    seek_file_func      zseek32_file;
} zlib_filefunc64_32_def;


#define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
#define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
#define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
M
Mark Adler 已提交
193

M
Mark Adler 已提交
194 195 196 197 198 199 200 201 202
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
long    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));

void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);

#define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode)))
#define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream)))
#define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
M
Mark Adler 已提交
203 204 205 206 207 208

#ifdef __cplusplus
}
#endif

#endif