mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-01 15:38:29 +00:00
Simplified SDL_SYS_RemovePath()
If we get ENOENT we call that success. If the parent directory doesn't exist, that's fine, other operations on it will fail if it matters to the application.
This commit is contained in:
@@ -59,26 +59,11 @@ int SDL_SYS_RemovePath(const char *path)
|
|||||||
{
|
{
|
||||||
int rc = remove(path);
|
int rc = remove(path);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
const int origerrno = errno;
|
if (errno == ENOENT) {
|
||||||
if (origerrno == ENOENT) {
|
// It's already gone, this is a success
|
||||||
char *parent = SDL_strdup(path);
|
return 0;
|
||||||
if (!parent) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
return SDL_SetError("Can't remove path: %s", strerror(errno));
|
||||||
char *ptr = SDL_strrchr(parent, '/');
|
|
||||||
if (ptr) {
|
|
||||||
*ptr = '\0'; // chop off thing we were removing, see if parent is there.
|
|
||||||
}
|
|
||||||
|
|
||||||
struct stat statbuf;
|
|
||||||
rc = stat(ptr ? parent : ".", &statbuf);
|
|
||||||
SDL_free(parent);
|
|
||||||
if (rc == 0) {
|
|
||||||
return 0; // it's already gone, and parent exists, consider it success.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SDL_SetError("Can't remove path: %s", strerror(origerrno));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user