annotate src/zlib-1.2.7/contrib/minizip/ioapi.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 /* ioapi.h -- IO base function header for compress/uncompress .zip
cannam@89 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
cannam@89 3
cannam@89 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
cannam@89 5
cannam@89 6 Modifications for Zip64 support
cannam@89 7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
cannam@89 8
cannam@89 9 For more info read MiniZip_info.txt
cannam@89 10
cannam@89 11 */
cannam@89 12
cannam@89 13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
cannam@89 14 #define _CRT_SECURE_NO_WARNINGS
cannam@89 15 #endif
cannam@89 16
cannam@89 17 #if defined(__APPLE__) || defined(IOAPI_NO_64)
cannam@89 18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
cannam@89 19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
cannam@89 20 #define FTELLO_FUNC(stream) ftello(stream)
cannam@89 21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
cannam@89 22 #else
cannam@89 23 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
cannam@89 24 #define FTELLO_FUNC(stream) ftello64(stream)
cannam@89 25 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
cannam@89 26 #endif
cannam@89 27
cannam@89 28
cannam@89 29 #include "ioapi.h"
cannam@89 30
cannam@89 31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
cannam@89 32 {
cannam@89 33 if (pfilefunc->zfile_func64.zopen64_file != NULL)
cannam@89 34 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
cannam@89 35 else
cannam@89 36 {
cannam@89 37 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
cannam@89 38 }
cannam@89 39 }
cannam@89 40
cannam@89 41 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
cannam@89 42 {
cannam@89 43 if (pfilefunc->zfile_func64.zseek64_file != NULL)
cannam@89 44 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
cannam@89 45 else
cannam@89 46 {
cannam@89 47 uLong offsetTruncated = (uLong)offset;
cannam@89 48 if (offsetTruncated != offset)
cannam@89 49 return -1;
cannam@89 50 else
cannam@89 51 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
cannam@89 52 }
cannam@89 53 }
cannam@89 54
cannam@89 55 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
cannam@89 56 {
cannam@89 57 if (pfilefunc->zfile_func64.zseek64_file != NULL)
cannam@89 58 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
cannam@89 59 else
cannam@89 60 {
cannam@89 61 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
cannam@89 62 if ((tell_uLong) == MAXU32)
cannam@89 63 return (ZPOS64_T)-1;
cannam@89 64 else
cannam@89 65 return tell_uLong;
cannam@89 66 }
cannam@89 67 }
cannam@89 68
cannam@89 69 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
cannam@89 70 {
cannam@89 71 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
cannam@89 72 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
cannam@89 73 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
cannam@89 74 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
cannam@89 75 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
cannam@89 76 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
cannam@89 77 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
cannam@89 78 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
cannam@89 79 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
cannam@89 80 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
cannam@89 81 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
cannam@89 82 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
cannam@89 83 }
cannam@89 84
cannam@89 85
cannam@89 86
cannam@89 87 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
cannam@89 88 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
cannam@89 89 static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
cannam@89 90 static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
cannam@89 91 static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
cannam@89 92 static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
cannam@89 93 static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
cannam@89 94
cannam@89 95 static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
cannam@89 96 {
cannam@89 97 FILE* file = NULL;
cannam@89 98 const char* mode_fopen = NULL;
cannam@89 99 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
cannam@89 100 mode_fopen = "rb";
cannam@89 101 else
cannam@89 102 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
cannam@89 103 mode_fopen = "r+b";
cannam@89 104 else
cannam@89 105 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
cannam@89 106 mode_fopen = "wb";
cannam@89 107
cannam@89 108 if ((filename!=NULL) && (mode_fopen != NULL))
cannam@89 109 file = fopen(filename, mode_fopen);
cannam@89 110 return file;
cannam@89 111 }
cannam@89 112
cannam@89 113 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
cannam@89 114 {
cannam@89 115 FILE* file = NULL;
cannam@89 116 const char* mode_fopen = NULL;
cannam@89 117 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
cannam@89 118 mode_fopen = "rb";
cannam@89 119 else
cannam@89 120 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
cannam@89 121 mode_fopen = "r+b";
cannam@89 122 else
cannam@89 123 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
cannam@89 124 mode_fopen = "wb";
cannam@89 125
cannam@89 126 if ((filename!=NULL) && (mode_fopen != NULL))
cannam@89 127 file = FOPEN_FUNC((const char*)filename, mode_fopen);
cannam@89 128 return file;
cannam@89 129 }
cannam@89 130
cannam@89 131
cannam@89 132 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
cannam@89 133 {
cannam@89 134 uLong ret;
cannam@89 135 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
cannam@89 136 return ret;
cannam@89 137 }
cannam@89 138
cannam@89 139 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
cannam@89 140 {
cannam@89 141 uLong ret;
cannam@89 142 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
cannam@89 143 return ret;
cannam@89 144 }
cannam@89 145
cannam@89 146 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
cannam@89 147 {
cannam@89 148 long ret;
cannam@89 149 ret = ftell((FILE *)stream);
cannam@89 150 return ret;
cannam@89 151 }
cannam@89 152
cannam@89 153
cannam@89 154 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
cannam@89 155 {
cannam@89 156 ZPOS64_T ret;
cannam@89 157 ret = FTELLO_FUNC((FILE *)stream);
cannam@89 158 return ret;
cannam@89 159 }
cannam@89 160
cannam@89 161 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
cannam@89 162 {
cannam@89 163 int fseek_origin=0;
cannam@89 164 long ret;
cannam@89 165 switch (origin)
cannam@89 166 {
cannam@89 167 case ZLIB_FILEFUNC_SEEK_CUR :
cannam@89 168 fseek_origin = SEEK_CUR;
cannam@89 169 break;
cannam@89 170 case ZLIB_FILEFUNC_SEEK_END :
cannam@89 171 fseek_origin = SEEK_END;
cannam@89 172 break;
cannam@89 173 case ZLIB_FILEFUNC_SEEK_SET :
cannam@89 174 fseek_origin = SEEK_SET;
cannam@89 175 break;
cannam@89 176 default: return -1;
cannam@89 177 }
cannam@89 178 ret = 0;
cannam@89 179 if (fseek((FILE *)stream, offset, fseek_origin) != 0)
cannam@89 180 ret = -1;
cannam@89 181 return ret;
cannam@89 182 }
cannam@89 183
cannam@89 184 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
cannam@89 185 {
cannam@89 186 int fseek_origin=0;
cannam@89 187 long ret;
cannam@89 188 switch (origin)
cannam@89 189 {
cannam@89 190 case ZLIB_FILEFUNC_SEEK_CUR :
cannam@89 191 fseek_origin = SEEK_CUR;
cannam@89 192 break;
cannam@89 193 case ZLIB_FILEFUNC_SEEK_END :
cannam@89 194 fseek_origin = SEEK_END;
cannam@89 195 break;
cannam@89 196 case ZLIB_FILEFUNC_SEEK_SET :
cannam@89 197 fseek_origin = SEEK_SET;
cannam@89 198 break;
cannam@89 199 default: return -1;
cannam@89 200 }
cannam@89 201 ret = 0;
cannam@89 202
cannam@89 203 if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
cannam@89 204 ret = -1;
cannam@89 205
cannam@89 206 return ret;
cannam@89 207 }
cannam@89 208
cannam@89 209
cannam@89 210 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
cannam@89 211 {
cannam@89 212 int ret;
cannam@89 213 ret = fclose((FILE *)stream);
cannam@89 214 return ret;
cannam@89 215 }
cannam@89 216
cannam@89 217 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
cannam@89 218 {
cannam@89 219 int ret;
cannam@89 220 ret = ferror((FILE *)stream);
cannam@89 221 return ret;
cannam@89 222 }
cannam@89 223
cannam@89 224 void fill_fopen_filefunc (pzlib_filefunc_def)
cannam@89 225 zlib_filefunc_def* pzlib_filefunc_def;
cannam@89 226 {
cannam@89 227 pzlib_filefunc_def->zopen_file = fopen_file_func;
cannam@89 228 pzlib_filefunc_def->zread_file = fread_file_func;
cannam@89 229 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
cannam@89 230 pzlib_filefunc_def->ztell_file = ftell_file_func;
cannam@89 231 pzlib_filefunc_def->zseek_file = fseek_file_func;
cannam@89 232 pzlib_filefunc_def->zclose_file = fclose_file_func;
cannam@89 233 pzlib_filefunc_def->zerror_file = ferror_file_func;
cannam@89 234 pzlib_filefunc_def->opaque = NULL;
cannam@89 235 }
cannam@89 236
cannam@89 237 void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
cannam@89 238 {
cannam@89 239 pzlib_filefunc_def->zopen64_file = fopen64_file_func;
cannam@89 240 pzlib_filefunc_def->zread_file = fread_file_func;
cannam@89 241 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
cannam@89 242 pzlib_filefunc_def->ztell64_file = ftell64_file_func;
cannam@89 243 pzlib_filefunc_def->zseek64_file = fseek64_file_func;
cannam@89 244 pzlib_filefunc_def->zclose_file = fclose_file_func;
cannam@89 245 pzlib_filefunc_def->zerror_file = ferror_file_func;
cannam@89 246 pzlib_filefunc_def->opaque = NULL;
cannam@89 247 }