Go to the documentation of this file.
26 #ifndef _LARGEFILE64_SOURCE
27 #define _LARGEFILE64_SOURCE
31 #include "../SDL_internal.h"
33 #if defined(__WIN32__)
34 #include "../core/windows/SDL_windows.h"
57 #include "../core/android/SDL_android.h"
62 #include "nacl_io/nacl_io.h"
69 #ifndef INVALID_SET_FILE_POINTER
70 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
73 #define READAHEAD_BUFFER_SIZE 1024
80 DWORD r_right, w_right;
81 DWORD must_exist, truncate;
87 context->hidden.windowsio.h = INVALID_HANDLE_VALUE;
89 context->hidden.windowsio.buffer.size = 0;
90 context->hidden.windowsio.buffer.left = 0;
102 || must_exist) ? GENERIC_READ : 0;
105 || truncate) ? GENERIC_WRITE : 0;
107 if (!r_right && !w_right)
110 context->hidden.windowsio.buffer.data =
112 if (!
context->hidden.windowsio.buffer.data) {
117 SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
121 h = CreateFile(tstr, (w_right | r_right),
122 (w_right) ? 0 : FILE_SHARE_READ,
NULL,
123 (must_exist | truncate | a_mode),
124 FILE_ATTRIBUTE_NORMAL,
NULL);
129 SetErrorMode(old_error_mode);
131 if (
h == INVALID_HANDLE_VALUE) {
148 if (!
context ||
context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
149 return SDL_SetError(
"windows_file_size: invalid context/file not opened");
152 if (!GetFileSizeEx(
context->hidden.windowsio.h, &
size)) {
156 return size.QuadPart;
163 LARGE_INTEGER windowsoffset;
165 if (!
context ||
context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
166 return SDL_SetError(
"windows_file_seek: invalid context/file not opened");
173 context->hidden.windowsio.buffer.left = 0;
177 windowswhence = FILE_BEGIN;
180 windowswhence = FILE_CURRENT;
183 windowswhence = FILE_END;
186 return SDL_SetError(
"windows_file_seek: Unknown value for 'whence'");
189 windowsoffset.QuadPart =
offset;
190 if (!SetFilePointerEx(
context->hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) {
193 return windowsoffset.QuadPart;
200 size_t total_read = 0;
204 total_need =
size * maxnum;
206 if (!
context ||
context->hidden.windowsio.h == INVALID_HANDLE_VALUE
210 if (
context->hidden.windowsio.buffer.left > 0) {
211 void *
data = (
char *)
context->hidden.windowsio.buffer.data +
212 context->hidden.windowsio.buffer.size -
213 context->hidden.windowsio.buffer.left;
217 context->hidden.windowsio.buffer.left -= read_ahead;
219 if (read_ahead == total_need) {
222 ptr = (
char *)
ptr + read_ahead;
223 total_need -= read_ahead;
224 total_read += read_ahead;
227 if (total_need < READAHEAD_BUFFER_SIZE) {
229 (
context->hidden.windowsio.h,
context->hidden.windowsio.buffer.data,
230 READAHEAD_BUFFER_SIZE, &byte_read,
NULL)) {
234 read_ahead =
SDL_min(total_need, (
int) byte_read);
236 context->hidden.windowsio.buffer.size = byte_read;
237 context->hidden.windowsio.buffer.left = byte_read - read_ahead;
238 total_read += read_ahead;
241 (
context->hidden.windowsio.h,
ptr, (DWORD)total_need, &byte_read,
NULL)) {
245 total_read += byte_read;
247 return (total_read /
size);
261 if (!
context ||
context->hidden.windowsio.h == INVALID_HANDLE_VALUE
262 || total_bytes <= 0 || !
size)
265 if (
context->hidden.windowsio.buffer.left) {
266 SetFilePointer(
context->hidden.windowsio.h,
267 -(LONG)
context->hidden.windowsio.buffer.left,
NULL,
269 context->hidden.windowsio.buffer.left = 0;
273 if (
context->hidden.windowsio.append) {
274 if (SetFilePointer(
context->hidden.windowsio.h, 0L,
NULL, FILE_END) ==
275 INVALID_SET_FILE_POINTER) {
282 (
context->hidden.windowsio.h,
ptr, (DWORD)total_bytes, &byte_written,
NULL)) {
287 nwritten = byte_written /
size;
296 if (
context->hidden.windowsio.h != INVALID_HANDLE_VALUE) {
297 CloseHandle(
context->hidden.windowsio.h);
298 context->hidden.windowsio.h = INVALID_HANDLE_VALUE;
311 #define fopen fopen64
314 #define fseek_off_t off64_t
315 #define fseek fseeko64
316 #define ftell ftello64
317 #elif defined(HAVE_FSEEKO)
318 #if defined(OFF_MIN) && defined(OFF_MAX)
319 #define FSEEK_OFF_MIN OFF_MIN
320 #define FSEEK_OFF_MAX OFF_MAX
321 #elif defined(HAVE_LIMITS_H)
328 #define FSEEK_OFF_MAX (((((off_t)1 << (sizeof(off_t) * CHAR_BIT - 2)) - 1) << 1) + 1)
329 #define FSEEK_OFF_MIN (-(FSEEK_OFF_MAX) - 1)
331 #define fseek_off_t off_t
334 #elif defined(HAVE__FSEEKI64)
335 #define fseek_off_t __int64
336 #define fseek _fseeki64
337 #define ftell _ftelli64
340 #define FSEEK_OFF_MIN LONG_MIN
341 #define FSEEK_OFF_MAX LONG_MAX
343 #define fseek_off_t long
370 stdiowhence = SEEK_SET;
373 stdiowhence = SEEK_CUR;
376 stdiowhence = SEEK_END;
382 #if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
388 if (fseek(
context->hidden.stdio.fp, (fseek_off_t)
offset, stdiowhence) == 0) {
404 if (nread == 0 && ferror(
context->hidden.stdio.fp)) {
416 if (nwrote == 0 && ferror(
context->hidden.stdio.fp)) {
427 if (
context->hidden.stdio.autoclose) {
429 if (fclose(
context->hidden.stdio.fp) != 0) {
465 if (newpos < context->hidden.mem.base) {
466 newpos =
context->hidden.mem.base;
468 if (newpos >
context->hidden.mem.stop) {
469 newpos =
context->hidden.mem.stop;
471 context->hidden.mem.here = newpos;
479 size_t mem_available;
481 total_bytes = (maxnum *
size);
482 if ((maxnum <= 0) || (
size <= 0)
483 || ((total_bytes / maxnum) !=
size)) {
487 mem_available = (
context->hidden.mem.stop -
context->hidden.mem.here);
488 if (total_bytes > mem_available) {
489 total_bytes = mem_available;
493 context->hidden.mem.here += total_bytes;
495 return (total_bytes /
size);
532 if (!file || !*file || !
mode || !*
mode) {
533 SDL_SetError(
"SDL_RWFromFile(): No file or no mode specified");
536 #if defined(__ANDROID__)
540 FILE *fp = fopen(file,
mode);
578 #elif defined(__WIN32__)
582 if (windows_file_open(rwops, file,
mode) < 0) {
586 rwops->
size = windows_file_size;
587 rwops->
seek = windows_file_seek;
588 rwops->
read = windows_file_read;
589 rwops->
write = windows_file_write;
590 rwops->
close = windows_file_close;
596 FILE *fp = SDL_OpenFPFromBundleOrFallback(file,
mode);
599 fopen_s(&fp, file,
mode);
601 FILE *fp = fopen(file,
mode);
624 rwops->
size = stdio_size;
625 rwops->
seek = stdio_seek;
626 rwops->
read = stdio_read;
627 rwops->
write = stdio_write;
628 rwops->
close = stdio_close;
724 const int FILE_CHUNK_SIZE = 1024;
726 size_t size_read, size_total;
736 size = FILE_CHUNK_SIZE;
742 if ((((
Sint64)size_total) + FILE_CHUNK_SIZE) >
size) {
743 size = (size_total + FILE_CHUNK_SIZE);
755 if (size_read == 0) {
758 size_total += size_read;
762 *datasize = size_total;
764 ((
char *)
data)[size_total] =
'\0';
767 if (freesrc &&
src) {
void SDL_FreeRW(SDL_RWops *area)
Sint64(* size)(struct SDL_RWops *context)
#define SDL_RWOPS_JNIFILE
#define WIN_UTF8ToString(S)
union SDL_RWops::@2 hidden
int SDL_RWclose(SDL_RWops *context)
struct SDL_RWops::@2::@4 stdio
Uint32 SDL_ReadBE32(SDL_RWops *src)
Sint64 SDL_RWtell(SDL_RWops *context)
#define SDL_RWOPS_WINFILE
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Sint64 SDL_RWseek(SDL_RWops *context, Sint64 offset, int whence)
void * SDL_LoadFile(const char *file, size_t *datasize)
#define SDL_InvalidParamError(param)
static size_t mem_writeconst(SDL_RWops *context, const void *ptr, size_t size, size_t num)
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
SDL_RWops * SDL_RWFromConstMem(const void *mem, int size)
GLsizei const GLchar *const * path
static Sint64 mem_size(SDL_RWops *context)
Uint64 SDL_ReadLE64(SDL_RWops *src)
size_t SDL_WriteLE32(SDL_RWops *dst, Uint32 value)
#define SDL_RWOPS_UNKNOWN
GLfloat GLfloat GLfloat GLfloat h
SDL_RWops * SDL_AllocRW(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_stack_alloc(type, count)
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
void * SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
Sint64 SDL_RWsize(SDL_RWops *context)
SDL_RWops * SDL_RWFromFile(const char *file, const char *mode)
Uint16 SDL_ReadBE16(SDL_RWops *src)
static screen_context_t context
static size_t mem_write(SDL_RWops *context, const void *ptr, size_t size, size_t num)
SDL_RWops * SDL_RWFromFP(void *fp, SDL_bool autoclose)
int(* close)(struct SDL_RWops *context)
size_t SDL_WriteBE16(SDL_RWops *dst, Uint16 value)
size_t SDL_WriteBE32(SDL_RWops *dst, Uint32 value)
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size, size_t maxnum)
size_t SDL_WriteBE64(SDL_RWops *dst, Uint64 value)
static int mem_close(SDL_RWops *context)
Uint32 SDL_ReadLE32(SDL_RWops *src)
size_t SDL_WriteLE64(SDL_RWops *dst, Uint64 value)
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
int Android_JNI_FileOpen(SDL_RWops *ctx, const char *fileName, const char *mode)
static Sint64 mem_seek(SDL_RWops *context, Sint64 offset, int whence)
int Android_JNI_FileClose(SDL_RWops *ctx)
#define SDL_OutOfMemory()
#define SDL_RWOPS_MEMORY_RO
struct SDL_RWops::@2::@5 mem
size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size, size_t num)
#define SDL_stack_free(data)
GLsizei const GLfloat * value
SDL_RWops * SDL_RWFromMem(void *mem, int size)
int WIN_SetError(const char *prefix)
size_t SDL_RWread(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Uint8 SDL_ReadU8(SDL_RWops *src)
#define SDL_RWOPS_STDFILE
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size, size_t num)
size_t SDL_WriteU8(SDL_RWops *dst, Uint8 value)
Uint64 SDL_ReadBE64(SDL_RWops *src)
Uint16 SDL_ReadLE16(SDL_RWops *src)
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
size_t SDL_WriteLE16(SDL_RWops *dst, Uint16 value)
static size_t mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
#define SDL_AndroidGetInternalStoragePath