SDL  2.0
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_RWopsSDL_RWFromFile (const char *file, const char *mode)
 
SDL_RWopsSDL_RWFromFP (void *fp, SDL_bool autoclose)
 
SDL_RWopsSDL_RWFromMem (void *mem, int size)
 
SDL_RWopsSDL_RWFromConstMem (const void *mem, int size)
 
SDL_RWopsSDL_AllocRW (void)
 
void SDL_FreeRW (SDL_RWops *area)
 
voidSDL_LoadFile_RW (SDL_RWops *src, size_t *datasize, int freesrc)
 
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

◆ _LARGEFILE64_SOURCE

#define _LARGEFILE64_SOURCE

Definition at line 26 of file SDL_rwops.c.

Function Documentation

◆ mem_close()

static int mem_close ( SDL_RWops context)
static

Definition at line 499 of file SDL_rwops.c.

References SDL_FreeRW().

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

500 {
501  if (context) {
502  SDL_FreeRW(context);
503  }
504  return 0;
505 }
void SDL_FreeRW(SDL_RWops *area)
Definition: SDL_rwops.c:696

◆ mem_read()

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

Definition at line 458 of file SDL_rwops.c.

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

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

459 {
460  size_t total_bytes;
461  size_t mem_available;
462 
463  total_bytes = (maxnum * size);
464  if ((maxnum <= 0) || (size <= 0)
465  || ((total_bytes / maxnum) != (size_t) size)) {
466  return 0;
467  }
468 
469  mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
470  if (total_bytes > mem_available) {
471  total_bytes = mem_available;
472  }
473 
474  SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
475  context->hidden.mem.here += total_bytes;
476 
477  return (total_bytes / size);
478 }
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
unsigned int size_t
struct SDL_RWops::@10::@13 mem
#define SDL_memcpy
GLsizeiptr size
union SDL_RWops::@10 hidden

◆ mem_seek()

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

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

431 {
432  Uint8 *newpos;
433 
434  switch (whence) {
435  case RW_SEEK_SET:
436  newpos = context->hidden.mem.base + offset;
437  break;
438  case RW_SEEK_CUR:
439  newpos = context->hidden.mem.here + offset;
440  break;
441  case RW_SEEK_END:
442  newpos = context->hidden.mem.stop + offset;
443  break;
444  default:
445  return SDL_SetError("Unknown value for 'whence'");
446  }
447  if (newpos < context->hidden.mem.base) {
448  newpos = context->hidden.mem.base;
449  }
450  if (newpos > context->hidden.mem.stop) {
451  newpos = context->hidden.mem.stop;
452  }
453  context->hidden.mem.here = newpos;
454  return (Sint64)(context->hidden.mem.here - context->hidden.mem.base);
455 }
GLintptr offset
#define RW_SEEK_END
Definition: SDL_rwops.h:176
struct SDL_RWops::@10::@13 mem
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define SDL_SetError
union SDL_RWops::@10 hidden
#define RW_SEEK_SET
Definition: SDL_rwops.h:174
#define RW_SEEK_CUR
Definition: SDL_rwops.h:175
int64_t Sint64
Definition: SDL_stdinc.h:210

◆ mem_size()

static Sint64 mem_size ( SDL_RWops context)
static

Definition at line 424 of file SDL_rwops.c.

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

Referenced by SDL_RWFromConstMem(), and SDL_RWFromMem().

425 {
426  return (Sint64)(context->hidden.mem.stop - context->hidden.mem.base);
427 }
struct SDL_RWops::@10::@13 mem
union SDL_RWops::@10 hidden
int64_t Sint64
Definition: SDL_stdinc.h:210

◆ mem_write()

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

Definition at line 481 of file SDL_rwops.c.

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

Referenced by SDL_RWFromMem().

482 {
483  if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) {
484  num = (context->hidden.mem.stop - context->hidden.mem.here) / size;
485  }
486  SDL_memcpy(context->hidden.mem.here, ptr, num * size);
487  context->hidden.mem.here += num * size;
488  return num;
489 }
GLuint num
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
struct SDL_RWops::@10::@13 mem
#define SDL_memcpy
GLsizeiptr size
union SDL_RWops::@10 hidden

◆ mem_writeconst()

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

Definition at line 492 of file SDL_rwops.c.

References SDL_SetError, and SDLCALL.

Referenced by SDL_RWFromConstMem().

493 {
494  SDL_SetError("Can't write to read-only memory");
495  return 0;
496 }
#define SDL_SetError

◆ 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:210

◆ 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 }
uint16_t Uint16
Definition: SDL_stdinc.h:191
#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

◆ 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
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:237
GLsizei const GLfloat * value
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ 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:216
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 }
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
GLsizei const GLfloat * value
#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
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:233
GLsizei const GLfloat * value
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ 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:216
#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:179
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:179
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 ( void fp,
SDL_bool  autoclose 
)

Definition at line 618 of file SDL_rwops.c.

References NULL, and SDL_SetError.

Referenced by SDL_RWFromFile().

619 {
620  SDL_SetError("SDL not compiled with stdio support");
621  return NULL;
622 }
#define NULL
Definition: begin_code.h:164
#define SDL_SetError

◆ 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:179
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
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_SwapBE16(X)
Definition: SDL_endian.h:236
GLsizei const GLfloat * value

◆ 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
#define SDL_SwapBE32(X)
Definition: SDL_endian.h:237
GLsizei const GLfloat * value
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ 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:216
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
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLsizei const GLfloat * value
#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
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:233
GLsizei const GLfloat * value
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ 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:216
#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