SDL: You can pass NULL to SDL_GetPathInfo() and SDL_GetStoragePathInfo() to test for the existence of a file.

From 92d01ef12a9a7692968b86f8113197c6ae12c06b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 18 Mar 2024 08:43:22 -0700
Subject: [PATCH] You can pass NULL to SDL_GetPathInfo() and
 SDL_GetStoragePathInfo() to test for the existence of a file.

---
 include/SDL3/SDL_filesystem.h   |  9 +++++----
 include/SDL3/SDL_storage.h      |  4 ++--
 src/filesystem/SDL_filesystem.c | 10 ++++++++--
 src/storage/SDL_storage.c       |  7 +++++++
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h
index 5ae90d3d8009e..dacd585fd4cb0 100644
--- a/include/SDL3/SDL_filesystem.h
+++ b/include/SDL3/SDL_filesystem.h
@@ -239,9 +239,10 @@ extern DECLSPEC char *SDLCALL SDL_GetUserFolder(SDL_Folder folder);
 
 typedef enum SDL_PathType
 {
-    SDL_PATHTYPE_FILE, /**< a normal file */
+    SDL_PATHTYPE_NONE,      /**< path does not exist */
+    SDL_PATHTYPE_FILE,      /**< a normal file */
     SDL_PATHTYPE_DIRECTORY, /**< a directory */
-    SDL_PATHTYPE_OTHER /**< something completely different like a device node (not a symlink, those are always followed) */
+    SDL_PATHTYPE_OTHER      /**< something completely different like a device node (not a symlink, those are always followed) */
 } SDL_PathType;
 
 /* SDL file times are 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970)
@@ -313,8 +314,8 @@ extern DECLSPEC int SDLCALL SDL_RenamePath(const char *oldpath, const char *newp
  * Get information about a filesystem path.
  *
  * \param path the path to query
- * \param info a pointer filled in with information about the path
- * \returns 0 on success or a negative error code on failure; call
+ * \param info a pointer filled in with information about the path, or NULL to check for the existence of a file
+ * \returns 0 on success or a negative error code if the file doesn't exist, or another failure; call
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
diff --git a/include/SDL3/SDL_storage.h b/include/SDL3/SDL_storage.h
index b714a3628e05f..477d6a5a2022c 100644
--- a/include/SDL3/SDL_storage.h
+++ b/include/SDL3/SDL_storage.h
@@ -317,8 +317,8 @@ extern DECLSPEC int SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const ch
  *
  * \param storage a storage container
  * \param path the path to query
- * \param info a pointer filled in with information about the path
- * \returns 0 on success or a negative error code on failure; call
+ * \param info a pointer filled in with information about the path, or NULL to check for the existence of a file
+ * \returns 0 on success or a negative error code if the file doesn't exist, or another failure; call
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
diff --git a/src/filesystem/SDL_filesystem.c b/src/filesystem/SDL_filesystem.c
index aa5c4ddd354e4..7fee9008acfc1 100644
--- a/src/filesystem/SDL_filesystem.c
+++ b/src/filesystem/SDL_filesystem.c
@@ -93,10 +93,16 @@ int SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback call
 
 int SDL_GetPathInfo(const char *path, SDL_PathInfo *info)
 {
+    SDL_PathInfo dummy;
+
+    if (!info) {
+        info = &dummy;
+    }
+    SDL_zerop(info);
+
     if (!path) {
         return SDL_InvalidParamError("path");
-    } else if (!info) {
-        return SDL_InvalidParamError("info");
     }
+
     return SDL_SYS_GetPathInfo(path, info);
 }
diff --git a/src/storage/SDL_storage.c b/src/storage/SDL_storage.c
index 30bdd2f5b5f28..a23a380be5c05 100644
--- a/src/storage/SDL_storage.c
+++ b/src/storage/SDL_storage.c
@@ -290,6 +290,13 @@ int SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char
 
 int SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info)
 {
+    SDL_PathInfo dummy;
+
+    if (!info) {
+        info = &dummy;
+    }
+    SDL_zerop(info);
+
     CHECK_STORAGE_MAGIC()
 
     if (!path) {