SDL_rwops.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL_endian.h"`
`#include "SDL_rwops.h"`
Include dependency graph for SDL_rwops.c:

Go to the source code of this file.

## Macros

#define | _LARGEFILE64_SOURCE

## Functions

static Sint64 | mem_size (SDL_RWops *context)
static Sint64 | mem_seek (SDL_RWops *context, Sint64 offset, int whence)
static size_t | mem_read (SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
static size_t | mem_write (SDL_RWops *context, const void *ptr, size_t size, size_t num)
static size_t | mem_writeconst (SDL_RWops *context, const void *ptr, size_t size, size_t num)
static int | mem_close (SDL_RWops *context)
SDL_RWops * | SDL_RWFromFile (const char *file, const char *mode)
SDL_RWops * | SDL_RWFromFP (void *fp, SDL_bool autoclose)
SDL_RWops * | SDL_RWFromMem (void *mem, int size)
SDL_RWops * | SDL_RWFromConstMem (const void *mem, int size)
SDL_RWops * | SDL_AllocRW (void)
void | SDL_FreeRW (SDL_RWops *area)
Uint8 | SDL_ReadU8 (SDL_RWops *src)
Uint16 | SDL_ReadLE16 (SDL_RWops *src)
Uint16 | SDL_ReadBE16 (SDL_RWops *src)
Uint32 | SDL_ReadLE32 (SDL_RWops *src)
Uint32 | SDL_ReadBE32 (SDL_RWops *src)
Uint64 | SDL_ReadLE64 (SDL_RWops *src)
Uint64 | SDL_ReadBE64 (SDL_RWops *src)
size_t | SDL_WriteU8 (SDL_RWops *dst, Uint8 value)
size_t | SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
size_t | SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
size_t | SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
size_t | SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
size_t | SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
size_t | SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)

## Macro Definition Documentation

#define _LARGEFILE64_SOURCE

Definition at line 22 of file SDL_rwops.c.

## Function Documentation

static int mem_close | ( | SDL_RWops * | context | ) |

static

Definition at line 454 of file SDL_rwops.c.

References SDL_FreeRW().

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

{
if (context) {
SDL_FreeRW(context);
}
return 0;
}
SDL_FreeRW
void SDL_FreeRW(SDL_RWops *area)
Definition: SDL_rwops.c:651

static size_t mem_read | ( | SDL_RWops * | context,
|  | void * | ptr,
|  | size_t | size,
|  | size_t | maxnum
| ) |  |

static

Definition at line 413 of file SDL_rwops.c.

References SDL_RWops::hidden, SDL_RWops::mem, SDL_memcpy, and SDLCALL.

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

{
size_t total_bytes;
size_t mem_available;
total_bytes = (maxnum * size);
if ((maxnum <= 0) || (size <= 0)
|| ((total_bytes / maxnum) != (size_t) size)) {
return 0;
}
mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
if (total_bytes > mem_available) {
total_bytes = mem_available;
}
SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
context->hidden.mem.here += total_bytes;
return (total_bytes / size);
}
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:393
SDL_RWops::hidden
union SDL_RWops::@10 hidden

static Sint64 mem_seek | ( | SDL_RWops * | context,
|  | Sint64 | offset,
|  | int | whence
| ) |  |

static

Definition at line 385 of file SDL_rwops.c.

References SDL_RWops::hidden, SDL_RWops::mem, RW_SEEK_CUR, RW_SEEK_END, RW_SEEK_SET, SDL_SetError, and SDLCALL.

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

{
Uint8 *newpos;
switch (whence) {
case RW_SEEK_SET:
newpos = context->hidden.mem.base + offset;
break;
case RW_SEEK_CUR:
newpos = context->hidden.mem.here + offset;
break;
case RW_SEEK_END:
newpos = context->hidden.mem.stop + offset;
break;
default:
return SDL_SetError("Unknown value for 'whence'");
}
if (newpos < context->hidden.mem.base) {
newpos = context->hidden.mem.base;
}
if (newpos > context->hidden.mem.stop) {
newpos = context->hidden.mem.stop;
}
context->hidden.mem.here = newpos;
return (Sint64)(context->hidden.mem.here - context->hidden.mem.base);
}
RW_SEEK_END
#define RW_SEEK_END
Definition: SDL_rwops.h:176
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_RWops::hidden
union SDL_RWops::@10 hidden
RW_SEEK_SET
#define RW_SEEK_SET
Definition: SDL_rwops.h:174
RW_SEEK_CUR
#define RW_SEEK_CUR
Definition: SDL_rwops.h:175
Sint64
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:162

