SDL  2.0
SDL_rwops.h File Reference
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_rwops.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_RWops
 

Macros

#define SDL_RWOPS_UNKNOWN   0U
 
#define SDL_RWOPS_WINFILE   1U
 
#define SDL_RWOPS_STDFILE   2U
 
#define SDL_RWOPS_JNIFILE   3U
 
#define SDL_RWOPS_MEMORY   4U
 
#define SDL_RWOPS_MEMORY_RO   5U
 
#define RW_SEEK_SET   0
 
#define RW_SEEK_CUR   1
 
#define RW_SEEK_END   2
 
#define SDL_LoadFile(file, datasize)   SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, 1)
 
Read/write macros

Macros to easily read and write from an SDL_RWops structure.

#define SDL_RWsize(ctx)   (ctx)->size(ctx)
 
#define SDL_RWseek(ctx, offset, whence)   (ctx)->seek(ctx, offset, whence)
 
#define SDL_RWtell(ctx)   (ctx)->seek(ctx, 0, RW_SEEK_CUR)
 
#define SDL_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
 
#define SDL_RWwrite(ctx, ptr, size, n)   (ctx)->write(ctx, ptr, size, n)
 
#define SDL_RWclose(ctx)   (ctx)->close(ctx)
 

Functions

SDL_RWopsSDL_AllocRW (void)
 
void SDL_FreeRW (SDL_RWops *area)
 
voidSDL_LoadFile_RW (SDL_RWops *src, size_t *datasize, int freesrc)
 
RWFrom functions

Functions to create SDL_RWops structures from various data streams.

SDL_RWopsSDL_RWFromFile (const char *file, const char *mode)
 
SDL_RWopsSDL_RWFromFP (FILE *fp, SDL_bool autoclose)
 
SDL_RWopsSDL_RWFromMem (void *mem, int size)
 
SDL_RWopsSDL_RWFromConstMem (const void *mem, int size)
 
Read endian functions

Read an item of the specified endianness and return in native format.

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)
 
Write endian functions

Write an item of native format to the specified endianness.

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)
 

Detailed Description

This file provides a general interface for SDL to read and write data streams. It can easily be extended to files, memory, etc.

Definition in file SDL_rwops.h.

Macro Definition Documentation

◆ RW_SEEK_CUR

#define RW_SEEK_CUR   1

Seek relative to current read point

Definition at line 175 of file SDL_rwops.h.

Referenced by _testGenericRWopsValidations(), main(), mem_seek(), SDL_LoadBMP_RW(), and SDL_LoadWAV_RW().

◆ RW_SEEK_END

#define RW_SEEK_END   2

Seek relative to the end of data

Definition at line 176 of file SDL_rwops.h.

Referenced by _testGenericRWopsValidations(), main(), and mem_seek().

◆ RW_SEEK_SET

#define RW_SEEK_SET   0

Seek from the beginning of data

Definition at line 174 of file SDL_rwops.h.

Referenced by _testGenericRWopsValidations(), main(), mem_seek(), rwops_testFileWriteReadEndian(), SDL_LoadBMP_RW(), and SDL_SaveBMP_RW().

◆ SDL_LoadFile

#define SDL_LoadFile (   file,
  datasize 
)    SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, 1)

Load an entire file.

Convenience macro.

Definition at line 214 of file SDL_rwops.h.

Referenced by SDL_LoadVIDPIDListFromHint().

◆ SDL_RWclose

◆ SDL_RWOPS_JNIFILE

#define SDL_RWOPS_JNIFILE   3U

Android asset

Definition at line 45 of file SDL_rwops.h.

Referenced by rwops_testFileRead(), rwops_testFileWrite(), and SDL_RWFromFile().

◆ SDL_RWOPS_MEMORY

#define SDL_RWOPS_MEMORY   4U

Memory stream

Definition at line 46 of file SDL_rwops.h.

Referenced by rwops_testMem(), and SDL_RWFromMem().

◆ SDL_RWOPS_MEMORY_RO

#define SDL_RWOPS_MEMORY_RO   5U

Read-Only memory stream

Definition at line 47 of file SDL_rwops.h.

Referenced by rwops_testConstMem(), and SDL_RWFromConstMem().

◆ SDL_RWOPS_STDFILE

#define SDL_RWOPS_STDFILE   2U

◆ SDL_RWOPS_UNKNOWN

#define SDL_RWOPS_UNKNOWN   0U

