SDL_GetBasePath(3)
๐ SDL_GetBasePath ๐
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, this one's all about SDL_GetBasePath and it's genuinely so useful ๐ซถ
โจ NAME โจ
SDL_GetBasePath โ get the directory where the application was run from. that's it, that's the vibe ๐ธ
๐ SYNOPSIS ๐
#include <SDL3/SDL_filesystem.h>
const char * SDL_GetBasePath(void);
no args, no drama, just a path coming back at you ๐
๐ DESCRIPTION ๐
so like, SDL caches the result of this call internally, which sounds slay, BUT โ the first call to this function is not necessarily fast, so plan accordingly. don't be out here calling it in your hot render loop on frame one and then acting surprised ๐ญ
๐ macOS and iOS Specific Functionality ๐
if the application is inside a ".app" bundle, this function returns the Resource directory (e.g. MyApp.app/Contents/Resources/). iconic.
but you can override that behaviour by adding a property to the Info.plist file. add a string key named SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value and the behaviour changes. main character energy, honestly ๐
supported values for the SDL_FILESYSTEM_BASE_DIR_TYPE property (given an application in /Applications/SDLApp/MyApp.app):
resourceโ the bundle resource directory, and yes that's the default. for example:/Applications/SDLApp/MyApp.app/Contents/Resourcesbundleโ the Bundle directory. for example:/Applications/SDLApp/MyApp.app/parentโ the containing directory of the bundle. for example:/Applications/SDLApp/
๐ค Android Specific Functionality ๐ค
this function returns "./", which lets filesystem operations use internal storage and the asset system. cute, right? โจ
๐ฎ Nintendo 3DS Specific Functionality ๐ฎ
this function returns the "romfs" directory of the application, because it's uncommon to store resources outside the executable. as such, it is not a writable directory. so don't try to write there, bestie, it's giving "read only, no notes" ๐
๐ฆ one more thing ๐ฆ
the returned path is guaranteed to end with a path separator โ that's '\\' on Windows, and '/' on most other platforms. so you never have to guess whether to add one. we love a predictable API ๐
โญ RETURN VALUE โญ
returns an absolute path in UTF-8 encoding to the application data directory.
NULL will be returned on error, or when the platform doesn't implement this functionality. if that happens, call SDL_GetError() for more information โ it's the little friend that tells you what went wrong ๐
๐งต THREAD SAFETY ๐งต
it is safe to call this function from any thread. no cap. go wild, all your threads can have it ๐ฅ
๐ AVAILABILITY ๐
this function is available since SDL 3.2.0. so if you're on something older... yeah, it's not there yet, sorry babe ๐ญ
๐ SEE ALSO ๐
and that's the whole page, fr fr ๐ thanks for reading all the way to the end, you're literally the best. this lil masterpiece comes to you from Simple Directmedia Layer, SDL 3.4.18 โ go forth and get that base path, bestie ๐๐ฆโจ
๐ฆ 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