View | Details | Raw Unified | Return to bug 36968
Collapse All | Expand All

(-)libiberty/pex-win32.c (-2 / +35 lines)
Lines 321-326 msys_rootify (const char *executable) Link Here
321
}
321
}
322
#endif
322
#endif
323
323
324
/* Return the number of arguments in an argv array, not including the null
325
   terminating argument. */
326
327
static int
328
argv_to_argc (char *const *argv)
329
{
330
  char *const *i = argv;
331
  while (*i)
332
    i++;
333
  return i - argv;
334
}
335
324
/* Return a Windows command-line from ARGV.  It is the caller's
336
/* Return a Windows command-line from ARGV.  It is the caller's
325
   responsibility to free the string returned.  */
337
   responsibility to free the string returned.  */
326
338
Lines 522-527 env_compare (const void *a_ptr, const vo Link Here
522
  return c1 - c2;
534
  return c1 - c2;
523
}
535
}
524
536
537
/* Execute a Windows executable as a child process.  This will fail if the
538
 * target is not actually an executable, such as if it is a shell script. */
539
525
static pid_t
540
static pid_t
526
win32_spawn (const char *executable,
541
win32_spawn (const char *executable,
527
	     BOOL search,
542
	     BOOL search,
Lines 619-624 win32_spawn (const char *executable, Link Here
619
  return (pid_t) -1;
634
  return (pid_t) -1;
620
}
635
}
621
636
637
/* Spawn a script.  This simulates the Unix script execution mechanism.
638
   This function is called as a fallback if win32_spawn fails. */
639
622
static pid_t
640
static pid_t
623
spawn_script (const char *executable, char *const *argv,
641
spawn_script (const char *executable, char *const *argv,
624
              char* const *env,
642
              char* const *env,
Lines 630-635 spawn_script (const char *executable, ch Link Here
630
  int save_errno = errno;
648
  int save_errno = errno;
631
  int fd = _open (executable, _O_RDONLY);
649
  int fd = _open (executable, _O_RDONLY);
632
650
651
  /* Try to open script, check header format, extract interpreter path,
652
     and spawn script using that interpretter. */
633
  if (fd >= 0)
653
  if (fd >= 0)
634
    {
654
    {
635
      char buf[MAX_PATH + 5];
655
      char buf[MAX_PATH + 5];
Lines 642-657 spawn_script (const char *executable, ch Link Here
642
	  eol = strchr (buf, '\n');
662
	  eol = strchr (buf, '\n');
643
	  if (eol && strncmp (buf, "#!", 2) == 0)
663
	  if (eol && strncmp (buf, "#!", 2) == 0)
644
	    {
664
	    {
665
            
666
	      /* Header format is OK. */
645
	      char *executable1;
667
	      char *executable1;
646
	      const char ** avhere = (const char **) --argv;
668
              int new_argc;
669
              const char **avhere;
670
671
	      /* Extract interpreter path. */
647
	      do
672
	      do
648
		*eol = '\0';
673
		*eol = '\0';
649
	      while (*--eol == '\r' || *eol == ' ' || *eol == '\t');
674
	      while (*--eol == '\r' || *eol == ' ' || *eol == '\t');
650
	      for (executable1 = buf + 2; *executable1 == ' ' || *executable1 == '\t'; executable1++)
675
	      for (executable1 = buf + 2; *executable1 == ' ' || *executable1 == '\t'; executable1++)
651
		continue;
676
		continue;
652
653
	      backslashify (executable1);
677
	      backslashify (executable1);
678
679
	      /* Duplicate argv, prepending the interpreter path. */
680
	      new_argc = argv_to_argc (argv) + 1;
681
	      avhere = XNEWVEC (const char *, new_argc + 1);
654
	      *avhere = executable1;
682
	      *avhere = executable1;
683
	      memcpy (avhere + 1, argv, new_argc * sizeof(*argv));
684
	      argv = (char *const *)avhere;
685
686
	      /* Spawn the child. */
655
#ifndef USE_MINGW_MSYS
687
#ifndef USE_MINGW_MSYS
656
	      executable = strrchr (executable1, '\\') + 1;
688
	      executable = strrchr (executable1, '\\') + 1;
657
	      if (!executable)
689
	      if (!executable)
Lines 686-691 spawn_script (const char *executable, ch Link Here
686
		    }
718
		    }
687
		}
719
		}
688
#endif
720
#endif
721
	      free (avhere);
689
	    }
722
	    }
690
	}
723
	}
691
    }
724
    }

Return to bug 36968