Ver Fonte

emscripten: Create directory recursively in GetPrefPath

Charlie Birks há 4 anos atrás
pai
commit
1a48ca666f
1 ficheiros alterados com 11 adições e 0 exclusões
  1. 11 0
      src/filesystem/emscripten/SDL_sysfilesystem.c

+ 11 - 0
src/filesystem/emscripten/SDL_sysfilesystem.c

@@ -44,6 +44,7 @@ SDL_GetPrefPath(const char *org, const char *app)
 {
     const char *append = "/libsdl/";
     char *retval;
+    char *ptr = NULL;
     size_t len = 0;
 
     if (!app) {
@@ -67,7 +68,17 @@ SDL_GetPrefPath(const char *org, const char *app)
         SDL_snprintf(retval, len, "%s%s/", append, app);
     }
 
+    for (ptr = retval+1; *ptr; ptr++) {
+        if (*ptr == '/') {
+            *ptr = '\0';
+            if (mkdir(retval, 0700) != 0 && errno != EEXIST)
+                goto error;
+            *ptr = '/';
+        }
+    }
+
     if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
+error:
         SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
         SDL_free(retval);
         return NULL;