static Sint64 mem_size | ( | SDL_RWops * | context | ) |

static

Definition at line 379 of file SDL_rwops.c.

References SDL_RWops::hidden, SDL_RWops::mem, and SDLCALL.

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

{
return (Sint64)(context->hidden.mem.stop - context->hidden.mem.base);
}
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
SDL_RWops::hidden
union SDL_RWops::@10 hidden
Sint64
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:162

static size_t mem_write | ( | SDL_RWops * | context,
|  | const void * | ptr,
|  | size_t | size,
|  | size_t | num
| ) |  |

static

Definition at line 436 of file SDL_rwops.c.

References SDL_RWops::hidden, SDL_RWops::mem, SDL_memcpy, and SDLCALL.

Referenced by SDL_RWFromMem().

{
if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) {
num = (context->hidden.mem.stop - context->hidden.mem.here) / size;
}
SDL_memcpy(context->hidden.mem.here, ptr, num * size);
context->hidden.mem.here += num * size;
return num;
}
num
GLuint num
Definition: SDL_opengl_glext.h:4956
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:393
SDL_RWops::hidden
union SDL_RWops::@10 hidden

static size_t mem_writeconst | ( | SDL_RWops * | context,
|  | const void * | ptr,
|  | size_t | size,
|  | size_t | num
| ) |  |

static

Definition at line 447 of file SDL_rwops.c.

References SDL_SetError, and SDLCALL.

Referenced by SDL_RWFromConstMem().

{
SDL_SetError("Can't write to read-only memory");
return 0;
}
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

SDL_RWops* SDL_AllocRW | ( | void |  | ) |

Definition at line 637 of file SDL_rwops.c.

References NULL, SDL_malloc, SDL_OutOfMemory, SDL_RWOPS_UNKNOWN, and SDL_RWops::type.

Referenced by SDL_RWFromConstMem(), SDL_RWFromFile(), and SDL_RWFromMem().

{
SDL_RWops *area;
area = (SDL_RWops *) SDL_malloc(sizeof *area);
if (area == NULL) {
SDL_OutOfMemory();
} else {
area->type = SDL_RWOPS_UNKNOWN;
}
return area;
}
SDL_RWops
Definition: SDL_rwops.h:52
SDL_RWOPS_UNKNOWN
#define SDL_RWOPS_UNKNOWN
Definition: SDL_rwops.h:42
SDL_RWops::type
Uint32 type
Definition: SDL_rwops.h:93
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:380

void SDL_FreeRW | ( | SDL_RWops * | area | ) |

Definition at line 651 of file SDL_rwops.c.

References SDL_free().

Referenced by mem_close(), and SDL_RWFromFile().

{
SDL_free(area);
}
SDL_free
void SDL_free(void *mem)

Uint16 SDL_ReadBE16 | ( | SDL_RWops * | src | ) |

Definition at line 677 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE16.

{
Uint16 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapBE16(value);
}
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
SDL_SwapBE16
#define SDL_SwapBE16(X)
Definition: SDL_endian.h:215
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147

Uint32 SDL_ReadBE32 | ( | SDL_RWops * | src | ) |

Definition at line 695 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE32.

{
Uint32 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapBE32(value);
}
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
SDL_SwapBE32
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:216
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

Uint64 SDL_ReadBE64 | ( | SDL_RWops * | src | ) |

Definition at line 713 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE64.

{
Uint64 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapBE64(value);
}
SDL_SwapBE64
#define SDL_SwapBE64(X)
Definition: SDL_endian.h:217
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

Uint16 SDL_ReadLE16 | ( | SDL_RWops * | src | ) |

Definition at line 668 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE16.

