mirror of https://github.com/OpenTTD/OpenTTD
(svn r27886) -Fix [FS#6575-ish]: Do not modify argv[0].
parent
35d8c37102
commit
4c50ecd958
|
@ -1032,30 +1032,29 @@ extern void DetermineBasePaths(const char *exe);
|
||||||
*/
|
*/
|
||||||
static bool ChangeWorkingDirectoryToExecutable(const char *exe)
|
static bool ChangeWorkingDirectoryToExecutable(const char *exe)
|
||||||
{
|
{
|
||||||
|
char tmp[MAX_PATH];
|
||||||
|
strecpy(tmp, exe, lastof(tmp));
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
#ifdef WITH_COCOA
|
#ifdef WITH_COCOA
|
||||||
char *app_bundle = strchr(exe, '.');
|
char *app_bundle = strchr(tmp, '.');
|
||||||
while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
|
while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
|
||||||
|
|
||||||
if (app_bundle != NULL) app_bundle[0] = '\0';
|
if (app_bundle != NULL) *app_bundle = '\0';
|
||||||
#endif /* WITH_COCOA */
|
#endif /* WITH_COCOA */
|
||||||
char *s = const_cast<char *>(strrchr(exe, PATHSEPCHAR));
|
char *s = strrchr(tmp, PATHSEPCHAR);
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
#if defined(__DJGPP__)
|
#if defined(__DJGPP__)
|
||||||
/* If we want to go to the root, we can't use cd C:, but we must use '/' */
|
/* If we want to go to the root, we can't use cd C:, but we must use '/' */
|
||||||
if (s[-1] == ':') chdir("/");
|
if (s > tmp && *(s - 1) == ':') chdir("/");
|
||||||
#endif
|
#endif
|
||||||
if (chdir(exe) != 0) {
|
if (chdir(tmp) != 0) {
|
||||||
DEBUG(misc, 0, "Directory with the binary does not exist?");
|
DEBUG(misc, 0, "Directory with the binary does not exist?");
|
||||||
} else {
|
} else {
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
*s = PATHSEPCHAR;
|
|
||||||
}
|
}
|
||||||
#ifdef WITH_COCOA
|
|
||||||
if (app_bundle != NULL) app_bundle[0] = '.';
|
|
||||||
#endif /* WITH_COCOA */
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue