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/Resources
  • bundle โ€” 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