{
Uint16 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapLE16(value);
}
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
SDL_SwapLE16
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:211

Uint32 SDL_ReadLE32 | ( | SDL_RWops * | src | ) |

Definition at line 686 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE32.

{
Uint32 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapLE32(value);
}
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_SwapLE32
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:212

Uint64 SDL_ReadLE64 | ( | SDL_RWops * | src | ) |

Definition at line 704 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE64.

{
Uint64 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapLE64(value);
}
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
SDL_SwapLE64
#define SDL_SwapLE64(X)
Definition: SDL_endian.h:213
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

Uint8 SDL_ReadU8 | ( | SDL_RWops * | src | ) |

Definition at line 659 of file SDL_rwops.c.

References SDL_RWread.

{
Uint8 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return value;
}
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139

SDL_RWops* SDL_RWFromConstMem | ( | const void * | mem,
|  | int | size
| ) |  |

Definition at line 609 of file SDL_rwops.c.

References SDL_RWops::close, SDL_RWops::hidden, SDL_RWops::mem, mem_close(), mem_read(), mem_seek(), mem_size(), mem_writeconst(), NULL, SDL_RWops::read, SDL_AllocRW(), SDL_InvalidParamError, SDL_RWOPS_MEMORY_RO, SDL_RWops::seek, SDL_RWops::size, SDL_RWops::type, and SDL_RWops::write.

