Wiki Page Content


Use this function to get the "pref dir". This is meant to be where the application can write personal files (Preferences and save games, etc.) that are specific to the application. This directory is unique per user and per application.


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

Function Parameters


the name of your organization


the name of your application

Return Value

Returns a UTF-8 string of the user directory in platform-dependent notation. NULL if there's a problem (creating directory failed, etc.).

The return path will be guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).

The pointer returned is owned by you. Please call SDL_free() on the pointer when you are done with it.

Code Examples

char *pref_path = NULL;

void InitializePrefPath() {
    char *base_path = SDL_GetPrefPath("My Company", "My Awesome SDL 2 Game");
    if (base_path) {
        pref_path = base_path;
    } else {
        /* Do something to disable writing in-game */


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, aren't where you should be writing things).

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

  • Try to use the same org string (including case-sensitivity) for all your applications that use this function.
  • Always use a unique app string for each one, and make sure it never changes for an app once you've decided on it.
  • Unicode characters are legal, as long as it's 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.


This function is available since SDL 2.0.1.

CategoryAPI, CategoryFilesystem

None: SDL_GetPrefPath (last edited 2015-05-08 19:33:13 by PhilippWiesemann)

Please include your contact information if you'd like to receive a reply.