Skip to content

Commit e5940b7

Browse files
authored
switch: simplify SDL_GetPrefPath (#113)
1 parent 78899b6 commit e5940b7

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/filesystem/switch/SDL_sysfilesystem.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,17 @@ char *
4545
SDL_GetPrefPath(const char *org, const char *app)
4646
{
4747
char *ret = NULL;
48-
char buf[PATH_MAX];
48+
char buf[PATH_MAX + 1];
4949
size_t len;
5050

51-
if (getcwd(buf, PATH_MAX)) {
52-
len = strlen(buf) + 2;
53-
ret = (char *) SDL_malloc(len);
54-
if (!ret) {
55-
SDL_OutOfMemory();
56-
return NULL;
57-
}
58-
SDL_snprintf(ret, len, "%s/", buf);
59-
return ret;
51+
if (getcwd(buf, sizeof(buf) - 1)) {
52+
len = strlen(buf);
53+
buf[len] = '/';
54+
buf[len + 1] = '\0';
55+
ret = SDL_strdup(buf);
6056
}
6157

62-
return NULL;
58+
return ret;
6359
}
6460

6561
#endif /* SDL_FILESYSTEM_SWITCH */

0 commit comments

Comments
 (0)