Unknown stream type

Definition at line 42 of file SDL_rwops.h.

Referenced by rwops_testAllocFree(), and SDL_AllocRW().

◆ SDL_RWOPS_WINFILE

#define SDL_RWOPS_WINFILE   1U

Win32 file

Definition at line 43 of file SDL_rwops.h.

Referenced by rwops_testFileRead(), rwops_testFileWrite(), and SDL_RWFromFile().

◆ SDL_RWread

◆ SDL_RWseek

#define SDL_RWseek (   ctx,
  offset,
  whence 
)    (ctx)->seek(ctx, offset, whence)

◆ SDL_RWsize

#define SDL_RWsize (   ctx)    (ctx)->size(ctx)

Definition at line 184 of file SDL_rwops.h.

Referenced by SDL_GameControllerAddMappingsFromRW(), and SDL_LoadFile_RW().

◆ SDL_RWtell

#define SDL_RWtell (   ctx)    (ctx)->seek(ctx, 0, RW_SEEK_CUR)

Definition at line 186 of file SDL_rwops.h.

Referenced by SDL_LoadBMP_RW(), and SDL_SaveBMP_RW().

◆ SDL_RWwrite

#define SDL_RWwrite (   ctx,
  ptr,
  size,
  n 
)    (ctx)->write(ctx, ptr, size, n)

Function Documentation

◆ SDL_AllocRW()

SDL_RWops* SDL_AllocRW ( void  )

Definition at line 682 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().

683 {
684  SDL_RWops *area;
685 
686  area = (SDL_RWops *) SDL_malloc(sizeof *area);
687  if (area == NULL) {
688  SDL_OutOfMemory();
689  } else {
690  area->type = SDL_RWOPS_UNKNOWN;
691  }
692  return area;
693 }
#define SDL_RWOPS_UNKNOWN
Definition: SDL_rwops.h:42
Uint32 type
Definition: SDL_rwops.h:93
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_malloc

◆ SDL_FreeRW()

void SDL_FreeRW ( SDL_RWops area)

Definition at line 696 of file SDL_rwops.c.

References SDL_free.

Referenced by mem_close(), and SDL_RWFromFile().

697 {
698  SDL_free(area);
699 }
#define SDL_free

◆ SDL_LoadFile_RW()

void* SDL_LoadFile_RW ( SDL_RWops src,
size_t datasize,
int  freesrc 
)

Load all the data from an SDL data stream.

The data is allocated with a zero byte at the end (null terminated)

If datasize is not NULL, it is filled with the size of the data read.

If freesrc is non-zero, the stream will be closed after being read.

The data should be freed with SDL_free().

Returns
the data, or NULL if there was an error.

Definition at line 703 of file SDL_rwops.c.

References done, NULL, SDL_free, SDL_InvalidParamError, SDL_malloc, SDL_OutOfMemory, SDL_realloc, SDL_RWclose, SDL_RWread, and SDL_RWsize.

704 {
705  const int FILE_CHUNK_SIZE = 1024;
706  Sint64 size;
707  size_t size_read, size_total;
708  void *data = NULL, *newdata;
709 
710  if (!src) {
711  SDL_InvalidParamError("src");
712  return NULL;
713  }
714 
715  size = SDL_RWsize(src);
716  if (size < 0) {
717  size = FILE_CHUNK_SIZE;
718  }
719  data = SDL_malloc((size_t)(size + 1));
720 
721  size_total = 0;
722  for (;;) {
723  if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) {
724  size = (size_total + FILE_CHUNK_SIZE);
725  newdata = SDL_realloc(data, (size_t)(size + 1));
726  if (!newdata) {
727  SDL_free(data);
728  data = NULL;
729  SDL_OutOfMemory();
730  goto done;
731  }
732  data = newdata;
733  }
734 
735  size_read = SDL_RWread(src, (char *)data+size_total, 1, (size_t)(size-size_total));
736  if (size_read == 0) {
737  break;
738  }
739  size_total += size_read;
740  }
741 
742  if (datasize) {
743  *datasize = size_total;
744  }
745  ((char *)data)[size_total] = '\0';
746 
747 done:
748  if (freesrc && src) {
749  SDL_RWclose(src);
750  }
751  return data;
752 }
#define SDL_RWsize(ctx)
Definition: SDL_rwops.h:184
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
#define SDL_realloc
#define SDL_free
int done
Definition: checkkeys.c:28
GLsizeiptr size
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_RWclose(ctx)
Definition: SDL_rwops.h:189
#define SDL_malloc
int64_t Sint64
Definition: SDL_stdinc.h:188

