Rizin
unix-like reverse engineering framework and cli tools
ioapi.c File Reference
#include "ioapi.h"

Go to the source code of this file.

Macros

#define FOPEN_FUNC(filename, mode)   fopen64(filename, mode)
 
#define FTELLO_FUNC(stream)   ftello64(stream)
 
#define FSEEKO_FUNC(stream, offset, origin)   fseeko64(stream, offset, origin)
 

Functions

voidpf call_zopen64 (const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode)
 
long call_zseek64 (const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, ZPOS64_T offset, int origin)
 
ZPOS64_T call_ztell64 (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)
 
static voidpf ZCALLBACK fopen_file_func OF ((voidpf opaque, const char *filename, int mode))
 
static uLong ZCALLBACK fread_file_func OF ((voidpf opaque, voidpf stream, void *buf, uLong size))
 
static uLong ZCALLBACK fwrite_file_func OF ((voidpf opaque, voidpf stream, const void *buf, uLong size))
 
static ZPOS64_T ZCALLBACK ftell64_file_func OF ((voidpf opaque, voidpf stream))
 
static long ZCALLBACK fseek64_file_func OF ((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin))
 
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char *filename, int mode)
 
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void *filename, int mode)
 
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void *buf, uLong size)
 
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void *buf, uLong size)
 
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
 
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
 
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
 
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
 
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
 
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
 
void fill_fopen_filefunc (zlib_filefunc_def *pzlib_filefunc_def)
 
void fill_fopen64_filefunc (zlib_filefunc64_def *pzlib_filefunc_def)
 

Macro Definition Documentation

◆ FOPEN_FUNC

#define FOPEN_FUNC (   filename,
  mode 
)    fopen64(filename, mode)

Definition at line 23 of file ioapi.c.

◆ FSEEKO_FUNC

#define FSEEKO_FUNC (   stream,
  offset,
  origin 
)    fseeko64(stream, offset, origin)

Definition at line 25 of file ioapi.c.

◆ FTELLO_FUNC

#define FTELLO_FUNC (   stream)    ftello64(stream)

Definition at line 24 of file ioapi.c.

Function Documentation

◆ call_zopen64()

voidpf call_zopen64 ( const zlib_filefunc64_32_def pfilefunc,
const void *  filename,
int  mode 
)

Definition at line 31 of file ioapi.c.

32 {
33  if (pfilefunc->zfile_func64.zopen64_file != NULL)
34  return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
35  else
36  {
37  return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
38  }
39 }
#define NULL
Definition: cris-opc.c:27
const char * filename
Definition: ioapi.h:137
const char int mode
Definition: ioapi.h:137
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:182
open_file_func zopen32_file
Definition: ioapi.h:183
open64_file_func zopen64_file
Definition: ioapi.h:166

References NULL, zlib_filefunc64_def_s::opaque, zlib_filefunc64_32_def_s::zfile_func64, zlib_filefunc64_32_def_s::zopen32_file, and zlib_filefunc64_def_s::zopen64_file.

◆ call_zseek64()

long call_zseek64 ( const zlib_filefunc64_32_def pfilefunc,
voidpf  filestream,
ZPOS64_T  offset,
int  origin 
)

Definition at line 41 of file ioapi.c.

42 {
43  if (pfilefunc->zfile_func64.zseek64_file != NULL)
44  return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
45  else
46  {
47  uLong offsetTruncated = (uLong)offset;
48  if (offsetTruncated != offset)
49  return -1;
50  else
51  return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
52  }
53 }
voidpf uLong int origin
Definition: ioapi.h:144
voidpf uLong offset
Definition: ioapi.h:144
seek_file_func zseek32_file
Definition: ioapi.h:185
seek64_file_func zseek64_file
Definition: ioapi.h:170
unsigned long uLong
Definition: zconf.h:394

References NULL, zlib_filefunc64_def_s::opaque, zlib_filefunc64_32_def_s::zfile_func64, zlib_filefunc64_32_def_s::zseek32_file, and zlib_filefunc64_def_s::zseek64_file.

◆ call_ztell64()

ZPOS64_T call_ztell64 ( const zlib_filefunc64_32_def pfilefunc,
voidpf  filestream 
)

Definition at line 55 of file ioapi.c.

56 {
57  if (pfilefunc->zfile_func64.zseek64_file != NULL)
58  return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
59  else
60  {
61  uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
62  if ((tell_uLong) == MAXU32)
63  return (ZPOS64_T)-1;
64  else
65  return tell_uLong;
66  }
67 }
#define MAXU32
Definition: ioapi.h:106
unsigned long long int ZPOS64_T
Definition: ioapi.h:99
tell_file_func ztell32_file
Definition: ioapi.h:184
tell64_file_func ztell64_file
Definition: ioapi.h:169

