[llvm-commits] [llvm] r77913 - /llvm/trunk/lib/System/Win32/Program.inc
Daniel Dunbar
daniel at zuster.org
Sun Aug 2 13:41:09 PDT 2009
Author: ddunbar
Date: Sun Aug 2 15:41:09 2009
New Revision: 77913
URL: http://llvm.org/viewvc/llvm-project?rev=77913&view=rev
Log:
Empty arguments need to be quoted on Win32.
Modified:
llvm/trunk/lib/System/Win32/Program.inc
Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=77913&r1=77912&r2=77913&view=diff
==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Sun Aug 2 15:41:09 2009
@@ -109,6 +109,12 @@
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 @@
// 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 @@
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);
More information about the llvm-commits
mailing list