◆ SDL_ReadBE16()

Uint16 SDL_ReadBE16 ( SDL_RWops src)

Definition at line 775 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE16.

776 {
777  Uint16 value = 0;
778 
779  SDL_RWread(src, &value, sizeof (value), 1);
780  return SDL_SwapBE16(value);
781 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
#define SDL_SwapBE16(X)
Definition: SDL_endian.h:236
GLsizei const GLfloat * value
uint16_t Uint16
Definition: SDL_stdinc.h:169

◆ SDL_ReadBE32()

Uint32 SDL_ReadBE32 ( SDL_RWops src)

Definition at line 793 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE32.

794 {
795  Uint32 value = 0;
796 
797  SDL_RWread(src, &value, sizeof (value), 1);
798  return SDL_SwapBE32(value);
799 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:237
GLsizei const GLfloat * value

◆ SDL_ReadBE64()

Uint64 SDL_ReadBE64 ( SDL_RWops src)

Definition at line 811 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapBE64.

812 {
813  Uint64 value = 0;
814 
815  SDL_RWread(src, &value, sizeof (value), 1);
816  return SDL_SwapBE64(value);
817 }
#define SDL_SwapBE64(X)
Definition: SDL_endian.h:238
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
uint64_t Uint64
Definition: SDL_stdinc.h:194
GLsizei const GLfloat * value

◆ SDL_ReadLE16()

Uint16 SDL_ReadLE16 ( SDL_RWops src)

Definition at line 766 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE16.

767 {
768  Uint16 value = 0;
769 
770  SDL_RWread(src, &value, sizeof (value), 1);
771  return SDL_SwapLE16(value);
772 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
GLsizei const GLfloat * value
uint16_t Uint16
Definition: SDL_stdinc.h:169
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:232

◆ SDL_ReadLE32()

Uint32 SDL_ReadLE32 ( SDL_RWops src)

Definition at line 784 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE32.

785 {
786  Uint32 value = 0;
787 
788  SDL_RWread(src, &value, sizeof (value), 1);
789  return SDL_SwapLE32(value);
790 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:233
GLsizei const GLfloat * value

◆ SDL_ReadLE64()

Uint64 SDL_ReadLE64 ( SDL_RWops src)

Definition at line 802 of file SDL_rwops.c.

References SDL_RWread, and SDL_SwapLE64.

803 {
804  Uint64 value = 0;
805 
806  SDL_RWread(src, &value, sizeof (value), 1);
807  return SDL_SwapLE64(value);
808 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
uint64_t Uint64
Definition: SDL_stdinc.h:194
#define SDL_SwapLE64(X)
Definition: SDL_endian.h:234
GLsizei const GLfloat * value

◆ SDL_ReadU8()

Uint8 SDL_ReadU8 ( SDL_RWops src)

Definition at line 757 of file SDL_rwops.c.

References SDL_RWread.

758 {
759  Uint8 value = 0;
760 
761  SDL_RWread(src, &value, sizeof (value), 1);
762  return value;
763 }
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
uint8_t Uint8
Definition: SDL_stdinc.h:157
GLsizei const GLfloat * value

◆ SDL_RWFromConstMem()

SDL_RWops* SDL_RWFromConstMem ( const void mem,
int  size 
)

Definition at line 654 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.

655 {
656  SDL_RWops *rwops = NULL;
657  if (!mem) {
658  SDL_InvalidParamError("mem");
659  return rwops;
660  }
661  if (!size) {
662  SDL_InvalidParamError("size");
663  return rwops;
664  }
665 
666  rwops = SDL_AllocRW();
667  if (rwops != NULL) {
668  rwops->size = mem_size;
669  rwops->seek = mem_seek;
670  rwops->read = mem_read;
671  rwops->write = mem_writeconst;
672  rwops->close = mem_close;
673  rwops->hidden.mem.base = (Uint8 *) mem;
674  rwops->hidden.mem.here = rwops->hidden.mem.base;
675  rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
676  rwops->type = SDL_RWOPS_MEMORY_RO;
677  }
678  return rwops;
679 }
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
static size_t mem_writeconst(SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.c:492
static Sint64 mem_size(SDL_RWops *context)
Definition: SDL_rwops.c:424
Uint32 type
Definition: SDL_rwops.h:93
struct SDL_RWops::@10::@13 mem
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:682
static int mem_close(SDL_RWops *context)
Definition: SDL_rwops.c:499
uint8_t Uint8
Definition: SDL_stdinc.h:157
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
static Sint64 mem_seek(SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.c:430
GLsizeiptr size
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
#define NULL
Definition: begin_code.h:164
union SDL_RWops::@10 hidden
#define SDL_RWOPS_MEMORY_RO
Definition: SDL_rwops.h:47
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
static size_t mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.c:458

◆ SDL_RWFromFile()

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

Definition at line 511 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.

512 {
513  SDL_RWops *rwops = NULL;
514  if (!file || !*file || !mode || !*mode) {
515  SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
516  return NULL;
517  }
518 #if defined(__ANDROID__)
519 #ifdef HAVE_STDIO_H
520  /* Try to open the file on the filesystem first */
521  if (*file == '/') {
522  FILE *fp = fopen(file, mode);
523  if (fp) {
524  return SDL_RWFromFP(fp, 1);
525  }
526  } else {
527  /* Try opening it from internal storage if it's a relative path */
528  char *path;
529  FILE *fp;
530 
531  path = SDL_stack_alloc(char, PATH_MAX);
532  if (path) {
533  SDL_snprintf(path, PATH_MAX, "%s/%s",
535  fp = fopen(path, mode);
536  SDL_stack_free(path);
537  if (fp) {
538  return SDL_RWFromFP(fp, 1);
539  }
540  }
541  }
542 #endif /* HAVE_STDIO_H */
543 
544  /* Try to open the file from the asset system */
545  rwops = SDL_AllocRW();
546  if (!rwops)
547  return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
548  if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
549  SDL_FreeRW(rwops);
550  return NULL;
551  }
552  rwops->size = Android_JNI_FileSize;
553  rwops->seek = Android_JNI_FileSeek;
554  rwops->read = Android_JNI_FileRead;
555  rwops->write = Android_JNI_FileWrite;
556  rwops->close = Android_JNI_FileClose;
557  rwops->type = SDL_RWOPS_JNIFILE;
558 
559 #elif defined(__WIN32__)
560  rwops = SDL_AllocRW();
561  if (!rwops)
562  return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
563  if (windows_file_open(rwops, file, mode) < 0) {
564  SDL_FreeRW(rwops);
565  return NULL;
566  }
567  rwops->size = windows_file_size;
568  rwops->seek = windows_file_seek;
569  rwops->read = windows_file_read;
570  rwops->write = windows_file_write;
571  rwops->close = windows_file_close;
572  rwops->type = SDL_RWOPS_WINFILE;
573 
574 #elif HAVE_STDIO_H
575  {
576  #ifdef __APPLE__
577  FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode);
578  #elif __WINRT__
579  FILE *fp = NULL;
580  fopen_s(&fp, file, mode);
581  #else
582  FILE *fp = fopen(file, mode);
583  #endif
584  if (fp == NULL) {
585  SDL_SetError("Couldn't open %s", file);
586  } else {
587  rwops = SDL_RWFromFP(fp, 1);
588  }
589  }
590 #else
591  SDL_SetError("SDL not compiled with stdio support");
592 #endif /* !HAVE_STDIO_H */
593 
594  return rwops;
595 }
int Android_JNI_FileClose(SDL_RWops *ctx)
void SDL_FreeRW(SDL_RWops *area)
Definition: SDL_rwops.c:696
#define SDL_RWOPS_WINFILE
Definition: SDL_rwops.h:43
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
int Android_JNI_FileOpen(SDL_RWops *ctx, const char *fileName, const char *mode)
Uint32 type
Definition: SDL_rwops.h:93
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:682
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:354
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
SDL_RWops * SDL_RWFromFP(void *fp, SDL_bool autoclose)
Definition: SDL_rwops.c:618
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size, size_t num)
GLenum mode
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size, size_t maxnum)
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
#define SDL_snprintf
GLsizei const GLchar *const * path
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:355
#define SDL_AndroidGetInternalStoragePath
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
#define SDL_RWOPS_JNIFILE
Definition: SDL_rwops.h:45

◆ SDL_RWFromFP()

SDL_RWops* SDL_RWFromFP ( FILE *  fp,
SDL_bool  autoclose 
)

◆ SDL_RWFromMem()

SDL_RWops* SDL_RWFromMem ( void mem,
int  size 
)

Definition at line 626 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.

627 {
628  SDL_RWops *rwops = NULL;
629  if (!mem) {
630  SDL_InvalidParamError("mem");
631  return rwops;
632  }
633  if (!size) {
634  SDL_InvalidParamError("size");
635  return rwops;
636  }
637 
638  rwops = SDL_AllocRW();
639  if (rwops != NULL) {
640  rwops->size = mem_size;
641  rwops->seek = mem_seek;
642  rwops->read = mem_read;
643  rwops->write = mem_write;
644  rwops->close = mem_close;
645  rwops->hidden.mem.base = (Uint8 *) mem;
646  rwops->hidden.mem.here = rwops->hidden.mem.base;
647  rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
648  rwops->type = SDL_RWOPS_MEMORY;
649  }
650  return rwops;
651 }
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.h:83
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
static Sint64 mem_size(SDL_RWops *context)
Definition: SDL_rwops.c:424
Uint32 type
Definition: SDL_rwops.h:93
struct SDL_RWops::@10::@13 mem
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
static size_t mem_write(SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition: SDL_rwops.c:481
SDL_RWops * SDL_AllocRW(void)
Definition: SDL_rwops.c:682
static int mem_close(SDL_RWops *context)
Definition: SDL_rwops.c:499
uint8_t Uint8
Definition: SDL_stdinc.h:157
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:91
static Sint64 mem_seek(SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.c:430
GLsizeiptr size
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
#define NULL
Definition: begin_code.h:164
#define SDL_RWOPS_MEMORY
Definition: SDL_rwops.h:46
union SDL_RWops::@10 hidden
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.h:74
static size_t mem_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition: SDL_rwops.c:458

◆ SDL_WriteBE16()

size_t SDL_WriteBE16 ( SDL_RWops dst,
Uint16  value 
)

Definition at line 833 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE16.

834 {
835  const Uint16 swapped = SDL_SwapBE16(value);
836  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
837 }
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
#define SDL_SwapBE16(X)
Definition: SDL_endian.h:236
GLsizei const GLfloat * value
uint16_t Uint16
Definition: SDL_stdinc.h:169

◆ SDL_WriteBE32()

size_t SDL_WriteBE32 ( SDL_RWops dst,
Uint32  value 
)

Definition at line 847 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE32.

848 {
849  const Uint32 swapped = SDL_SwapBE32(value);
850  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
851 }
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:237
GLsizei const GLfloat * value

◆ SDL_WriteBE64()

size_t SDL_WriteBE64 ( SDL_RWops dst,
Uint64  value 
)

Definition at line 861 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapBE64.

862 {
863  const Uint64 swapped = SDL_SwapBE64(value);
864  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
865 }
#define SDL_SwapBE64(X)
Definition: SDL_endian.h:238
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
uint64_t Uint64
Definition: SDL_stdinc.h:194
GLsizei const GLfloat * value

◆ SDL_WriteLE16()

size_t SDL_WriteLE16 ( SDL_RWops dst,
Uint16  value 
)

Definition at line 826 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE16.

827 {
828  const Uint16 swapped = SDL_SwapLE16(value);
829  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
830 }
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
GLsizei const GLfloat * value
uint16_t Uint16
Definition: SDL_stdinc.h:169
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:232

◆ SDL_WriteLE32()

size_t SDL_WriteLE32 ( SDL_RWops dst,
Uint32  value 
)

Definition at line 840 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE32.

841 {
842  const Uint32 swapped = SDL_SwapLE32(value);
843  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
844 }
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:233
GLsizei const GLfloat * value

◆ SDL_WriteLE64()

size_t SDL_WriteLE64 ( SDL_RWops dst,
Uint64  value 
)

Definition at line 854 of file SDL_rwops.c.

References SDL_RWwrite, and SDL_SwapLE64.

855 {
856  const Uint64 swapped = SDL_SwapLE64(value);
857  return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
858 }
#define SDL_RWwrite(ctx, ptr, size, n)
Definition: SDL_rwops.h:188
uint64_t Uint64
Definition: SDL_stdinc.h:194
#define SDL_SwapLE64(X)
Definition: SDL_endian.h:234
GLsizei const GLfloat * value

◆ SDL_WriteU8()

size_t SDL_WriteU8 ( SDL_RWops dst,
Uint8  value 
)

Definition at line 820 of file SDL_rwops.c.

References SDL_RWwrite.

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