Files & storageSDL 3.2

SDL_OpenUserStorage

Opens the player's writable storage (save games, settings) through SDL's storage API.

Signature

SDL_Storage * SDL_OpenUserStorage(const char *org, const char *app, SDL_PropertiesID props);

How it works

The writable twin of SDL_OpenTitleStorage. On PC it maps to the same folder as SDL_GetPrefPath. Open it only when you are about to read or write, and close it soon after: on some platforms closing is what actually commits the save safely.

Parameters

orgconst char *

Your organization name (as in SDL_GetPrefPath).

appconst char *

Your application name.

propsSDL_PropertiesID

Backend-specific options, usually 0.

Return value

The storage container, or NULL on failure.

Example

example.cpp
1SDL_Storage* user = SDL_OpenUserStorage("MyStudio", "MyGame", 0);
2while (!SDL_StorageReady(user)) SDL_Delay(1);
3SDL_WriteStorageFile(user, "save1.dat", save.data(), save.size());
4SDL_CloseStorage(user);   // commit
Official SDL wiki