summaryrefslogtreecommitdiff
path: root/setup/execute.c
diff options
context:
space:
mode:
authorSimon Howard2010-01-27 19:50:30 +0000
committerSimon Howard2010-01-27 19:50:30 +0000
commit0b8bf3cfe37a3d6e8ad01c0f6726430f53c0ad7e (patch)
tree483f983aacbd9907290cf61f0e3b3afb1b03f7e9 /setup/execute.c
parent3cf74a97261b1a0aceb591b495b0857781918edd (diff)
parenta9e2d244a5a37fed344405e40698de2a2969c12a (diff)
downloadchocolate-doom-0b8bf3cfe37a3d6e8ad01c0f6726430f53c0ad7e.tar.gz
chocolate-doom-0b8bf3cfe37a3d6e8ad01c0f6726430f53c0ad7e.tar.bz2
chocolate-doom-0b8bf3cfe37a3d6e8ad01c0f6726430f53c0ad7e.zip
Merge from trunk.
Subversion-branch: /branches/opl-branch Subversion-revision: 1829
Diffstat (limited to 'setup/execute.c')
-rw-r--r--setup/execute.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/setup/execute.c b/setup/execute.c
index fb9885fa..8e753f60 100644
--- a/setup/execute.c
+++ b/setup/execute.c
@@ -185,29 +185,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);
@@ -301,9 +310,9 @@ static int ExecuteCommand(const char *program, const char *arg)
argv[1] = arg;
argv[2] = NULL;
- execv(argv[0], (char **) argv);
+ execvp(argv[0], (char **) argv);
- exit(-1);
+ exit(0x80);
}
else
{
@@ -312,7 +321,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);
}