Fixed bug 3639 - SDL_GetPrefPath returns a path with two consecutive slashes on Unix if org is omitted
Fabian Greffrath we use SDL_GetPrefPath() in Chocolate Doom to get a reasonable directory to save and restore config files and savegames: https://github.com/chocolate-doom/chocolate-doom/blob/sdl2-branch/src/m_config.c#L2162 However, since there is no "organization" behind Chocolate Doom and there is really only one "product" called Chocolate Doom, we pass an empty string for the org parameter and the package string for app. This leads to two consecutive slashes in the path returned by SDL_GetPrefPath() like this: /home/user/.local/share//chocolate-doom/ While this is harmless, it sure looks bad. I believe that it should be possible to either pass a NULL pointer for the org parameter or at least have the function detect an empty string as a means to express "there is no origanization, just a single product". The generation of the path string to be returned by the function will have to get adapted accordingly.
This commit is contained in:
parent
594181451c
commit
ebae122371
8 changed files with 90 additions and 10 deletions
|
@ -77,6 +77,15 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
const char *home = SDL_getenv("HOME");
|
||||
const char *append = "/config/settings/";
|
||||
size_t len = SDL_strlen(home);
|
||||
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
if (!len || (home[len - 1] == '/')) {
|
||||
++append; // home empty or ends with separator, skip the one from append
|
||||
}
|
||||
|
@ -85,7 +94,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
|
||||
}
|
||||
create_directory(retval, 0700); // Haiku api: creates missing dirs
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue