SDL: All storage interface functions are optional

From 2f78e5f321b5aca80344b2a75fee0e9d7ae9b2b9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 16 Mar 2024 18:33:36 -0700
Subject: [PATCH] All storage interface functions are optional

If an application is creating custom storage, presumably they'll implement the functions they need.
---
 src/storage/SDL_storage.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/storage/SDL_storage.c b/src/storage/SDL_storage.c
index 1111d2a7813ba..30bdd2f5b5f28 100644
--- a/src/storage/SDL_storage.c
+++ b/src/storage/SDL_storage.c
@@ -151,24 +151,23 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata)
         return NULL;
     }
 
-    storage = (SDL_Storage*) SDL_malloc(sizeof(SDL_Storage));
-    if (!storage) {
-        SDL_OutOfMemory();
-        return NULL;
+    storage = (SDL_Storage *)SDL_calloc(1, sizeof(*storage));
+    if (storage) {
+        SDL_copyp(&storage->iface, iface);
+        storage->userdata = userdata;
     }
-
-    SDL_memcpy(&storage->iface, iface, sizeof(SDL_StorageInterface));
-    storage->userdata = userdata;
     return storage;
 }
 
 int SDL_CloseStorage(SDL_Storage *storage)
 {
-    int retval;
+    int retval = 0;
 
     CHECK_STORAGE_MAGIC()
 
-    retval = storage->iface.close(storage->userdata);
+    if (storage->iface.close) {
+        retval = storage->iface.close(storage->userdata);
+    }
     SDL_free(storage);
     return retval;
 }