Skip to content

Commit

Permalink
Ensure custom preferences path ends with path separator
Browse files Browse the repository at this point in the history
Example:
  Given: FSO_PREFERENCES_PATH='./config' fs2_open
  Path becomes: './config/'
  • Loading branch information
daftmugi committed Dec 20, 2024
1 parent 7f48375 commit db5038b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions code/osapi/osapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ namespace
auto envPreferencesPath = getenv("FSO_PREFERENCES_PATH");
if (envPreferencesPath != nullptr && strlen(envPreferencesPath) > 0) {
preferencesPath = envPreferencesPath;

// Ensure path ends with a path separator (slash)
size_t length = strlen(preferencesPath);
if (preferencesPath[length - 1] != DIR_SEPARATOR_CHAR) {
char* fixedPath = new char[length + 2]; // +1 for DIR_SEPARATOR, +1 for '\0'
strcpy(fixedPath, preferencesPath);
strcat(fixedPath, DIR_SEPARATOR_STR);
preferencesPath = fixedPath;
}
}
else {
preferencesPath = SDL_GetPrefPath(ORGANIZATION_NAME, APPLICATION_NAME);
Expand Down

0 comments on commit db5038b

Please sign in to comment.