Christoph Mallon: Simplify avoidance of duplicate / in SDL_GetPrefPath()
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 Aug 2013 08:24:43 -0700
changeset 7713 6074c53b0cda
parent 7712 66b5b8446275
child 7714 1c227c5f5d8d
Christoph Mallon: Simplify avoidance of duplicate / in SDL_GetPrefPath()
src/filesystem/unix/SDL_sysfilesystem.c
--- a/src/filesystem/unix/SDL_sysfilesystem.c	Wed Aug 28 22:09:17 2013 -0400
+++ b/src/filesystem/unix/SDL_sysfilesystem.c	Thu Aug 29 08:24:43 2013 -0700
@@ -156,7 +156,7 @@
      * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
      */
     const char *envr = SDL_getenv("XDG_DATA_HOME");
-    const char *append = "/";
+    const char *append;
     char *retval = NULL;
     char *ptr = NULL;
     size_t len = 0;
@@ -169,18 +169,16 @@
             SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
             return NULL;
         }
-        if (envr[SDL_strlen(envr) - 1] == '/') {
-            append = ".local/share/";
-        } else {
-            append = "/.local/share/";
-        }
+        append = "/.local/share/";
     } else {
-        if (envr[SDL_strlen(envr) - 1] == '/') {
-            append = "";
-        }
+        append = "/";
     } /* if */
 
-    len = SDL_strlen(envr) + SDL_strlen(append) + SDL_strlen(app) + 2;
+    len = SDL_strlen(envr);
+    if (envr[len - 1] == '/')
+        append += 1;
+
+    len += SDL_strlen(append) + SDL_strlen(app) + 2;
     retval = (char *) SDL_malloc(len);
     if (!retval) {
         SDL_OutOfMemory();