aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Win32
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-02 20:41:09 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-02 20:41:09 +0000
commitaad7ba1b9a9c87694073c72dcaf93f8b5b3e3250 (patch)
treef2d0012a46578d4d0099f5269fad3a132eebca76 /lib/System/Win32
parent159abc0158542e0a7fe3a1200e93df0af32e163c (diff)
downloadexternal_llvm-aad7ba1b9a9c87694073c72dcaf93f8b5b3e3250.zip
external_llvm-aad7ba1b9a9c87694073c72dcaf93f8b5b3e3250.tar.gz
external_llvm-aad7ba1b9a9c87694073c72dcaf93f8b5b3e3250.tar.bz2
Empty arguments need to be quoted on Win32.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77913 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Win32')
-rw-r--r--lib/System/Win32/Program.inc12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc
index 7dbfb3e..963946a 100644
--- a/lib/System/Win32/Program.inc
+++ b/lib/System/Win32/Program.inc
@@ -109,6 +109,12 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
DWORD cbJobObjectInfoLength);
#endif
+/// ArgNeedsQuotes - Check whether argument needs to be quoted when calling
+/// CreateProcess.
+static bool ArgNeedsQuotes(const char *Str) {
+ return Str[0] == '\0' || strchr(Str, ' ') != 0;
+}
+
bool
Program::Execute(const Path& path,
const char** args,
@@ -124,13 +130,13 @@ Program::Execute(const Path& path,
// Windows wants a command line, not an array of args, to pass to the new
// process. We have to concatenate them all, while quoting the args that
- // have embedded spaces.
+ // have embedded spaces (or are empty).
// First, determine the length of the command line.
unsigned len = 0;
for (unsigned i = 0; args[i]; i++) {
len += strlen(args[i]) + 1;
- if (strchr(args[i], ' '))
+ if (ArgNeedsQuotes(args[i]))
len += 2;
}
@@ -141,7 +147,7 @@ Program::Execute(const Path& path,
for (unsigned i = 0; args[i]; i++) {
const char *arg = args[i];
size_t len = strlen(arg);
- bool needsQuoting = strchr(arg, ' ') != 0;
+ bool needsQuoting = ArgNeedsQuotes(arg);
if (needsQuoting)
*p++ = '"';
memcpy(p, arg, len);