UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
ioapi.cpp
Go to the documentation of this file.
1
/* ioapi.c -- IO base function header for compress/uncompress .zip
2
files using zlib + zip or unzip API
3
4
Version 1.01e, February 12th, 2005
5
6
Copyright (C) 1998-2005 Gilles Vollant
7
*/
8
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <string.h>
12
13
#include <zlib.h>
14
#include "
ioapi.h
"
15
#include "
../ports/system.h
"
16
17
18
19
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
20
21
#ifndef SEEK_CUR
22
#define SEEK_CUR 1
23
#endif
24
25
#ifndef SEEK_END
26
#define SEEK_END 2
27
#endif
28
29
#ifndef SEEK_SET
30
#define SEEK_SET 0
31
#endif
32
33
static
voidpf
ZCALLBACK
fopen_file_func
(
voidpf
opaque,
const
char
*
filename
,
int
mode
)
34
{
35
FILE
* file = NULL;
36
const
char
* mode_fopen = NULL;
37
if
((
mode
&
ZLIB_FILEFUNC_MODE_READWRITEFILTER
)==
ZLIB_FILEFUNC_MODE_READ
)
38
mode_fopen =
"rb"
;
39
else
40
if
(
mode
&
ZLIB_FILEFUNC_MODE_EXISTING
)
41
mode_fopen =
"r+b"
;
42
else
43
if
(
mode
&
ZLIB_FILEFUNC_MODE_CREATE
)
44
mode_fopen =
"wb"
;
45
46
if
((
filename
!=NULL) && (mode_fopen != NULL))
47
file =
Sys_Fopen
(
filename
, mode_fopen);
48
return
file;
49
}
50
51
static
uLong
ZCALLBACK
fread_file_func
(
voidpf
opaque,
voidpf
stream
,
void
*
buf
,
uLong
size
)
52
{
53
return
(
uLong
)fread(
buf
, 1, (
size_t
)
size
, (
FILE
* )
stream
);
54
}
55
56
static
uLong
ZCALLBACK
fwrite_file_func
(
voidpf
opaque,
voidpf
stream
,
const
void
*
buf
,
uLong
size
)
57
{
58
return
(
uLong
)fwrite(
buf
, 1, (
size_t
)
size
, (
FILE
* )
stream
);
59
}
60
61
static
long
ZCALLBACK
ftell_file_func
(
voidpf
opaque,
voidpf
stream
)
62
{
63
return
ftell((
FILE
* )
stream
);
64
}
65
66
static
long
ZCALLBACK
fseek_file_func
(
voidpf
opaque,
voidpf
stream
,
uLong
offset
,
int
origin
)
67
{
68
int
fseek_origin=0;
69
switch
(
origin
)
70
{
71
case
ZLIB_FILEFUNC_SEEK_CUR
:
72
fseek_origin =
SEEK_CUR
;
73
break
;
74
case
ZLIB_FILEFUNC_SEEK_END
:
75
fseek_origin =
SEEK_END
;
76
break
;
77
case
ZLIB_FILEFUNC_SEEK_SET
:
78
fseek_origin =
SEEK_SET
;
79
break
;
80
default
:
return
-1;
81
}
82
return
fseek((
FILE
* )
stream
,
offset
, fseek_origin);
83
}
84
85
static
int
ZCALLBACK
fclose_file_func
(
voidpf
opaque,
voidpf
stream
)
86
{
87
return
fclose((
FILE
* )
stream
);
88
}
89
90
static
int
ZCALLBACK
ferror_file_func
(
voidpf
opaque,
voidpf
stream
)
91
{
92
return
ferror((
FILE
* )
stream
);
93
}
94
95
void
fill_fopen_filefunc
(
zlib_filefunc_def
* pzlib_filefunc_def)
96
{
97
pzlib_filefunc_def->
zopen_file
=
fopen_file_func
;
98
pzlib_filefunc_def->
zread_file
=
fread_file_func
;
99
pzlib_filefunc_def->
zwrite_file
=
fwrite_file_func
;
100
pzlib_filefunc_def->
ztell_file
=
ftell_file_func
;
101
pzlib_filefunc_def->
zseek_file
=
fseek_file_func
;
102
pzlib_filefunc_def->
zclose_file
=
fclose_file_func
;
103
pzlib_filefunc_def->
zerror_file
=
ferror_file_func
;
104
pzlib_filefunc_def->
opaque
= NULL;
105
}
fseek_file_func
static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin)
Definition
ioapi.cpp:66
SEEK_SET
#define SEEK_SET
Definition
ioapi.cpp:30
ferror_file_func
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream)
Definition
ioapi.cpp:90
SEEK_CUR
#define SEEK_CUR
Definition
ioapi.cpp:22
fwrite_file_func
static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uLong size)
Definition
ioapi.cpp:56
fill_fopen_filefunc
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
Definition
ioapi.cpp:95
SEEK_END
#define SEEK_END
Definition
ioapi.cpp:26
fopen_file_func
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode)
Definition
ioapi.cpp:33
ftell_file_func
static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream)
Definition
ioapi.cpp:61
fread_file_func
static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void *buf, uLong size)
Definition
ioapi.cpp:51
fclose_file_func
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream)
Definition
ioapi.cpp:85
ioapi.h
size
voidpf void uLong size
Definition
ioapi.h:42
ZLIB_FILEFUNC_MODE_READWRITEFILTER
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER
Definition
ioapi.h:18
voidpf
typedef voidpf(ZCALLBACK *open_file_func) OF((voidpf opaque
stream
voidpf stream
Definition
ioapi.h:42
uLong
typedef uLong(ZCALLBACK *read_file_func) OF((voidpf opaque
origin
voidpf uLong int origin
Definition
ioapi.h:45
ZLIB_FILEFUNC_MODE_EXISTING
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition
ioapi.h:20
ZLIB_FILEFUNC_SEEK_CUR
#define ZLIB_FILEFUNC_SEEK_CUR
Definition
ioapi.h:12
filename
const char * filename
Definition
ioapi.h:41
buf
voidpf void * buf
Definition
ioapi.h:42
ZLIB_FILEFUNC_SEEK_SET
#define ZLIB_FILEFUNC_SEEK_SET
Definition
ioapi.h:14
ZCALLBACK
#define ZCALLBACK
Definition
ioapi.h:29
mode
const char int mode
Definition
ioapi.h:41
ZLIB_FILEFUNC_MODE_CREATE
#define ZLIB_FILEFUNC_MODE_CREATE
Definition
ioapi.h:21
ZLIB_FILEFUNC_SEEK_END
#define ZLIB_FILEFUNC_SEEK_END
Definition
ioapi.h:13
ZLIB_FILEFUNC_MODE_READ
#define ZLIB_FILEFUNC_MODE_READ
Definition
ioapi.h:16
offset
voidpf uLong offset
Definition
ioapi.h:45
zlib_filefunc_def
Definition
ioapi.h:50
zlib_filefunc_def::zseek_file
seek_file_func zseek_file
Definition
ioapi.h:55
zlib_filefunc_def::zopen_file
open_file_func zopen_file
Definition
ioapi.h:51
zlib_filefunc_def::zwrite_file
write_file_func zwrite_file
Definition
ioapi.h:53
zlib_filefunc_def::opaque
voidpf opaque
Definition
ioapi.h:58
zlib_filefunc_def::zerror_file
testerror_file_func zerror_file
Definition
ioapi.h:57
zlib_filefunc_def::zread_file
read_file_func zread_file
Definition
ioapi.h:52
zlib_filefunc_def::ztell_file
tell_file_func ztell_file
Definition
ioapi.h:54
zlib_filefunc_def::zclose_file
close_file_func zclose_file
Definition
ioapi.h:56
system.h
System specific stuff.
Sys_Fopen
FILE * Sys_Fopen(const char *filename, const char *mode)
Definition
unix_files.cpp:240
FILE
#define FILE
Definition
test_webapi.cpp:30
src
common
ioapi.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0