All storage interface functions are optional

If an application is creating custom storage, presumably they'll implement the functions they need.
main
Sam Lantinga 2024-03-16 18:33:36 -07:00
parent f460f42e70
commit 2f78e5f321
1 changed files with 8 additions and 9 deletions

View File

@ -151,24 +151,23 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata)
return NULL; return NULL;
} }
storage = (SDL_Storage*) SDL_malloc(sizeof(SDL_Storage)); storage = (SDL_Storage *)SDL_calloc(1, sizeof(*storage));
if (!storage) { if (storage) {
SDL_OutOfMemory(); SDL_copyp(&storage->iface, iface);
return NULL;
}
SDL_memcpy(&storage->iface, iface, sizeof(SDL_StorageInterface));
storage->userdata = userdata; storage->userdata = userdata;
}
return storage; return storage;
} }
int SDL_CloseStorage(SDL_Storage *storage) int SDL_CloseStorage(SDL_Storage *storage)
{ {
int retval; int retval = 0;
CHECK_STORAGE_MAGIC() CHECK_STORAGE_MAGIC()
if (storage->iface.close) {
retval = storage->iface.close(storage->userdata); retval = storage->iface.close(storage->userdata);
}
SDL_free(storage); SDL_free(storage);
return retval; return retval;
} }