emscripten: Create directory recursively in GetPrefPath

This commit is contained in:
Charlie Birks 2021-02-04 16:20:54 +00:00 committed by Ryan C. Gordon
parent fa367cdd5c
commit 1a48ca666f
1 changed files with 11 additions and 0 deletions

View File

@ -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;