Initialize interface structures so they can be extended in the future

We guarantee that we will only add to the end of these interfaces, and any new fields will be optional.
This commit is contained in:
Sam Lantinga
2024-09-05 16:28:48 -07:00
parent 434193d153
commit 702ed83f72
13 changed files with 130 additions and 22 deletions

View File

@@ -153,6 +153,11 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata)
SDL_InvalidParamError("iface");
return NULL;
}
if (iface->version < sizeof(*iface)) {
// Update this to handle older versions of this interface
SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
return NULL;
}
storage = (SDL_Storage *)SDL_calloc(1, sizeof(*storage));
if (storage) {

View File

@@ -182,6 +182,7 @@ static Uint64 GENERIC_GetStorageSpaceRemaining(void *userdata)
}
static const SDL_StorageInterface GENERIC_title_iface = {
sizeof(SDL_StorageInterface),
GENERIC_CloseStorage,
NULL, // ready
GENERIC_EnumerateStorageDirectory,
@@ -224,6 +225,7 @@ TitleStorageBootStrap GENERIC_titlebootstrap = {
};
static const SDL_StorageInterface GENERIC_user_iface = {
sizeof(SDL_StorageInterface),
GENERIC_CloseStorage,
NULL, // ready
GENERIC_EnumerateStorageDirectory,
@@ -259,6 +261,7 @@ UserStorageBootStrap GENERIC_userbootstrap = {
};
static const SDL_StorageInterface GENERIC_file_iface = {
sizeof(SDL_StorageInterface),
GENERIC_CloseStorage,
NULL, // ready
GENERIC_EnumerateStorageDirectory,

View File

@@ -129,6 +129,7 @@ static Uint64 STEAM_GetStorageSpaceRemaining(void *userdata)
}
static const SDL_StorageInterface STEAM_user_iface = {
sizeof(SDL_StorageInterface),
STEAM_CloseStorage,
STEAM_StorageReady,
NULL, // enumerate