diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h index 5ae90d3d8..dacd585fd 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 b714a3628..477d6a5a2 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 aa5c4ddd3..7fee9008a 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 30bdd2f5b..a23a380be 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) {