References MAXU32, NULL, zlib_filefunc64_def_s::opaque, zlib_filefunc64_32_def_s::zfile_func64, zlib_filefunc64_def_s::zseek64_file, zlib_filefunc64_32_def_s::ztell32_file, and zlib_filefunc64_def_s::ztell64_file.

◆ fclose_file_func()

static int ZCALLBACK fclose_file_func ( voidpf  opaque,
voidpf  stream 
)
static

Definition at line 218 of file ioapi.c.

219 {
220  (void)opaque;
221  int ret;
222  ret = fclose((FILE *)stream);
223  return ret;
224 }
voidpf stream
Definition: ioapi.h:138
string FILE
Definition: benchmark.py:21

References benchmark::FILE.

Referenced by fill_fopen64_filefunc(), and fill_fopen_filefunc().

◆ ferror_file_func()

static int ZCALLBACK ferror_file_func ( voidpf  opaque,
voidpf  stream 
)
static

Definition at line 226 of file ioapi.c.

227 {
228  (void)opaque;
229  int ret;
230  ret = ferror((FILE *)stream);
231  return ret;
232 }

References benchmark::FILE.

Referenced by fill_fopen64_filefunc(), and fill_fopen_filefunc().

◆ fill_fopen64_filefunc()

void fill_fopen64_filefunc ( zlib_filefunc64_def pzlib_filefunc_def)

Definition at line 247 of file ioapi.c.

248 {
249  pzlib_filefunc_def->zopen64_file = fopen64_file_func;
250  pzlib_filefunc_def->zread_file = fread_file_func;
251  pzlib_filefunc_def->zwrite_file = fwrite_file_func;
252  pzlib_filefunc_def->ztell64_file = ftell64_file_func;
253  pzlib_filefunc_def->zseek64_file = fseek64_file_func;
254  pzlib_filefunc_def->zclose_file = fclose_file_func;
255  pzlib_filefunc_def->zerror_file = ferror_file_func;
256  pzlib_filefunc_def->opaque = NULL;
257 }
static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream)
Definition: ioapi.c:159
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
Definition: ioapi.c:191
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream)
Definition: ioapi.c:226
static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uLong size)
Definition: ioapi.c:142
static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void *filename, int mode)
Definition: ioapi.c:114
static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void *buf, uLong size)
Definition: ioapi.c:134
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream)
Definition: ioapi.c:218
write_file_func zwrite_file
Definition: ioapi.h:168
read_file_func zread_file
Definition: ioapi.h:167
close_file_func zclose_file
Definition: ioapi.h:171
testerror_file_func zerror_file
Definition: ioapi.h:172

References fclose_file_func(), ferror_file_func(), fopen64_file_func(), fread_file_func(), fseek64_file_func(), ftell64_file_func(), fwrite_file_func(), NULL, zlib_filefunc64_def_s::opaque, zlib_filefunc64_def_s::zclose_file, zlib_filefunc64_def_s::zerror_file, zlib_filefunc64_def_s::zopen64_file, zlib_filefunc64_def_s::zread_file, zlib_filefunc64_def_s::zseek64_file, zlib_filefunc64_def_s::ztell64_file, and zlib_filefunc64_def_s::zwrite_file.

Referenced by unzOpenInternal(), and zipOpen3().

◆ fill_fopen_filefunc()

void fill_fopen_filefunc ( zlib_filefunc_def pzlib_filefunc_def)

Definition at line 234 of file ioapi.c.

236 {
237  pzlib_filefunc_def->zopen_file = fopen_file_func;
238  pzlib_filefunc_def->zread_file = fread_file_func;
239  pzlib_filefunc_def->zwrite_file = fwrite_file_func;
240  pzlib_filefunc_def->ztell_file = ftell_file_func;
241  pzlib_filefunc_def->zseek_file = fseek_file_func;
242  pzlib_filefunc_def->zclose_file = fclose_file_func;
243  pzlib_filefunc_def->zerror_file = ferror_file_func;
244  pzlib_filefunc_def->opaque = NULL;
245 }
static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin)
Definition: ioapi.c:167
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode)
Definition: ioapi.c:95
static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream)
Definition: ioapi.c:150
seek_file_func zseek_file
Definition: ioapi.h:154
open_file_func zopen_file
Definition: ioapi.h:150
testerror_file_func zerror_file
Definition: ioapi.h:156
write_file_func zwrite_file
Definition: ioapi.h:152
read_file_func zread_file
Definition: ioapi.h:151
close_file_func zclose_file
Definition: ioapi.h:155
tell_file_func ztell_file
Definition: ioapi.h:153

