SDL_LoadFile(3)
π SDL_LoadFile(3) β the SDL3 FUNCTIONS girlies' guide to slurping a whole file π
okay so bestie, picture this: you got a file path, you want everything in it, and you do not want to do the whole open/read/close dance yourself. that's literally what SDL_LoadFile is for. it's giving "just hand me the path and I'll handle it." β¨
πΈ NAME πΈ
SDL_LoadFile β load all the data from a file path. yes. all of it. the whole thing. no crumbs left behind. π
π SYNOPSIS π
#include <SDL3/SDL_iostream.h>
void * SDL_LoadFile(const char *file, size_t *datasize);
π¦ DESCRIPTION π¦
so the data you get back is allocated with a zero byte at the end (null terminated, periodt π
) just for convenience, because we're nice like that. but β and this is the part where you have to pay attention, no cap β that extra byte is not included in the value that gets reported via datasize. so datasize is the real byte count, and there's one sneaky bonus \0 chilling after it. don't @ me, that's just how it is.
and when you're done with all this beautiful data? you gotta free it with SDL_free(). she's not gonna clean up after herself, bestie. π§
π FUNCTION PARAMETERS π
fileβ the path to read all available data from. all of it. every last byte. πdatasizeβ if it's notNULL, this will store the number of bytes read. if you passNULL... okay go off, live your truth, but you won't know how big your data is. π
β RETURN VALUE β
returns the data, or NULL on failure β and if you get NULL, go call SDL_GetError() for more information, because she will tell you what went wrong. π
π THREAD SAFETY π
it is safe to call this function from any thread. any. thread. main character energy in every single one of them. π₯
β¨ AVAILABILITY β¨
this function has been available since SDL 3.2.0. iconic behavior, honestly.
π SEE ALSO π
and that's the whole page, bestie β brought to you by the fine folks at Simple Directmedia Layer, running the SDL 3.4.18 era, and yeah, it's SDL_LoadFile(3) if you need to cite her. 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