SDL_IOStreamInterface(3type)
π SDL_IOStreamInterface π (from the SDL3 DATATYPES manual, bestie)
β¨ NAME β¨
SDL_IOStreamInterface β the lil bundle of function pointers that literally drive an SDL_IOStream. it's giving "custom engine, your rules" ποΈ
πΈ SYNOPSIS πΈ
okay so first you gotta pull in the header:
#include <SDL3/SDL_iostream.h>
and then, boom, here's the whole struct in all its glory β every field, every callback, untouched, no cap:
typedef struct SDL_IOStreamInterface
{
/* The version of this interface */
Uint32 version;
/**
* Return the number of bytes in this SDL_IOStream
*
* \return the total size of the data stream, or -1 on error.
*/
Sint64 (SDLCALL *size)(void *userdata);
/**
* Seek to `offset` relative to `whence`, one of stdio's whence values:
* SDL_IO_SEEK_SET, SDL_IO_SEEK_CUR, SDL_IO_SEEK_END
*
* \return the final offset in the data stream, or -1 on error.
*/
Sint64 (SDLCALL *seek)(void *userdata, Sint64 offset, SDL_IOWhence whence);
/**
* Read up to `size` bytes from the data stream to the area pointed
* at by `ptr`. `size` will always be > 0.
*
* On an incomplete read, you should set `*status` to a value from the
* SDL_IOStatus enum. You do not have to explicitly set this on
* a complete, successful read.
*
* \return the number of bytes read
*/
size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *status);
/**
* Write exactly `size` bytes from the area pointed at by `ptr`
* to data stream. `size` will always be > 0.
*
* On an incomplete write, you should set `*status` to a value from the
* SDL_IOStatus enum. You do not have to explicitly set this on
* a complete, successful write.
*
* \return the number of bytes written
*/
size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status);
/**
* If the stream is buffering, make sure the data is written out.
*
* On failure, you should set `*status` to a value from the
* SDL_IOStatus enum. You do not have to explicitly set this on
* a successful flush.
*
* \return true if successful or false on write error when flushing data.
*/
bool (SDLCALL *flush)(void *userdata, SDL_IOStatus *status);
/**
* Close and free any allocated resources.
*
* This does not guarantee file writes will sync to physical media; they
* can be in the system's file cache, waiting to go to disk.
*
* The SDL_IOStream is still destroyed even if this fails, so clean up anything
* even if flushing buffers, etc, returns an error.
*
* \return true if successful or false on write error when flushing data.
*/
bool (SDLCALL *close)(void *userdata);
} SDL_IOStreamInterface;
π the members, one by one π
Uint32 versionβ the version of this interface, bestie. it's the little handshake that says "hey, we're on the same page". π«ΆSint64 (SDLCALL *size)(void *userdata)β hand back the number of bytes in thisSDL_IOStream. you return the total size of the data stream, or-1on error. πSint64 (SDLCALL *seek)(void *userdata, Sint64 offset, SDL_IOWhence whence)β jump tooffsetrelative towhence, which is one of stdio's whence values:SDL_IO_SEEK_SET,SDL_IO_SEEK_CUR,SDL_IO_SEEK_END. you return the final offset in the data stream, or-1on error. periodt. πsize_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *status)β read up tosizebytes from the data stream into the areaptrpoints at.sizewill always be> 0, no zero-byte shenanigans here. on an incomplete read you should set*statusto a value from theSDL_IOStatusenum β but on a complete, successful read you do not have to set it explicitly, so chill. you return the number of bytes read. πsize_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status)β write exactlysizebytes from the areaptrpoints at to the data stream. again,sizewill always be> 0. on an incomplete write you should set*statusto a value from theSDL_IOStatusenum; on a complete, successful write you don't have to set it explicitly. you return the number of bytes written. βοΈbool (SDLCALL *flush)(void *userdata, SDL_IOStatus *status)β if the stream is buffering, make sure the data actually gets written out. on failure you should set*statusto a value from theSDL_IOStatusenum; on a successful flush you don't have to set it. you returntrueif successful, orfalseon write error when flushing data. π°bool (SDLCALL *close)(void *userdata)β close and free any allocated resources, the final curtain call. β οΈ heads up tho: this does not guarantee file writes will sync to physical media β they can be sitting in the system's file cache, waiting to go to disk. and listen: theSDL_IOStreamis still destroyed even if this fails, so clean up everything even if flushing buffers, etc, returns an error. you returntrueif successful, orfalseon write error when flushing data. π
π DESCRIPTION π
so here's the tea: applications can hand this struct to SDL_OpenIO() to create their own implementation of SDL_IOStream. it's the DIY build-your-own-stream kit. π οΈ
but lowkey? it's not necessarily required, because SDL already offers several common types of I/O streams via functions like SDL_IOFromFile() and SDL_IOFromMem(). so if the stock ones hit, you don't gotta do a thing. π
β οΈ important: this structure should be initialized using SDL_INIT_INTERFACE(). do not skip this step, bestie, that's the whole vibe check. π
π¦ AVAILABILITY π¦
this struct is available since SDL 3.2.0. iconic behavior honestly. β¨
π SEE ALSO π
and that's the whole page, bestie β brought to you by Simple Directmedia Layer, running SDL 3.4.18, and yes this is the SDL_IOStreamInterface(3type) page, slay, mwah π
πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms