]> code.delx.au - gnu-emacs/commitdiff
Backport fix for bug#18745 from master.
authorNoam Postavsky <npostavs@users.sourceforget.net>
Tue, 10 Feb 2015 16:51:14 +0000 (18:51 +0200)
committerEli Zaretskii <eliz@gnu.org>
Tue, 10 Feb 2015 16:51:14 +0000 (18:51 +0200)
 nt/cmdproxy.c (batch_file_p): New function.
 (spawn): If calling a quoted batch file pass NULL for progname.

nt/ChangeLog
nt/cmdproxy.c

index d1f953f9ac58300c32825d942db10b8db5cecbd8..861cb18f0b23def6b3a6e2efb181e26905acf607 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-10  Noam Postavsky  <npostavs@users.sourceforget.net>
+
+       * nt/cmdproxy.c (batch_file_p): New function.
+       (spawn): If calling a quoted batch file pass NULL for progname.
+       (Bug#18745)
+
 2015-02-10  Eli Zaretskii  <eliz@gnu.org>
 
        * cmdproxy.c (get_next_token): Don't make backslashes disappear
index ce5815291dfee083d646f0cf66c4e0deb22f85ec..16956288fef75655e3e9577589b96778fd4583d3 100644 (file)
@@ -243,6 +243,28 @@ get_next_token (char * buf, const char ** pSrc)
   return o - buf;
 }
 
+/* Return TRUE if PROGNAME is a batch file. */
+BOOL
+batch_file_p (const char *progname)
+{
+  const char *exts[] = {".bat", ".cmd"};
+  int n_exts = sizeof (exts) / sizeof (char *);
+  int i;
+
+  const char *ext = strrchr (progname, '.');
+
+  if (ext)
+    {
+      for (i = 0; i < n_exts; i++)
+        {
+          if (stricmp (ext, exts[i]) == 0)
+            return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
 /* Search for EXEC file in DIR.  If EXEC does not have an extension,
    DIR is searched for EXEC with the standard extensions appended.  */
 int
@@ -524,6 +546,13 @@ spawn (const char *progname, char *cmdline, const char *dir, int *retcode)
   memset (&start, 0, sizeof (start));
   start.cb = sizeof (start);
 
+  /* CreateProcess handles batch files as progname specially.  This
+     special handling fails when both the batch file and arguments are
+     quoted.  We pass NULL as progname to avoid the special
+     handling. */
+  if (progname != NULL && cmdline[0] == '"' && batch_file_p (progname))
+    progname = NULL;
+
   if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
                     0, envblock, dir, &start, &child))
   {