-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathioapi.cpp
113 lines (102 loc) · 2.38 KB
/
ioapi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdio.h>
#include <windows.h>
#include "tp_stub.h"
#include "mz_compat.h"
static void* ZCALLBACK fopen64_file_func (void* opaque, const void* filename, int mode)
{
IStream *file = NULL;
int tjsmode = 0;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
tjsmode = TJS_BS_READ;
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
tjsmode= TJS_BS_APPEND;
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
tjsmode = TJS_BS_WRITE;
if ((filename!=NULL)) {
file = TVPCreateIStream(ttstr((const tjs_char*)filename), tjsmode);
}
return file;
}
static unsigned long ZCALLBACK fread_file_func (void* opaque, void* stream, void* buf, unsigned long size)
{
IStream *is = (IStream*)stream;
if (is) {
DWORD s;
if (is->Read(buf,size,&s) == S_OK) {
return s;
}
}
return 0;
}
static unsigned long ZCALLBACK fwrite_file_func (void* opaque, void* stream, const void* buf, unsigned long size)
{
IStream *is = (IStream*)stream;
if (is) {
DWORD s;
if (is->Write(buf,size,&s) == S_OK) {
return s;
}
}
return 0;
}
static ZPOS64_T ZCALLBACK ftell64_file_func (void* opaque, void* stream)
{
IStream *is = (IStream *)stream;
if (is) {
LARGE_INTEGER move = {0};
ULARGE_INTEGER newposition;
if (is->Seek(move, STREAM_SEEK_CUR, &newposition) == S_OK) {
return newposition.QuadPart;
}
}
return -1;
}
static long ZCALLBACK fseek64_file_func (void* opaque, void* stream, ZPOS64_T offset, int origin)
{
tjs_int dwOrigin;
switch(origin) {
case ZLIB_FILEFUNC_SEEK_CUR: dwOrigin = TJS_BS_SEEK_CUR; break;
case ZLIB_FILEFUNC_SEEK_END: dwOrigin = TJS_BS_SEEK_END; break;
case ZLIB_FILEFUNC_SEEK_SET: dwOrigin = TJS_BS_SEEK_SET; break;
default: return -1; //failed
}
IStream *is = (IStream *)stream;
if (is) {
LARGE_INTEGER move;
move.QuadPart = offset;
ULARGE_INTEGER newposition;
if (is->Seek(move, origin, &newposition) == S_OK) {
return 0;
}
}
return -1;
}
static int ZCALLBACK fclose_file_func (void* opaque, void* stream)
{
IStream *is = (IStream *)stream;
if (is) {
is->Release();
return 0;
}
return EOF;
}
static int ZCALLBACK ferror_file_func (void* opaque, void* stream)
{
IStream *is = (IStream *)stream;
if (is) {
return 0;
}
return EOF;
}
zlib_filefunc64_def TVPZlibFileFunc = {
fopen64_file_func,
fread_file_func,
fwrite_file_func,
ftell64_file_func,
fseek64_file_func,
fclose_file_func,
ferror_file_func,
NULL
};