Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit cd6d089

Browse files
committed
emscripten: Create directory recursively in GetPrefPath
1 parent 2695e11 commit cd6d089

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/filesystem/emscripten/SDL_sysfilesystem.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SDL_GetPrefPath(const char *org, const char *app)
4444
{
4545
const char *append = "/libsdl/";
4646
char *retval;
47+
char *ptr = NULL;
4748
size_t len = 0;
4849

4950
if (!app) {
@@ -67,7 +68,17 @@ SDL_GetPrefPath(const char *org, const char *app)
6768
SDL_snprintf(retval, len, "%s%s/", append, app);
6869
}
6970

71+
for (ptr = retval+1; *ptr; ptr++) {
72+
if (*ptr == '/') {
73+
*ptr = '\0';
74+
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
75+
goto error;
76+
*ptr = '/';
77+
}
78+
}
79+
7080
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
81+
error:
7182
SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
7283
SDL_free(retval);
7384
return NULL;

0 commit comments

Comments
 (0)