/* Auxiliary functions for the creation of subprocesses. Native Woe32 API.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006-2009 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Get declarations of the Win32 API functions. */
#define WIN32_LEAN_AND_MEAN
#include <io.h>
#include <stdbool.h>
+#include <string.h>
#include <errno.h>
-#include "strpbrk.h"
#include "xalloc.h"
/* Duplicates a file handle, making the copy uninheritable. */
FALSE, /* InheritHandle */
DUPLICATE_SAME_ACCESS)) /* Options */
error (EXIT_FAILURE, 0, _("DuplicateHandle failed with error code 0x%08x"),
- GetLastError ());
+ (unsigned int) GetLastError ());
nfd = _open_osfhandle ((long) new_handle, O_BINARY);
if (nfd < 0)
;
/* Allocate new argument vector. */
- new_argv = (char **) xmalloc ((argc + 1) * sizeof (char *));
+ new_argv = XNMALLOC (1 + argc + 1, char *);
+
+ /* Add an element upfront that can be used when argv[0] turns out to be a
+ script, not a program.
+ On Unix, this would be "/bin/sh". On native Windows, "sh" is actually
+ "sh.exe". We have to omit the directory part and rely on the search in
+ PATH, because the mingw "mount points" are not visible inside Win32
+ CreateProcess(). */
+ *new_argv++ = "sh.exe";
/* Put quoted arguments into the new argument vector. */
for (i = 0; i < argc; i++)