22 #define _LARGEFILE64_SOURCE
37 #include "../core/android/SDL_android.h"
45 #include "../core/windows/SDL_windows.h"
47 #ifndef INVALID_SET_FILE_POINTER
48 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
51 #define READAHEAD_BUFFER_SIZE 1024
58 DWORD r_right, w_right;
59 DWORD must_exist, truncate;
65 context->
hidden.windowsio.h = INVALID_HANDLE_VALUE;
68 context->
hidden.windowsio.buffer.left = 0;
80 || must_exist) ? GENERIC_READ : 0;
83 || truncate) ? GENERIC_WRITE : 0;
85 if (!r_right && !w_right)
88 context->
hidden.windowsio.buffer.data =
90 if (!context->
hidden.windowsio.buffer.data) {
95 SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
99 h = CreateFile(tstr, (w_right | r_right),
100 (w_right) ? 0 : FILE_SHARE_READ,
NULL,
101 (must_exist | truncate | a_mode),
102 FILE_ATTRIBUTE_NORMAL,
NULL);
107 SetErrorMode(old_error_mode);
109 if (h == INVALID_HANDLE_VALUE) {
115 context->
hidden.windowsio.h =
h;
126 if (!context || context->
hidden.windowsio.h == INVALID_HANDLE_VALUE) {
127 return SDL_SetError(
"windows_file_size: invalid context/file not opened");
130 if (!GetFileSizeEx(context->
hidden.windowsio.h, &size)) {
134 return size.QuadPart;
141 LARGE_INTEGER windowsoffset;
143 if (!context || context->
hidden.windowsio.h == INVALID_HANDLE_VALUE) {
144 return SDL_SetError(
"windows_file_seek: invalid context/file not opened");
149 offset -= (long)context->
hidden.windowsio.buffer.left;
151 context->
hidden.windowsio.buffer.left = 0;
155 windowswhence = FILE_BEGIN;
158 windowswhence = FILE_CURRENT;
161 windowswhence = FILE_END;
164 return SDL_SetError(
"windows_file_seek: Unknown value for 'whence'");
167 windowsoffset.QuadPart =
offset;
168 if (!SetFilePointerEx(context->
hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) {
171 return windowsoffset.QuadPart;
175 windows_file_read(
SDL_RWops * context,
void *ptr,
size_t size,
size_t maxnum)
178 size_t total_read = 0;
182 total_need = size * maxnum;
184 if (!context || context->
hidden.windowsio.h == INVALID_HANDLE_VALUE
188 if (context->
hidden.windowsio.buffer.left > 0) {
189 void *
data = (
char *) context->
hidden.windowsio.buffer.data +
191 context->
hidden.windowsio.buffer.left;
195 context->
hidden.windowsio.buffer.left -= read_ahead;
197 if (read_ahead == total_need) {
200 ptr = (
char *) ptr + read_ahead;
201 total_need -= read_ahead;
202 total_read += read_ahead;
205 if (total_need < READAHEAD_BUFFER_SIZE) {
207 (context->
hidden.windowsio.h, context->
hidden.windowsio.buffer.data,
208 READAHEAD_BUFFER_SIZE, &byte_read,
NULL)) {
212 read_ahead =
SDL_min(total_need, (
int) byte_read);
214 context->
hidden.windowsio.buffer.
size = byte_read;
215 context->
hidden.windowsio.buffer.left = byte_read - read_ahead;
216 total_read += read_ahead;
219 (context->
hidden.windowsio.h, ptr, (
DWORD)total_need, &byte_read,
NULL)) {
223 total_read += byte_read;
225 return (total_read / size);
229 windows_file_write(
SDL_RWops * context,
const void *ptr,
size_t size,
237 total_bytes = size *
num;
239 if (!context || context->
hidden.windowsio.h == INVALID_HANDLE_VALUE
240 || total_bytes <= 0 || !size)
243 if (context->
hidden.windowsio.buffer.left) {
244 SetFilePointer(context->
hidden.windowsio.h,
245 -(LONG)context->
hidden.windowsio.buffer.left,
NULL,
247 context->
hidden.windowsio.buffer.left = 0;
251 if (context->
hidden.windowsio.append) {
252 if (SetFilePointer(context->
hidden.windowsio.h, 0L,
NULL, FILE_END) ==
253 INVALID_SET_FILE_POINTER) {
260 (context->
hidden.windowsio.h, ptr, (
DWORD)total_bytes, &byte_written,
NULL)) {
265 nwritten = byte_written /
size;
274 if (context->
hidden.windowsio.h != INVALID_HANDLE_VALUE) {
275 CloseHandle(context->
hidden.windowsio.h);
276 context->
hidden.windowsio.h = INVALID_HANDLE_VALUE;
309 if (fseeko64(context->
hidden.stdio.fp, (off64_t)offset, whence) == 0) {
310 return ftello64(context->
hidden.stdio.fp);
312 #elif defined(HAVE_FSEEKO)
313 if (fseeko(context->
hidden.stdio.fp, (off_t)offset, whence) == 0) {
314 return ftello(context->
hidden.stdio.fp);
317 if (fseek(context->
hidden.stdio.fp, offset, whence) == 0) {
318 return (ftell(context->
hidden.stdio.fp));
325 stdio_read(
SDL_RWops * context,
void *ptr,
size_t size,
size_t maxnum)
329 nread = fread(ptr, size, maxnum, context->
hidden.stdio.fp);
330 if (nread == 0 && ferror(context->
hidden.stdio.fp)) {
337 stdio_write(
SDL_RWops * context,
const void *ptr,
size_t size,
size_t num)
341 nwrote = fwrite(ptr, size, num, context->
hidden.stdio.fp);
342 if (nwrote == 0 && ferror(context->
hidden.stdio.fp)) {
353 if (context->
hidden.stdio.autoclose) {
355 if (fclose(context->
hidden.stdio.fp) != 0) {
391 if (newpos < context->hidden.mem.base) {
405 size_t mem_available;
407 total_bytes = (maxnum *
size);
408 if ((maxnum <= 0) || (size <= 0)
409 || ((total_bytes / maxnum) != (
size_t) size)) {
414 if (total_bytes > mem_available) {
415 total_bytes = mem_available;
421 return (total_bytes / size);
458 if (!file || !*file || !mode || !*mode) {
459 SDL_SetError(
"SDL_RWFromFile(): No file or no mode specified");
466 FILE *fp = fopen(file, mode);
478 SDL_AndroidGetInternalStoragePath(), file);
479 fp = fopen(path, mode);
503 #elif defined(__WIN32__)
507 if (windows_file_open(rwops, file, mode) < 0) {
511 rwops->
size = windows_file_size;
512 rwops->seek = windows_file_seek;
513 rwops->read = windows_file_read;
514 rwops->write = windows_file_write;
515 rwops->close = windows_file_close;
521 FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode);
523 FILE *fp = fopen(file, mode);
546 rwops->
size = stdio_size;
547 rwops->seek = stdio_seek;
548 rwops->read = stdio_read;
549 rwops->write = stdio_write;
550 rwops->close = stdio_close;
551 rwops->
hidden.stdio.fp = fp;
552 rwops->
hidden.stdio.autoclose = autoclose;
710 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
717 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
724 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
731 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
738 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
745 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
752 return (
SDL_RWwrite(dst, &value, (
sizeof value), 1));
DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src)
DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops *src)
int Android_JNI_FileClose(SDL_RWops *ctx)
#define WIN_UTF8ToString(S)
GLfloat GLfloat GLfloat GLfloat h
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
#define SDL_stack_free(data)
#define SDL_RWwrite(ctx, ptr, size, n)
DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src)
DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void *fp, SDL_bool autoclose)
#define SDL_RWOPS_WINFILE
DECLSPEC void SDLCALL SDL_free(void *mem)
#define SDL_RWread(ctx, ptr, size, n)
#define SDL_RWOPS_UNKNOWN
DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value)
#define SDL_InvalidParamError(param)
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c)
DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value)
GLsizei const GLchar *const * path
int Android_JNI_FileOpen(SDL_RWops *ctx, const char *fileName, const char *mode)
DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void)
static int SDLCALL mem_close(SDL_RWops *context)
DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src)
#define SDL_RWseek(ctx, offset, whence)
uint32_t Uint32
An unsigned 32-bit integer type.
static size_t SDLCALL mem_write(SDL_RWops *context, const void *ptr, size_t size, size_t num)
static size_t SDLCALL mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size)
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code)
uint64_t Uint64
An unsigned 64-bit integer type.
DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area)
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size, size_t num)
static Sint64 SDLCALL mem_size(SDL_RWops *context)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src)
DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value)
static Sint64 SDLCALL mem_seek(SDL_RWops *context, Sint64 offset, int whence)
#define SDL_OutOfMemory()
static size_t SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, size_t size, size_t num)
DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src)
int WIN_SetError(const char *prefix)
EGLSurface EGLint void ** value
DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src)
#define SDL_RWOPS_STDFILE
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size, size_t maxnum)
#define SDL_RWOPS_MEMORY_RO
uint8_t Uint8
An unsigned 8-bit integer type.
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value)
union SDL_RWops::@74 hidden
DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops *dst, Uint8 value)
struct SDL_RWops::@74::@75 mem
#define SDL_stack_alloc(type, count)
uint16_t Uint16
An unsigned 16-bit integer type.
DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value)
DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem, int size)
DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value)
int64_t Sint64
A signed 64-bit integer type.
DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file, const char *mode)
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
#define SDL_RWOPS_JNIFILE