diff options
author | Simon Howard | 2010-02-06 03:14:20 +0000 |
---|---|---|
committer | Simon Howard | 2010-02-06 03:14:20 +0000 |
commit | d9520b6415f8e373cf759f316094b986e57f0f5a (patch) | |
tree | d256f7d4f1941ec33ae3c956449c70349de7297d /src/setup/execute.c | |
parent | 57011e785808847273461aaf6d8ed1df76ff1db9 (diff) | |
parent | 52f81b4ef175358d1e1f7f9eecab2a1edb7f4b65 (diff) | |
download | chocolate-doom-d9520b6415f8e373cf759f316094b986e57f0f5a.tar.gz chocolate-doom-d9520b6415f8e373cf759f316094b986e57f0f5a.tar.bz2 chocolate-doom-d9520b6415f8e373cf759f316094b986e57f0f5a.zip |
Merge from trunk.
Subversion-branch: /branches/strife-branch
Subversion-revision: 1849
Diffstat (limited to 'src/setup/execute.c')
-rw-r--r-- | src/setup/execute.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/setup/execute.c b/src/setup/execute.c index be7214f5..4be44149 100644 --- a/src/setup/execute.c +++ b/src/setup/execute.c @@ -172,29 +172,38 @@ static void ConcatWCString(wchar_t *buf, const char *value) static wchar_t *BuildCommandLine(const char *program, const char *arg) { + wchar_t exe_path[MAX_PATH]; wchar_t *result; - char *sep; + wchar_t *sep; + + // Get the path to this .exe file. + + GetModuleFileNameW(NULL, exe_path, MAX_PATH); - result = calloc(strlen(myargv[0]) + strlen(program) + strlen(arg) + 6, + // Allocate buffer to contain result string. + + result = calloc(wcslen(exe_path) + strlen(program) + strlen(arg) + 6, sizeof(wchar_t)); wcscpy(result, L"\""); - sep = strrchr(myargv[0], DIR_SEPARATOR); + // Copy the path part of the filename (including ending \) + // into the result buffer: + + sep = wcsrchr(exe_path, DIR_SEPARATOR); if (sep != NULL) { - ConcatWCString(result, myargv[0]); - - // Cut off the string after the last directory separator, - // before appending the actual program. - - result[sep - myargv[0] + 2] = '\0'; - + wcsncpy(result + 1, exe_path, sep - exe_path + 1); + result[sep - exe_path + 2] = '\0'; } + // Concatenate the name of the program: + ConcatWCString(result, program); + // End of program name, start of argument: + wcscat(result, L"\" \""); ConcatWCString(result, arg); @@ -290,7 +299,7 @@ static int ExecuteCommand(const char *program, const char *arg) execvp(argv[0], (char **) argv); - exit(-1); + exit(0x80); } else { @@ -299,7 +308,7 @@ static int ExecuteCommand(const char *program, const char *arg) waitpid(childpid, &result, 0); - if (WIFEXITED(result)) + if (WIFEXITED(result) && WEXITSTATUS(result) != 0x80) { return WEXITSTATUS(result); } |