+static char* CmdAllocArg (const char* Arg, unsigned Len)
+/* Alloc (potentially quoted) argument */
+{
+ char* Alloc;
+
+/* The Microsoft docs say on spawnvp():
+** Spaces embedded in strings may cause unexpected behavior; for example,
+** passing _spawn the string "hi there" will result in the new process getting
+** two arguments, "hi" and "there". If the intent was to have the new process
+** open a file named "hi there", the process would fail. You can avoid this by
+** quoting the string: "\"hi there\"".
+*/
+#if defined(_WIN32)
+ /* Quote argument if it contains space(s) */
+ if (memchr (Arg, ' ', Len)) {
+ Alloc = xmalloc (Len + 3);
+ Alloc[0] = '"';
+ memcpy (Alloc + 1, Arg, Len);
+ Alloc[Len + 1] = '"';
+ Alloc[Len + 2] = '\0';
+ } else
+#endif
+ {
+ Alloc = xmalloc (Len + 1);
+ memcpy (Alloc, Arg, Len);
+ Alloc[Len] = '\0';
+ }
+ return Alloc;
+}
+
+
+