ioapi.c
Go to the documentation of this file.
00001 /* ioapi.h -- IO base function header for compress/uncompress .zip
00002    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
00003 
00004          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
00005 
00006          Modifications for Zip64 support
00007          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
00008 
00009          For more info read MiniZip_info.txt
00010 
00011 */
00012 
00013 #if (defined(_WIN32))
00014         #define _CRT_SECURE_NO_WARNINGS
00015 #endif
00016 
00017 #include "ioapi.h"
00018 
00019 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
00020 {
00021     if (pfilefunc->zfile_func64.zopen64_file != NULL)
00022         return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
00023     else
00024     {
00025         return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
00026     }
00027 }
00028 
00029 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
00030 {
00031     if (pfilefunc->zfile_func64.zseek64_file != NULL)
00032         return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
00033     else
00034     {
00035         uLong offsetTruncated = (uLong)offset;
00036         if (offsetTruncated != offset)
00037             return -1;
00038         else
00039             return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
00040     }
00041 }
00042 
00043 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
00044 {
00045     if (pfilefunc->zfile_func64.zseek64_file != NULL)
00046         return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
00047     else
00048     {
00049         uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
00050         if ((tell_uLong) == ((uLong)-1))
00051             return (ZPOS64_T)-1;
00052         else
00053             return tell_uLong;
00054     }
00055 }
00056 
00057 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
00058 {
00059     p_filefunc64_32->zfile_func64.zopen64_file = NULL;
00060     p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
00061     p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
00062     p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
00063     p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
00064     p_filefunc64_32->zfile_func64.ztell64_file = NULL;
00065     p_filefunc64_32->zfile_func64.zseek64_file = NULL;
00066     p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
00067     p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
00068     p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
00069     p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
00070     p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
00071 }
00072 
00073 
00074 
00075 static voidpf  ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
00076 static uLong   ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
00077 static uLong   ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
00078 static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
00079 static long    ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
00080 static int     ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
00081 static int     ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
00082 
00083 static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
00084 {
00085     FILE* file = NULL;
00086     const char* mode_fopen = NULL;
00087     if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
00088         mode_fopen = "rb";
00089     else
00090     if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
00091         mode_fopen = "r+b";
00092     else
00093     if (mode & ZLIB_FILEFUNC_MODE_CREATE)
00094         mode_fopen = "wb";
00095 
00096     if ((filename!=NULL) && (mode_fopen != NULL))
00097         file = fopen(filename, mode_fopen);
00098     return file;
00099 }
00100 
00101 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
00102 {
00103     FILE* file = NULL;
00104     const char* mode_fopen = NULL;
00105     if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
00106         mode_fopen = "rb";
00107     else
00108     if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
00109         mode_fopen = "r+b";
00110     else
00111     if (mode & ZLIB_FILEFUNC_MODE_CREATE)
00112         mode_fopen = "wb";
00113 
00114     if ((filename!=NULL) && (mode_fopen != NULL))
00115         file = fopen64((const char*)filename, mode_fopen);
00116     return file;
00117 }
00118 
00119 
00120 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
00121 {
00122     uLong ret;
00123     ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
00124     return ret;
00125 }
00126 
00127 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
00128 {
00129     uLong ret;
00130     ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
00131     return ret;
00132 }
00133 
00134 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
00135 {
00136     long ret;
00137     ret = ftell((FILE *)stream);
00138     return ret;
00139 }
00140 
00141 
00142 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
00143 {
00144     ZPOS64_T ret;
00145     ret = ftello64((FILE *)stream);
00146     return ret;
00147 }
00148 
00149 static long ZCALLBACK fseek_file_func (voidpf  opaque, voidpf stream, uLong offset, int origin)
00150 {
00151     int fseek_origin=0;
00152     long ret;
00153     switch (origin)
00154     {
00155     case ZLIB_FILEFUNC_SEEK_CUR :
00156         fseek_origin = SEEK_CUR;
00157         break;
00158     case ZLIB_FILEFUNC_SEEK_END :
00159         fseek_origin = SEEK_END;
00160         break;
00161     case ZLIB_FILEFUNC_SEEK_SET :
00162         fseek_origin = SEEK_SET;
00163         break;
00164     default: return -1;
00165     }
00166     ret = 0;
00167     if (fseek((FILE *)stream, offset, fseek_origin) != 0)
00168         ret = -1;
00169     return ret;
00170 }
00171 
00172 static long ZCALLBACK fseek64_file_func (voidpf  opaque, voidpf stream, ZPOS64_T offset, int origin)
00173 {
00174     int fseek_origin=0;
00175     long ret;
00176     switch (origin)
00177     {
00178     case ZLIB_FILEFUNC_SEEK_CUR :
00179         fseek_origin = SEEK_CUR;
00180         break;
00181     case ZLIB_FILEFUNC_SEEK_END :
00182         fseek_origin = SEEK_END;
00183         break;
00184     case ZLIB_FILEFUNC_SEEK_SET :
00185         fseek_origin = SEEK_SET;
00186         break;
00187     default: return -1;
00188     }
00189     ret = 0;
00190 
00191     if(fseeko64((FILE *)stream, offset, fseek_origin) != 0)
00192                         ret = -1;
00193 
00194     return ret;
00195 }
00196 
00197 
00198 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
00199 {
00200     int ret;
00201     ret = fclose((FILE *)stream);
00202     return ret;
00203 }
00204 
00205 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
00206 {
00207     int ret;
00208     ret = ferror((FILE *)stream);
00209     return ret;
00210 }
00211 
00212 void fill_fopen_filefunc (pzlib_filefunc_def)
00213   zlib_filefunc_def* pzlib_filefunc_def;
00214 {
00215     pzlib_filefunc_def->zopen_file = fopen_file_func;
00216     pzlib_filefunc_def->zread_file = fread_file_func;
00217     pzlib_filefunc_def->zwrite_file = fwrite_file_func;
00218     pzlib_filefunc_def->ztell_file = ftell_file_func;
00219     pzlib_filefunc_def->zseek_file = fseek_file_func;
00220     pzlib_filefunc_def->zclose_file = fclose_file_func;
00221     pzlib_filefunc_def->zerror_file = ferror_file_func;
00222     pzlib_filefunc_def->opaque = NULL;
00223 }
00224 
00225 void fill_fopen64_filefunc (zlib_filefunc64_def*  pzlib_filefunc_def)
00226 {
00227     pzlib_filefunc_def->zopen64_file = fopen64_file_func;
00228     pzlib_filefunc_def->zread_file = fread_file_func;
00229     pzlib_filefunc_def->zwrite_file = fwrite_file_func;
00230     pzlib_filefunc_def->ztell64_file = ftell64_file_func;
00231     pzlib_filefunc_def->zseek64_file = fseek64_file_func;
00232     pzlib_filefunc_def->zclose_file = fclose_file_func;
00233     pzlib_filefunc_def->zerror_file = ferror_file_func;
00234     pzlib_filefunc_def->opaque = NULL;
00235 }


re_object_recorder
Author(s): Andreas Koch
autogenerated on Sun Jan 5 2014 11:39:12