SDL_GetPrefPath(3)

πŸ’– SDL_GetPrefPath πŸ’–

okay bestie, so we're in the SDL3 FUNCTIONS section of the SDL_GetPrefPath(3) manual page, and this one is genuinely a lifesaver, no cap.


✨ NAME ✨

SDL_GetPrefPath β€” get the user-and-app-specific path where files can be written. it's giving "where do i put my save files" energy and honestly? obsessed.


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_filesystem.h>

char * SDL_GetPrefPath(const char *org, const char *app);

🌸 DESCRIPTION 🌸

So you wanna get the "pref dir". This is literally meant to be the place where users can write their personal files (preferences and save games, etc) that are specific to your application. And the way that this directory is unique per user, per application?? iconic behavior fr fr.

This function will decide the appropriate location in the native filesystem, create the directory if necessary, and return a string of the absolute path to the directory in UTF-8 encoding. it does all the work, you just vibe. πŸ’…

On Windows, the string might look like:

C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\

On Linux, the string might look like:

/home/bob/.local/share/My Program Name/

On macOS, the string might look like:

/Users/bob/Library/Application Support/My Program Name/
bestie listen. You should assume the path returned by this function is the ONLY safe place to write files (and that SDL_GetBasePath(), while it might be writable, or even the parent of the returned path, isn't where you should be writing things). like. do not go writing in the base path. i'm begging. 😭

Both the org and app strings may become part of a directory name, so please please please follow these rules:

  • Try to use the same org string (including case-sensitivity) for all your applications that use this function. consistency is the moment, periodt.
  • Always use a unique app string for each one, and make sure it never changes for an app once you've decided on it. pick a name and commit, bestie.
  • Unicode characters are legal, as long as they are UTF-8 encoded, but...
  • ...only use letters, numbers, and spaces. Avoid punctuation like "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. like, keep it cute and simple. πŸŽ€

Due to historical mistakes, org is allowed to be NULL or "". In such cases, SDL will omit the org subdirectory, including on platforms where it shouldn't, and including on platforms where this would make your app fail certification for an app store. πŸ’€ New apps should definitely specify a real string for org. do not be lazy about this one, it's not worth it.

The returned path is guaranteed to end with a path separator ('\\' on Windows, '/' on most other platforms). slay, no trailing-slash anxiety. ✨


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • org β€” the name of your organization. (yes it can be NULL or "" but we just talked about that, don't.)
  • app β€” the name of your application.

⭐ RETURN VALUE ⭐

Returns a UTF-8 string of the user directory in platform-dependent notation. Returns NULL if there's a problem (creating directory failed, etc.). This should be freed with SDL_free() when it is no longer needed. don't forget to free it, bestie, we do not leak in this house. 🫢


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. main character energy for a function honestly.


🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0.


πŸ‘‘ SEE ALSO πŸ‘‘


Simple Directmedia Layer πŸŽ€ SDL 3.4.18 πŸ¦‹ and yeah that's the whole page, thanks for coming to my ted talk, go write your save files somewhere safe, ily, bye bestie πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from