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

main
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,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.

View File

@ -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.

View File

@ -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);
}

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)
{
SDL_PathInfo dummy;
if (!info) {
info = &dummy;
}
SDL_zerop(info);
CHECK_STORAGE_MAGIC()
if (!path) {