Skip to content

Commit

Permalink
Mac OS X: If the current working directory is the root of the filesys…
Browse files Browse the repository at this point in the history
…tem, then change it instead to the user home directory so that configuration writing and settings are not useless when run from the Finder
  • Loading branch information
joncampbell123 committed Mar 8, 2018
1 parent 7860af8 commit c54cd8a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

{
Expand Down

0 comments on commit c54cd8a

Please sign in to comment.