# SDL: Simplified SDL\_SYS\_RemovePath()

**URL:** <https://discourse.libsdl.org/t/sdl-simplified-sdl-sys-removepath/50016>\
**Category:** SDL Commits\
**Created:** [March 22, 2024, 4:18am UTC](https://discourse.libsdl.org/t/sdl-simplified-sdl-sys-removepath/50016 "2024-03-22T04:18:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [March 22, 2024, 4:18am UTC](https://discourse.libsdl.org/t/sdl-simplified-sdl-sys-removepath/50016/1 "2024-03-22T04:18:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/05b57f6c2cbb4103f4ece01ab0a9182679d3b02f>
>
> If we get ENOENT we call that success. If the parent directory doesn't exist, th…at's fine, other operations on it will fail if it matters to the application.

```diff
From 05b57f6c2cbb4103f4ece01ab0a9182679d3b02f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 21 Mar 2024 21:16:14 -0700
Subject: [PATCH] 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.
---
 src/filesystem/posix/SDL_sysfsops.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c
index fcc38ed9bbda5..857782eb6ec63 100644
--- a/src/filesystem/posix/SDL_sysfsops.c
+++ b/src/filesystem/posix/SDL_sysfsops.c
@@ -59,26 +59,11 @@ int SDL_SYS_RemovePath(const char *path)
 {
     int rc = remove(path);
     if (rc < 0) {
- const int origerrno = errno;
- if (origerrno == ENOENT) {
- char *parent = SDL_strdup(path);
- if (!parent) {
- return -1;
- }
-
- 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.
- }
+ if (errno == ENOENT) {
+ // It's already gone, this is a success
+ return 0;
         }
- return SDL_SetError("Can't remove path: %s", strerror(origerrno));
+ return SDL_SetError("Can't remove path: %s", strerror(errno));
     }
     return 0;
 }

```
