Commit e5b65e4e037c3839487cab56dd4b176e5e358887

Edward Rudd 2013-08-24T09:05:18

Fix #2062 Be more diligent about validating trailing "/" existence in HOME and XDG_DATA_HOME env vars

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index d8eb6e5..d3a3a06 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -173,7 +173,15 @@ SDL_GetPrefPath(const char *org, const char *app)
             SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
             return NULL;
         }
-        append = ".local/share/";
+        if (envr[SDL_strlen(envr) - 1] == '/') {
+            append = ".local/share/";
+        } else {
+            append = "/.local/share/";
+        }
+    } else {
+        if (envr[SDL_strlen(envr) - 1] == '/') {
+            append = "";
+        }
     } /* if */
 
     len = SDL_strlen(envr) + SDL_strlen(append) + SDL_strlen(app) + 2;