SDL_WriteIO(3)

πŸ’– SDL_WriteIO πŸ’–

okay bestie, welcome to SDL_WriteIO(3) β€” the SDL3 FUNCTIONS girlie whose whole job is ✨writing to an SDL_IOStream data stream✨. no cap, that's literally it.


🌸 NAME 🌸

SDL_WriteIO β€” write to an SDL_IOStream data stream, fr fr πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_iostream.h>

size_t SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: this function writes exactly size bytes from the area that ptr is pointing at, straight into the stream. that's the dream, that's the goal, that's the main character moment 🫢

but if it fails for literally any reason?? it'll return less than size to show you how far the write actually got. so you can see exactly where it gave up. on success, it returns size. slay. βœ…

and here's the important part, no cap: on error, this function still attempts to write as much as possible, so it might hand you back a positive value that's less than the write size you asked for. it's doing its best, okay 😭

the caller can use SDL_GetIOStatus() to figure out if the problem is recoverable β€” like a non-blocking write that you can simply retry later β€” or a fatal error. so like, is it giving "just try again bestie" or is it giving "we're cooked" πŸ’€

also!! a request for zero bytes on a valid stream will return zero immediately without even touching the stream, so the stream status (EOF, err, etc.) will not change. zero bytes = zero drama, periodt ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • context β€” a pointer to an SDL_IOStream structure. this is the stream we're writing into, our canvas, our moment πŸ’–
  • ptr β€” a pointer to a buffer containing the data to write. the goods. the content. πŸ“
  • size β€” the number of bytes to write. how much we're serving today πŸ‘‘

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns the number of bytes written πŸ’« β€” which will be less than size on failure. and if that happens, call SDL_GetError() for more info, because she will tell you what went wrong πŸ—£οΈ


🧚 THREAD SAFETY 🧚

⚠️ do NOT use the same SDL_IOStream from two threads at once. that's it, that's the rule, one stream one thread, we do not share, we do not pass go πŸ™ˆ

🌈 AVAILABILITY 🌈

this function is available since SDL 3.2.0 β€” so if you're on anything older, sorry babe, she's not there yet 😭


⭐ SEE ALSO ⭐

go read those too, they're all part of the same friend group 🫢


and that's the whole page, bestie!! this lil writeup came to you from Simple Directmedia Layer, rocking version SDL 3.4.18 πŸ’–βœ¨ mwah, go write some bytes, you're gonna ate πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from