References fclose_file_func(), ferror_file_func(), fopen_file_func(), fread_file_func(), fseek_file_func(), ftell_file_func(), fwrite_file_func(), NULL, and zlib_filefunc_def_s::zopen_file.

◆ fill_zlib_filefunc64_32_def_from_filefunc32()

void fill_zlib_filefunc64_32_def_from_filefunc32 ( zlib_filefunc64_32_def p_filefunc64_32,
const zlib_filefunc_def p_filefunc32 
)

Definition at line 69 of file ioapi.c.

70 {
71  p_filefunc64_32->zfile_func64.zopen64_file = NULL;
72  p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73  p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
74  p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
75  p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
76  p_filefunc64_32->zfile_func64.ztell64_file = NULL;
77  p_filefunc64_32->zfile_func64.zseek64_file = NULL;
78  p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
79  p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
80  p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
81  p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
82  p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
83 }

References NULL, zlib_filefunc_def_s::opaque, zlib_filefunc64_def_s::opaque, zlib_filefunc_def_s::zclose_file, zlib_filefunc64_def_s::zclose_file, zlib_filefunc_def_s::zerror_file, zlib_filefunc64_def_s::zerror_file, zlib_filefunc64_32_def_s::zfile_func64, zlib_filefunc64_32_def_s::zopen32_file, zlib_filefunc64_def_s::zopen64_file, zlib_filefunc_def_s::zopen_file, zlib_filefunc_def_s::zread_file, zlib_filefunc64_def_s::zread_file, zlib_filefunc64_32_def_s::zseek32_file, zlib_filefunc64_def_s::zseek64_file, zlib_filefunc_def_s::zseek_file, zlib_filefunc64_32_def_s::ztell32_file, zlib_filefunc64_def_s::ztell64_file, zlib_filefunc_def_s::ztell_file, zlib_filefunc_def_s::zwrite_file, and zlib_filefunc64_def_s::zwrite_file.

Referenced by unzOpen2(), and zipOpen2().

◆ fopen64_file_func()

static voidpf ZCALLBACK fopen64_file_func ( voidpf  opaque,
const void *  filename,
int  mode 
)
static

Definition at line 114 of file ioapi.c.

115 {
116  (void)opaque;
117  FILE* file = NULL;
118  const char* mode_fopen = NULL;
120  mode_fopen = "rb";
121  else
123  mode_fopen = "r+b";
124  else
126  mode_fopen = "wb";
127 
128  if ((filename!=NULL) && (mode_fopen != NULL))
129  file = FOPEN_FUNC((const char*)filename, mode_fopen);
130  return file;
131 }
#define FOPEN_FUNC(filename, mode)
Definition: ioapi.c:23
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER
Definition: ioapi.h:120
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition: ioapi.h:122
#define ZLIB_FILEFUNC_MODE_CREATE
Definition: ioapi.h:123
#define ZLIB_FILEFUNC_MODE_READ
Definition: ioapi.h:118
Definition: gzappend.c:170
static int file
Definition: z80asm.c:58

References file, benchmark::FILE, FOPEN_FUNC, NULL, ZLIB_FILEFUNC_MODE_CREATE, ZLIB_FILEFUNC_MODE_EXISTING, ZLIB_FILEFUNC_MODE_READ, and ZLIB_FILEFUNC_MODE_READWRITEFILTER.

Referenced by fill_fopen64_filefunc().

◆ fopen_file_func()

static voidpf ZCALLBACK fopen_file_func ( voidpf  opaque,
const char *  filename,
int  mode 
)
static

Definition at line 95 of file ioapi.c.

96 {
97  (void)opaque;
98  FILE* file = NULL;
99  const char* mode_fopen = NULL;
101  mode_fopen = "rb";
102  else
104  mode_fopen = "r+b";
105  else
107  mode_fopen = "wb";
108 
109  if ((filename!=NULL) && (mode_fopen != NULL))
110  file = fopen(filename, mode_fopen);
111  return file;
112 }

References file, benchmark::FILE, NULL, ZLIB_FILEFUNC_MODE_CREATE, ZLIB_FILEFUNC_MODE_EXISTING, ZLIB_FILEFUNC_MODE_READ, and ZLIB_FILEFUNC_MODE_READWRITEFILTER.

Referenced by fill_fopen_filefunc().

◆ fread_file_func()