{
SDL_RWops *rwops = NULL;
if (!mem) {
SDL_InvalidParamError("mem");
return rwops;
}
if (!size) {
SDL_InvalidParamError("size");
return rwops;
}
rwops = SDL_AllocRW();
if (rwops != NULL) {
rwops->size = mem_size;
rwops->seek = mem_seek;
rwops->read = mem_read;
rwops->write = mem_writeconst;
rwops->close = mem_close;
rwops->hidden.mem.base = (Uint8 *) mem;
rwops->hidden.mem.here = rwops->hidden.mem.base;
rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
rwops->type = SDL_RWOPS_MEMORY_RO;
}
return rwops;
}
SDL_RWops
Definition: SDL_rwops.h:52
SDL_RWops::write
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
mem_writeconst
static size_t mem_writeconst(SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.c:447
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
mem_size
static Sint64 mem_size(SDL_RWops *context)
Definition: SDL_rwops.c:379
SDL_RWops::type
Uint32 type
Definition: SDL_rwops.h:93
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
SDL_RWops::seek
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
SDL_AllocRW
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:637
mem_close
static int mem_close(SDL_RWops *context)
Definition: SDL_rwops.c:454
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_RWops::close
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
mem_seek
static Sint64 mem_seek(SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.c:385
SDL_RWops::size
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
NULL
#define NULL
Definition: begin_code.h:143
SDL_RWops::hidden
union SDL_RWops::@10 hidden
SDL_RWOPS_MEMORY_RO
#define SDL_RWOPS_MEMORY_RO
Definition: SDL_rwops.h:47
SDL_RWops::read
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
mem_read
static size_t mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.c:413

SDL_RWops* SDL_RWFromFile | ( | const char * | file,
|  | const char * | mode
| ) |  |

Definition at line 466 of file SDL_rwops.c.

References Android_JNI_FileClose(), Android_JNI_FileOpen(), Android_JNI_FileRead(), Android_JNI_FileSeek(), Android_JNI_FileSize(), Android_JNI_FileWrite(), SDL_RWops::close, SDL_RWops::hidden, NULL, SDL_RWops::read, SDL_AllocRW(), SDL_AndroidGetInternalStoragePath, SDL_FreeRW(), SDL_RWFromFP(), SDL_RWOPS_JNIFILE, SDL_RWOPS_STDFILE, SDL_RWOPS_WINFILE, SDL_SetError, SDL_snprintf, SDL_stack_alloc, SDL_stack_free, SDL_RWops::seek, SDL_RWops::size, SDL_RWops::stdio, SDL_RWops::type, and SDL_RWops::write.

{
SDL_RWops *rwops = NULL;
if (!file || !*file || !mode || !*mode) {
SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
return NULL;
}
#if defined(__ANDROID__)
#ifdef HAVE_STDIO_H
/* Try to open the file on the filesystem first */
if (*file == '/') {
FILE *fp = fopen(file, mode);
if (fp) {
return SDL_RWFromFP(fp, 1);
}
} else {
/* Try opening it from internal storage if it's a relative path */
char *path;
FILE *fp;
path = SDL_stack_alloc(char, PATH_MAX);
if (path) {
SDL_snprintf(path, PATH_MAX, "%s/%s",
SDL_AndroidGetInternalStoragePath(), file);
fp = fopen(path, mode);
SDL_stack_free(path);
if (fp) {
return SDL_RWFromFP(fp, 1);
}
}
}
#endif /* HAVE_STDIO_H */
/* Try to open the file from the asset system */
rwops = SDL_AllocRW();
if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
SDL_FreeRW(rwops);
return NULL;
}
rwops->size = Android_JNI_FileSize;
rwops->seek = Android_JNI_FileSeek;
rwops->read = Android_JNI_FileRead;
rwops->write = Android_JNI_FileWrite;
rwops->close = Android_JNI_FileClose;
rwops->type = SDL_RWOPS_JNIFILE;
#elif defined(__WIN32__)
rwops = SDL_AllocRW();
if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
if (windows_file_open(rwops, file, mode) < 0) {
SDL_FreeRW(rwops);
return NULL;
}
rwops->size = windows_file_size;
rwops->seek = windows_file_seek;
rwops->read = windows_file_read;
rwops->write = windows_file_write;
rwops->close = windows_file_close;
rwops->type = SDL_RWOPS_WINFILE;
#elif HAVE_STDIO_H
{
#ifdef __APPLE__
FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode);
#elif __WINRT__
FILE *fp = NULL;
fopen_s(&fp, file, mode);
#else
FILE *fp = fopen(file, mode);
#endif
if (fp == NULL) {
SDL_SetError("Couldn't open %s", file);
} else {
rwops = SDL_RWFromFP(fp, 1);
}
}
#else
SDL_SetError("SDL not compiled with stdio support");
#endif /* !HAVE_STDIO_H */
return rwops;
}
Android_JNI_FileClose
int Android_JNI_FileClose(SDL_RWops *ctx)
SDL_FreeRW
void SDL_FreeRW(SDL_RWops *area)
Definition: SDL_rwops.c:651
SDL_RWops
Definition: SDL_rwops.h:52
SDL_RWOPS_WINFILE
#define SDL_RWOPS_WINFILE
Definition: SDL_rwops.h:43
SDL_RWops::write
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
Android_JNI_FileOpen
int Android_JNI_FileOpen(SDL_RWops *ctx, const char *fileName, const char *mode)
SDL_RWops::type
Uint32 type
Definition: SDL_rwops.h:93
SDL_RWops::seek
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
SDL_AllocRW
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:637
SDL_stack_alloc
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:326
SDL_RWops::close
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
SDL_RWFromFP
SDL_RWops * SDL_RWFromFP(void *fp, SDL_bool autoclose)
Definition: SDL_rwops.c:573
Android_JNI_FileWrite
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size, size_t num)
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_RWops::size
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
Android_JNI_FileRead
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size, size_t maxnum)
SDL_RWops::read
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:46
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
SDL_stack_free
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:327
SDL_AndroidGetInternalStoragePath
#define SDL_AndroidGetInternalStoragePath
Definition: SDL_dynapi_overrides.h:57
Android_JNI_FileSeek
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
Android_JNI_FileSize
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
SDL_RWOPS_JNIFILE
#define SDL_RWOPS_JNIFILE
Definition: SDL_rwops.h:45

SDL_RWops* SDL_RWFromFP | ( | void * | fp,
|  | SDL_bool | autoclose
| ) |  |

Definition at line 573 of file SDL_rwops.c.

References NULL, and SDL_SetError.

Referenced by SDL_RWFromFile().

{
SDL_SetError("SDL not compiled with stdio support");
return NULL;
}
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

SDL_RWops* SDL_RWFromMem | ( | void * | mem,
|  | int | size
| ) |  |

Definition at line 581 of file SDL_rwops.c.

