From c54cd8afe7152c0e4162f87a813c5742eb560eec Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Thu, 8 Mar 2018 11:49:12 -0800 Subject: [PATCH] Mac OS X: If the current working directory is the root of the filesystem, then change it instead to the user home directory so that configuration writing and settings are not useless when run from the Finder --- src/gui/sdlmain.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 01da96c133b..b5d1b4f6cd7 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -5137,6 +5137,26 @@ int main(int argc, char* argv[]) { } } } + + /* If we were launched by the Finder, the current working directory will usually be + the root of the filesystem (/) which is useless. If we see that, change instead + to the user's home directory */ + { + char *home = getenv("HOME"); + char cwd[512]; + + cwd[0]=0; + getcwd(cwd,sizeof(cwd)-1); + + if (!strcmp(cwd,"/")) { + /* Only the Finder would do that. + Even if the user somehow did this from the Terminal app, it's still + worth changing to the home directory because certain directories + including / are locked readonly even for sudo in Mac OS X */ + /* NTS: HOME is usually an absolute path */ + if (home != NULL) chdir(home); + } + } #endif {