static uLong ZCALLBACK fread_file_func ( voidpf  opaque,
voidpf  stream,
void *  buf,
uLong  size 
)
static

Definition at line 134 of file ioapi.c.

135 {
136  (void)opaque;
137  uLong ret;
138  ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
139  return ret;
140 }
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138

References benchmark::FILE.

Referenced by fill_fopen64_filefunc(), and fill_fopen_filefunc().

◆ fseek64_file_func()

static long ZCALLBACK fseek64_file_func ( voidpf  opaque,
voidpf  stream,
ZPOS64_T  offset,
int  origin 
)
static

Definition at line 191 of file ioapi.c.

192 {
193  (void)opaque;
194  int fseek_origin=0;
195  long ret;
196  switch (origin)
197  {
199  fseek_origin = SEEK_CUR;
200  break;
202  fseek_origin = SEEK_END;
203  break;
205  fseek_origin = SEEK_SET;
206  break;
207  default: return -1;
208  }
209  ret = 0;
210 
211  if(FSEEKO_FUNC((FILE *)stream, (long)offset, fseek_origin) != 0)
212  ret = -1;
213 
214  return ret;
215 }
#define FSEEKO_FUNC(stream, offset, origin)
Definition: ioapi.c:25
#define ZLIB_FILEFUNC_SEEK_CUR
Definition: ioapi.h:114
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:116
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:115
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84

References benchmark::FILE, FSEEKO_FUNC, SEEK_CUR, SEEK_END, SEEK_SET, ZLIB_FILEFUNC_SEEK_CUR, ZLIB_FILEFUNC_SEEK_END, and ZLIB_FILEFUNC_SEEK_SET.

Referenced by fill_fopen64_filefunc().

◆ fseek_file_func()

static long ZCALLBACK fseek_file_func ( voidpf  opaque,
voidpf  stream,
uLong  offset,
int  origin 
)
static

Definition at line 167 of file ioapi.c.

168 {
169  (void)opaque;
170  int fseek_origin=0;
171  long ret;
172  switch (origin)
173  {
175  fseek_origin = SEEK_CUR;
176  break;
178  fseek_origin = SEEK_END;
179  break;
181  fseek_origin = SEEK_SET;
182  break;
183  default: return -1;
184  }
185  ret = 0;
186  if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
187  ret = -1;
188  return ret;
189 }

References benchmark::FILE, SEEK_CUR, SEEK_END, SEEK_SET, ZLIB_FILEFUNC_SEEK_CUR, ZLIB_FILEFUNC_SEEK_END, and ZLIB_FILEFUNC_SEEK_SET.

Referenced by fill_fopen_filefunc().

◆ ftell64_file_func()

static ZPOS64_T ZCALLBACK ftell64_file_func ( voidpf  opaque,
voidpf  stream 
)
static

Definition at line 159 of file ioapi.c.

160 {
161  (void)opaque;
162  ZPOS64_T ret;
163  ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
164  return ret;
165 }
#define FTELLO_FUNC(stream)
Definition: ioapi.c:24

References benchmark::FILE, and FTELLO_FUNC.

Referenced by fill_fopen64_filefunc().

◆ ftell_file_func()

static long ZCALLBACK ftell_file_func ( voidpf  opaque,
voidpf  stream 
)
static

Definition at line 150 of file ioapi.c.

151 {
152  (void)opaque;
153  long ret;
154  ret = ftell((FILE *)stream);
155  return ret;
156 }

References benchmark::FILE.

Referenced by fill_fopen_filefunc().

◆ fwrite_file_func()

static uLong ZCALLBACK fwrite_file_func ( voidpf  opaque,
voidpf  stream,
const void *  buf,
uLong  size 
)
static

Definition at line 142 of file ioapi.c.

143 {
144  (void)opaque;
145  uLong ret;
146  ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
147  return ret;
148 }

References benchmark::FILE.

Referenced by fill_fopen64_filefunc(), and fill_fopen_filefunc().

◆ OF() [1/5]

static voidpf ZCALLBACK fopen_file_func OF ( (voidpf opaque, const char *filename, int mode )
static

◆ OF() [2/5]

static ZPOS64_T ZCALLBACK ftell64_file_func OF ( (voidpf opaque, voidpf stream )
static

◆ OF() [3/5]

static uLong ZCALLBACK fwrite_file_func OF ( (voidpf opaque, voidpf stream, const void *buf, uLong size )
static

◆ OF() [4/5]

static uLong ZCALLBACK fread_file_func OF ( (voidpf opaque, voidpf stream, void *buf, uLong size )
static

◆ OF() [5/5]