This is the read/write operation structure -- very basic.
Defined in [SDL_rwops.h](https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_rwops.h), but apps should _only_ `#include "SDL.h"`!
typedef struct SDL_RWops
{/**
* Return the size of the file in this rwops, or -1 if unknown
*/
struct SDL_RWops * context);
Sint64 (SDLCALL * size) (
/**
* Seek to \c offset relative to \c whence, one of stdio's whence values:
* RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
*
* \return the final offset in the data stream, or -1 on error.
*/
struct SDL_RWops * context, Sint64 offset,
Sint64 (SDLCALL * seek) (int whence);
/**
* Read up to \c maxnum objects each of size \c size from the data
* stream to the area pointed at by \c ptr.
*
* \return the number of objects read, or 0 at error or end of file.
*/
size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
size_t size, size_t maxnum);
/**
* Write exactly \c num objects each of size \c size from the area
* pointed at by \c ptr to data stream.
*
* \return the number of objects written, or 0 at error or end of file.
*/
size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
size_t size, size_t num);
/**
* Close and free an allocated SDL_RWops structure.
*
* \return 0 if successful or -1 on write error when flushing data.
*/
int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type;union
{#if defined(__ANDROID__)
struct
{void *asset;
} androidio;#elif defined(__WIN32__) || defined(__GDK__)
struct
{
SDL_bool append;void *h;
struct
{void *data;
size_t size;
size_t left;
} buffer;
} windowsio;#endif
#ifdef HAVE_STDIO_H
struct
{
SDL_bool autoclose;FILE *fp;
} stdio;#endif
struct
{
Uint8 *base;
Uint8 *here;
Uint8 *stop;
} mem;struct
{void *data1;
void *data2;
} unknown;
} hidden;
} SDL_RWops;
"username.txt", "rb");
SDL_RWops *io = SDL_RWFromFile(if (io != NULL) {
char name[256];
if (io->read(io, name, sizeof (name), 1) > 0) {
"Hello, %s!\n", name);
printf(
}
io->close(io); }
The following is functionally identical to the above example, but uses the recommended macro interface.
"username.txt", "rb");
SDL_RWops *io = SDL_RWFromFile(if (io != NULL) {
char name[256];
if (SDL_RWread(io, name, sizeof (name), 1) > 0) {
"Hello, %s!\n", name);
printf(
}
SDL_RWclose(io); }
Sint64 (*)(SDL_RWops *) |
size |
callback that reports stream size; see Remarks |
Sint64 (*)(SDL_RWops *, Sint64, int) |
seek |
callback that seeks in stream; see Remarks |
size_t (*)(SDL_RWops *, void *, size_t, size_t) |
read |
callback that reads from the stream; see Remarks |
size_t (*)(SDL_RWops *, const void *, size_t, size_t) |
write |
callback that writes to the stream; see Remarks |
int (*)(SDL_RWops *) |
close |
callback that closes the stream; see Remarks |
Uint32 |
type |
type of stream; see Remarks |
union |
hidden |
type-specific data; see Remarks |
CategoryAPI, CategoryAPIStruct, CategoryStruct, CategoryIO