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

This commit is contained in:
Sam Lantinga
2024-03-18 08:43:22 -07:00
parent ebb6582534
commit 92d01ef12a
4 changed files with 22 additions and 8 deletions

View File

@@ -239,6 +239,7 @@ extern DECLSPEC char *SDLCALL SDL_GetUserFolder(SDL_Folder folder);
typedef enum SDL_PathType typedef enum SDL_PathType
{ {
SDL_PATHTYPE_NONE, /**< path does not exist */
SDL_PATHTYPE_FILE, /**< a normal file */ SDL_PATHTYPE_FILE, /**< a normal file */
SDL_PATHTYPE_DIRECTORY, /**< a directory */ 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) */
@@ -313,8 +314,8 @@ extern DECLSPEC int SDLCALL SDL_RenamePath(const char *oldpath, const char *newp
* Get information about a filesystem path. * Get information about a filesystem path.
* *
* \param path the path to query * \param path the path to query
* \param info a pointer filled in with information about the path * \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 on failure; call * \returns 0 on success or a negative error code if the file doesn't exist, or another failure; call
* SDL_GetError() for more information. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.

View File

@@ -317,8 +317,8 @@ extern DECLSPEC int SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const ch
* *
* \param storage a storage container * \param storage a storage container
* \param path the path to query * \param path the path to query
* \param info a pointer filled in with information about the path * \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 on failure; call * \returns 0 on success or a negative error code if the file doesn't exist, or another failure; call
* SDL_GetError() for more information. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.

View File

@@ -93,10 +93,16 @@ int SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback call
int SDL_GetPathInfo(const char *path, SDL_PathInfo *info) int SDL_GetPathInfo(const char *path, SDL_PathInfo *info)
{ {
SDL_PathInfo dummy;
if (!info) {
info = &dummy;
}
SDL_zerop(info);
if (!path) { if (!path) {
return SDL_InvalidParamError("path"); return SDL_InvalidParamError("path");
} else if (!info) {
return SDL_InvalidParamError("info");
} }
return SDL_SYS_GetPathInfo(path, info); return SDL_SYS_GetPathInfo(path, info);
} }

View File

@@ -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) 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() CHECK_STORAGE_MAGIC()
if (!path) { if (!path) {