switch: use getcwd for SDL_GetPrefPath

This commit is contained in:
cpasjuste 2021-06-24 13:55:22 +02:00
parent a10e1c5b40
commit 8249883616

View File

@ -27,6 +27,7 @@
#include <limits.h> #include <limits.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/unistd.h>
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_stdinc.h" #include "SDL_stdinc.h"
@ -43,44 +44,22 @@ SDL_GetBasePath(void)
char * char *
SDL_GetPrefPath(const char *org, const char *app) SDL_GetPrefPath(const char *org, const char *app)
{ {
const char *envr = "sdmc:/switch/"; char *ret = NULL;
char *retval = NULL; char buf[PATH_MAX];
char *ptr = NULL; size_t len;
size_t len = 0;
if (!app) { if (getcwd(buf, PATH_MAX)) {
SDL_InvalidParamError("app"); len = strlen(buf) + 2;
return NULL; ret = (char *) SDL_malloc(len);
} if (!ret) {
if (!org) { SDL_OutOfMemory();
org = ""; return NULL;
}
len = SDL_strlen(envr);
len += SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *) SDL_malloc(len);
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
if (*org) {
SDL_snprintf(retval, len, "%s%s/%s/", envr, org, app);
} else {
SDL_snprintf(retval, len, "%s%s/", envr, app);
}
for (ptr = retval+1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
mkdir(retval, 0777);
*ptr = '/';
} }
SDL_snprintf(ret, len, "%s/", buf);
return ret;
} }
mkdir(retval, 0777);
return retval; return NULL;
} }
#endif /* SDL_FILESYSTEM_SWITCH */ #endif /* SDL_FILESYSTEM_SWITCH */