References SDL_RWops::close, SDL_RWops::hidden, SDL_RWops::mem, mem_close(), mem_read(), mem_seek(), mem_size(), mem_write(), NULL, SDL_RWops::read, SDL_AllocRW(), SDL_InvalidParamError, SDL_RWOPS_MEMORY, SDL_RWops::seek, SDL_RWops::size, SDL_RWops::type, and SDL_RWops::write.

{
SDL_RWops *rwops = NULL;
if (!mem) {
SDL_InvalidParamError("mem");
return rwops;
}
if (!size) {
SDL_InvalidParamError("size");
return rwops;
}
rwops = SDL_AllocRW();
if (rwops != NULL) {
rwops->size = mem_size;
rwops->seek = mem_seek;
rwops->read = mem_read;
rwops->write = mem_write;
rwops->close = mem_close;
rwops->hidden.mem.base = (Uint8 *) mem;
rwops->hidden.mem.here = rwops->hidden.mem.base;
rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
rwops->type = SDL_RWOPS_MEMORY;
}
return rwops;
}
SDL_RWops
Definition: SDL_rwops.h:52
SDL_RWops::write
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
mem_size
static Sint64 mem_size(SDL_RWops *context)
Definition: SDL_rwops.c:379
SDL_RWops::type
Uint32 type
Definition: SDL_rwops.h:93
SDL_RWops::mem
struct SDL_RWops::@10::@13 mem
SDL_RWops::seek
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
mem_write
static size_t mem_write(SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.c:436
SDL_AllocRW
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:637
mem_close
static int mem_close(SDL_RWops *context)
Definition: SDL_rwops.c:454
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_RWops::close
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
mem_seek
static Sint64 mem_seek(SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.c:385
SDL_RWops::size
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
NULL
#define NULL
Definition: begin_code.h:143
SDL_RWOPS_MEMORY
#define SDL_RWOPS_MEMORY
Definition: SDL_rwops.h:46
SDL_RWops::hidden
union SDL_RWops::@10 hidden
SDL_RWops::read
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
mem_read
static size_t mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.c:413

size_t SDL_WriteBE16 | ( | SDL_RWops * | dst,
|  | Uint16 | value
| ) |  |

Definition at line 735 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE16.

{
const Uint16 swapped = SDL_SwapBE16(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
SDL_SwapBE16
#define SDL_SwapBE16(X)
Definition: SDL_endian.h:215
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147

size_t SDL_WriteBE32 | ( | SDL_RWops * | dst,
|  | Uint32 | value
| ) |  |

Definition at line 749 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE32.

{
const Uint32 swapped = SDL_SwapBE32(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
SDL_SwapBE32
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:216
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

size_t SDL_WriteBE64 | ( | SDL_RWops * | dst,
|  | Uint64 | value
| ) |  |

Definition at line 763 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE64.

{
const Uint64 swapped = SDL_SwapBE64(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
SDL_SwapBE64
#define SDL_SwapBE64(X)
Definition: SDL_endian.h:217
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

size_t SDL_WriteLE16 | ( | SDL_RWops * | dst,
|  | Uint16 | value
| ) |  |

Definition at line 728 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE16.

{
const Uint16 swapped = SDL_SwapLE16(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
SDL_SwapLE16
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:211

size_t SDL_WriteLE32 | ( | SDL_RWops * | dst,
|  | Uint32 | value
| ) |  |

Definition at line 742 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE32.

{
const Uint32 swapped = SDL_SwapLE32(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_SwapLE32
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:212

size_t SDL_WriteLE64 | ( | SDL_RWops * | dst,
|  | Uint64 | value
| ) |  |

Definition at line 756 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE64.

{
const Uint64 swapped = SDL_SwapLE64(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
}
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
SDL_SwapLE64
#define SDL_SwapLE64(X)
Definition: SDL_endian.h:213
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

size_t SDL_WriteU8 | ( | SDL_RWops * | dst,
|  | Uint8 | value
| ) |  |

Definition at line 722 of file SDL_rwops.c.

References SDL_RWwrite.

{
return SDL_RWwrite(dst, &value, sizeof (value), 1);
}
SDL_RWwrite
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698