14 stream->
close = close;
30 return stream->
read(stream->
data, buffer, count);
35 return stream->
seek(stream->
data, offset, origin);
40 return stream->
seek(stream->
data, count, SEEK_CUR);
55 static size_t file_read(
void *data,
void *buffer,
size_t count)
57 return fread(buffer, 1, count, data);
63 return _fseeki64(data, offset, origin) == 0;
65 #if _POSIX_C_SOURCE >= 200112L
66 if (
sizeof(off_t) == 8)
67 return fseeko(data, offset, origin) == 0;
69 if (offset > INT32_MAX || offset < INT32_MIN)
71 return fseek(data, (
long)offset, origin) == 0;
78 return _ftelli64(data);
79 #elif _POSIX_C_SOURCE >= 200112L
88 FILE *f = path ? fopen(path,
"rb") : NULL;
95 ar_stream *ar_open_file_w(
const wchar_t *path)
97 FILE *f = path ? _wfopen(path, L
"rb") : NULL;
131 if (origin == SEEK_CUR)
133 else if (origin == SEEK_END)
137 stm->
offset = (size_t)offset;
164 static void stream_close(
void *
data)
166 IUnknown_Release((IStream *)data);
169 static size_t stream_read(
void *data,
void *buffer,
size_t count)
175 while (count > ULONG_MAX) {
176 res = IStream_Read((IStream *)data, buffer, ULONG_MAX, &cbRead);
180 buffer = (BYTE *)buffer + ULONG_MAX;
184 res = IStream_Read((IStream *)data, buffer, (ULONG)count, &cbRead);
190 static bool stream_seek(
void *data,
off64_t offset,
int origin)
196 res = IStream_Seek((IStream *)data, off, origin, &n);
197 return SUCCEEDED(res);
200 static off64_t stream_tell(
void *data)
202 LARGE_INTEGER zero = { 0 };
203 ULARGE_INTEGER n = { 0 };
204 IStream_Seek((IStream *)data, zero, SEEK_CUR, &n);
208 ar_stream *ar_open_istream(IStream *stream)
210 LARGE_INTEGER zero = { 0 };
211 HRESULT res = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
214 IUnknown_AddRef(stream);
215 return ar_open_stream(stream, stream_close, stream_read, stream_seek, stream_tell);