2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll spawn/exec functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2008-01-07 14:24:02 +01:00
|
|
|
* Copyright 2007 Hans Leidekker
|
2001-01-11 00:59:25 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-11 00:59:25 +01:00
|
|
|
* FIXME:
|
|
|
|
* -File handles need some special handling. Sometimes children get
|
|
|
|
* open file handles, sometimes not. The docs are confusing
|
|
|
|
* -No check for maximum path/argument/environment size is done
|
|
|
|
*/
|
2002-08-09 21:49:31 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2013-01-18 11:03:51 +01:00
|
|
|
#include "mtdll.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
2007-09-21 15:50:01 +02:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
static void msvcrt_search_executable(const MSVCRT_wchar_t *name, MSVCRT_wchar_t *fullname, int use_path)
|
|
|
|
{
|
|
|
|
static const MSVCRT_wchar_t path[] = {'P','A','T','H',0};
|
|
|
|
static const MSVCRT_wchar_t suffix[][5] =
|
|
|
|
{{'.','c','o','m',0}, {'.','e','x','e',0}, {'.','b','a','t',0}, {'.','c','m','d',0}};
|
|
|
|
|
|
|
|
MSVCRT_wchar_t buffer[MAX_PATH];
|
|
|
|
const MSVCRT_wchar_t *env, *p;
|
|
|
|
unsigned int i, name_len, path_len;
|
|
|
|
int extension = 1;
|
|
|
|
|
|
|
|
*fullname = '\0';
|
|
|
|
msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
|
|
|
|
|
|
|
|
p = memchrW(name, '\0', MAX_PATH);
|
|
|
|
if (!p) p = name + MAX_PATH - 1;
|
|
|
|
name_len = p - name;
|
|
|
|
|
|
|
|
/* FIXME extra-long names are silently truncated */
|
|
|
|
memcpy(buffer, name, name_len * sizeof(MSVCRT_wchar_t));
|
|
|
|
buffer[name_len] = '\0';
|
|
|
|
|
|
|
|
/* try current dir first */
|
|
|
|
if (GetFileAttributesW(buffer) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
strcpyW(fullname, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p--; p >= name; p--)
|
|
|
|
if (*p == '\\' || *p == '/' || *p == ':' || *p == '.') break;
|
|
|
|
|
|
|
|
/* if there's no extension, try some well-known extensions */
|
|
|
|
if ((p < name || *p != '.') && name_len <= MAX_PATH - 5)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
memcpy(buffer + name_len, suffix[i], 5 * sizeof(MSVCRT_wchar_t));
|
|
|
|
if (GetFileAttributesW(buffer) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
strcpyW(fullname, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extension = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:32 +02:00
|
|
|
if (!use_path || !(env = MSVCRT__wgetenv(path))) return;
|
2008-01-07 14:24:02 +01:00
|
|
|
|
|
|
|
/* now try search path */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
p = env;
|
|
|
|
while (*p && *p != ';') p++;
|
|
|
|
if (p == env) return;
|
|
|
|
|
|
|
|
path_len = p - env;
|
|
|
|
if (path_len + name_len <= MAX_PATH - 2)
|
|
|
|
{
|
|
|
|
memcpy(buffer, env, path_len * sizeof(MSVCRT_wchar_t));
|
2008-09-23 14:32:00 +02:00
|
|
|
if (buffer[path_len] != '/' && buffer[path_len] != '\\')
|
2008-01-07 14:24:02 +01:00
|
|
|
{
|
|
|
|
buffer[path_len++] = '\\';
|
|
|
|
buffer[path_len] = '\0';
|
|
|
|
}
|
|
|
|
else buffer[path_len] = '\0';
|
|
|
|
|
|
|
|
strcatW(buffer, name);
|
|
|
|
if (GetFileAttributesW(buffer) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
strcpyW(fullname, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* again, if there's no extension, try some well-known extensions */
|
|
|
|
if (!extension && path_len + name_len <= MAX_PATH - 5)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
memcpy(buffer + path_len + name_len, suffix[i], 5 * sizeof(MSVCRT_wchar_t));
|
|
|
|
if (GetFileAttributesW(buffer) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
strcpyW(fullname, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env = *p ? p + 1 : p;
|
|
|
|
} while(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MSVCRT_intptr_t msvcrt_spawn(int flags, const MSVCRT_wchar_t* exe, MSVCRT_wchar_t* cmdline,
|
|
|
|
MSVCRT_wchar_t* env, int use_path)
|
2007-09-21 15:50:01 +02:00
|
|
|
{
|
|
|
|
STARTUPINFOW si;
|
|
|
|
PROCESS_INFORMATION pi;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t fullname[MAX_PATH];
|
2014-12-04 11:41:30 +01:00
|
|
|
DWORD create_flags = CREATE_UNICODE_ENVIRONMENT;
|
2008-01-07 14:24:02 +01:00
|
|
|
|
|
|
|
TRACE("%x %s %s %s %d\n", flags, debugstr_w(exe), debugstr_w(cmdline), debugstr_w(env), use_path);
|
2007-09-21 15:50:01 +02:00
|
|
|
|
|
|
|
if ((unsigned)flags > MSVCRT__P_DETACH)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
msvcrt_search_executable(exe, fullname, use_path);
|
|
|
|
|
2007-09-21 15:50:01 +02:00
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
msvcrt_create_io_inherit_block(&si.cbReserved2, &si.lpReserved2);
|
2014-12-04 11:41:30 +01:00
|
|
|
if (flags == MSVCRT__P_DETACH) create_flags |= DETACHED_PROCESS;
|
2008-01-07 14:24:02 +01:00
|
|
|
if (!CreateProcessW(fullname, cmdline, NULL, NULL, TRUE,
|
2014-12-04 11:41:30 +01:00
|
|
|
create_flags, env, NULL, &si, &pi))
|
2007-09-21 15:50:01 +02:00
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
MSVCRT_free(si.lpReserved2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_free(si.lpReserved2);
|
|
|
|
switch(flags)
|
|
|
|
{
|
|
|
|
case MSVCRT__P_WAIT:
|
|
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
|
GetExitCodeProcess(pi.hProcess,&pi.dwProcessId);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
return pi.dwProcessId;
|
|
|
|
case MSVCRT__P_DETACH:
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
pi.hProcess = 0;
|
|
|
|
/* fall through */
|
|
|
|
case MSVCRT__P_NOWAIT:
|
|
|
|
case MSVCRT__P_NOWAITO:
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
return (MSVCRT_intptr_t)pi.hProcess;
|
|
|
|
case MSVCRT__P_OVERLAY:
|
|
|
|
MSVCRT__exit(0);
|
|
|
|
}
|
|
|
|
return -1; /* can't reach here */
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/* INTERNAL: Convert wide argv list to a single 'delim'-separated wide string, with an
|
|
|
|
* extra '\0' to terminate it.
|
|
|
|
*/
|
2008-01-07 14:23:08 +01:00
|
|
|
static MSVCRT_wchar_t* msvcrt_argvtos(const MSVCRT_wchar_t* const* arg, MSVCRT_wchar_t delim)
|
2007-09-21 15:50:01 +02:00
|
|
|
{
|
|
|
|
const MSVCRT_wchar_t* const* a;
|
2009-05-23 11:49:09 +02:00
|
|
|
int size;
|
2007-09-21 15:50:01 +02:00
|
|
|
MSVCRT_wchar_t* p;
|
|
|
|
MSVCRT_wchar_t* ret;
|
|
|
|
|
2008-01-10 09:49:47 +01:00
|
|
|
if (!arg)
|
2007-09-21 15:50:01 +02:00
|
|
|
{
|
|
|
|
/* Return NULL for an empty environment list */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get length */
|
|
|
|
a = arg;
|
|
|
|
size = 0;
|
|
|
|
while (*a)
|
|
|
|
{
|
|
|
|
size += strlenW(*a) + 1;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = MSVCRT_malloc((size + 1) * sizeof(MSVCRT_wchar_t));
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* fill string */
|
|
|
|
a = arg;
|
|
|
|
p = ret;
|
|
|
|
while (*a)
|
|
|
|
{
|
|
|
|
int len = strlenW(*a);
|
|
|
|
memcpy(p,*a,len * sizeof(MSVCRT_wchar_t));
|
|
|
|
p += len;
|
|
|
|
*p++ = delim;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
if (delim && p > ret) p[-1] = 0;
|
|
|
|
else *p = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
/* INTERNAL: Convert ansi argv list to a single 'delim'-separated wide string, with an
|
|
|
|
* extra '\0' to terminate it.
|
2001-09-11 01:07:07 +02:00
|
|
|
*/
|
2008-01-07 14:22:46 +01:00
|
|
|
static MSVCRT_wchar_t *msvcrt_argvtos_aw(const char * const *arg, MSVCRT_wchar_t delim)
|
|
|
|
{
|
|
|
|
const char * const *a;
|
2009-05-23 11:49:09 +02:00
|
|
|
unsigned int len;
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_wchar_t *p, *ret;
|
|
|
|
|
2008-01-10 09:49:47 +01:00
|
|
|
if (!arg)
|
2008-01-07 14:22:46 +01:00
|
|
|
{
|
|
|
|
/* Return NULL for an empty environment list */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get length */
|
|
|
|
a = arg;
|
|
|
|
len = 0;
|
|
|
|
while (*a)
|
|
|
|
{
|
|
|
|
len += MultiByteToWideChar(CP_ACP, 0, *a, -1, NULL, 0);
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = MSVCRT_malloc((len + 1) * sizeof(MSVCRT_wchar_t));
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* fill string */
|
|
|
|
a = arg;
|
|
|
|
p = ret;
|
|
|
|
while (*a)
|
|
|
|
{
|
|
|
|
p += MultiByteToWideChar(CP_ACP, 0, *a, strlen(*a), p, len - (p - ret));
|
|
|
|
*p++ = delim;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
if (delim && p > ret) p[-1] = 0;
|
|
|
|
else *p = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/* INTERNAL: Convert wide va_list to a single 'delim'-separated wide string, with an
|
|
|
|
* extra '\0' to terminate it.
|
|
|
|
*/
|
2009-01-02 21:46:35 +01:00
|
|
|
static MSVCRT_wchar_t *msvcrt_valisttos(const MSVCRT_wchar_t *arg0, __ms_va_list alist, MSVCRT_wchar_t delim)
|
2008-01-07 14:23:19 +01:00
|
|
|
{
|
2008-12-17 12:55:30 +01:00
|
|
|
unsigned int size = 0, pos = 0;
|
|
|
|
const MSVCRT_wchar_t *arg;
|
|
|
|
MSVCRT_wchar_t *new, *ret = NULL;
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2008-12-17 12:55:30 +01:00
|
|
|
for (arg = arg0; arg; arg = va_arg( alist, MSVCRT_wchar_t * ))
|
|
|
|
{
|
|
|
|
unsigned int len = strlenW( arg ) + 1;
|
|
|
|
if (pos + len >= size)
|
|
|
|
{
|
|
|
|
size = max( 256, size * 2 );
|
|
|
|
size = max( size, pos + len + 1 );
|
|
|
|
if (!(new = MSVCRT_realloc( ret, size * sizeof(MSVCRT_wchar_t) )))
|
|
|
|
{
|
|
|
|
MSVCRT_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ret = new;
|
|
|
|
}
|
|
|
|
strcpyW( ret + pos, arg );
|
|
|
|
pos += len;
|
|
|
|
ret[pos - 1] = delim;
|
|
|
|
}
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
if (delim) ret[pos - 1] = 0;
|
|
|
|
else ret[pos] = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2008-01-07 14:23:19 +01:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
/* INTERNAL: Convert ansi va_list to a single 'delim'-separated wide string, with an
|
|
|
|
* extra '\0' to terminate it.
|
|
|
|
*/
|
2009-01-02 21:46:35 +01:00
|
|
|
static MSVCRT_wchar_t *msvcrt_valisttos_aw(const char *arg0, __ms_va_list alist, MSVCRT_wchar_t delim)
|
2001-05-18 22:58:08 +02:00
|
|
|
{
|
2008-12-17 12:55:30 +01:00
|
|
|
unsigned int size = 0, pos = 0;
|
|
|
|
const char *arg;
|
|
|
|
MSVCRT_wchar_t *new, *ret = NULL;
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-12-17 12:55:30 +01:00
|
|
|
for (arg = arg0; arg; arg = va_arg( alist, char * ))
|
|
|
|
{
|
|
|
|
unsigned int len = MultiByteToWideChar( CP_ACP, 0, arg, -1, NULL, 0 );
|
|
|
|
if (pos + len >= size)
|
|
|
|
{
|
|
|
|
size = max( 256, size * 2 );
|
|
|
|
size = max( size, pos + len + 1 );
|
|
|
|
if (!(new = MSVCRT_realloc( ret, size * sizeof(MSVCRT_wchar_t) )))
|
|
|
|
{
|
|
|
|
MSVCRT_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ret = new;
|
|
|
|
}
|
|
|
|
pos += MultiByteToWideChar( CP_ACP, 0, arg, -1, ret + pos, size - pos );
|
|
|
|
ret[pos - 1] = delim;
|
|
|
|
}
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
if (delim) ret[pos - 1] = 0;
|
|
|
|
else ret[pos] = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2001-05-18 22:58:08 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:22:23 +01:00
|
|
|
/* INTERNAL: retrieve COMSPEC environment variable */
|
|
|
|
static MSVCRT_wchar_t *msvcrt_get_comspec(void)
|
|
|
|
{
|
|
|
|
static const MSVCRT_wchar_t cmd[] = {'c','m','d',0};
|
|
|
|
static const MSVCRT_wchar_t comspec[] = {'C','O','M','S','P','E','C',0};
|
|
|
|
MSVCRT_wchar_t *ret;
|
|
|
|
unsigned int len;
|
|
|
|
|
2018-07-26 00:05:52 +02:00
|
|
|
if (!(len = GetEnvironmentVariableW(comspec, NULL, 0))) len = ARRAY_SIZE(cmd);
|
2008-01-07 14:22:23 +01:00
|
|
|
if ((ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t))))
|
|
|
|
{
|
|
|
|
if (!GetEnvironmentVariableW(comspec, ret, len)) strcpyW(ret, cmd);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _cwait (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_intptr_t CDECL _cwait(int *status, MSVCRT_intptr_t pid, int action)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
HANDLE hPid = (HANDLE)pid;
|
|
|
|
int doserrno;
|
|
|
|
|
2004-04-09 21:03:13 +02:00
|
|
|
if (!WaitForSingleObject(hPid, INFINITE))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
DWORD stat;
|
|
|
|
GetExitCodeProcess(hPid, &stat);
|
|
|
|
*status = (int)stat;
|
|
|
|
}
|
2005-11-03 14:17:51 +01:00
|
|
|
return pid;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
doserrno = GetLastError();
|
|
|
|
|
|
|
|
if (doserrno == ERROR_INVALID_HANDLE)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ECHILD;
|
2004-03-16 20:17:11 +01:00
|
|
|
*MSVCRT___doserrno() = doserrno;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
else
|
2004-06-25 03:19:15 +02:00
|
|
|
msvcrt_set_errno(doserrno);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
return status ? *status = -1 : -1;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecl (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execl
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wexecl(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:19 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:23:19 +01:00
|
|
|
MSVCRT_wchar_t *args;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, name, args, NULL, 0);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execl (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _execl(const char* name, const char* arg0, ...)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
2008-01-07 14:22:46 +01:00
|
|
|
|
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, nameW, args, NULL, 0);
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
2001-05-22 21:18:51 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecle (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execle
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wexecle(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:19 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:23:19 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs = NULL;
|
|
|
|
const MSVCRT_wchar_t * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
while (va_arg( ap, MSVCRT_wchar_t * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const MSVCRT_wchar_t * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, name, args, envs, 0);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-14 04:29:51 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _execle (MSVCRT.@)
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _execle(const char* name, const char* arg0, ...)
|
2003-11-14 04:29:51 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:22:57 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs = NULL;
|
|
|
|
const char * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:57 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:57 +01:00
|
|
|
while (va_arg( ap, char * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const char * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos_aw(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, nameW, args, envs, 0);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2003-11-14 04:29:51 +01:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexeclp (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execlp
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wexeclp(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:19 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args;
|
2008-01-07 14:23:19 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, name, args, NULL, 1);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execlp (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _execlp(const char* name, const char* arg0, ...)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args;
|
2005-11-03 14:17:51 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, nameW, args, NULL, 1);
|
2001-05-22 21:18:51 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
2001-05-22 21:18:51 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexeclpe (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execlpe
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wexeclpe(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:19 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs = NULL;
|
2008-01-07 14:23:19 +01:00
|
|
|
const MSVCRT_wchar_t * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:19 +01:00
|
|
|
while (va_arg( ap, MSVCRT_wchar_t * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const MSVCRT_wchar_t * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, name, args, envs, 1);
|
2008-01-07 14:23:19 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-14 04:29:51 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _execlpe (MSVCRT.@)
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _execlpe(const char* name, const char* arg0, ...)
|
2003-11-14 04:29:51 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs = NULL;
|
2008-01-07 14:22:57 +01:00
|
|
|
const char * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:57 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:57 +01:00
|
|
|
while (va_arg( ap, char * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const char * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos_aw(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(MSVCRT__P_OVERLAY, nameW, args, envs, 1);
|
2008-01-07 14:22:57 +01:00
|
|
|
|
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2003-11-14 04:29:51 +01:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecv (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execv
|
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _wexecv(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv)
|
2008-01-07 14:23:46 +01:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__wspawnve(MSVCRT__P_OVERLAY, name, argv, NULL);
|
2008-01-07 14:23:46 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execv (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _execv(const char* name, const char* const* argv)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__spawnve(MSVCRT__P_OVERLAY, name, argv, NULL);
|
2001-05-22 21:18:51 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecve (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execve
|
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _wexecve(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv, const MSVCRT_wchar_t* const* envv)
|
2008-01-07 14:23:46 +01:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__wspawnve(MSVCRT__P_OVERLAY, name, argv, envv);
|
2008-01-07 14:23:46 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execve (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL MSVCRT__execve(const char* name, const char* const* argv, const char* const* envv)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__spawnve(MSVCRT__P_OVERLAY, name, argv, envv);
|
2001-05-22 21:18:51 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecvpe (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execvpe
|
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _wexecvpe(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv, const MSVCRT_wchar_t* const* envv)
|
2008-01-07 14:23:46 +01:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__wspawnvpe(MSVCRT__P_OVERLAY, name, argv, envv);
|
2008-01-07 14:23:46 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execvpe (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _execvpe(const char* name, const char* const* argv, const char* const* envv)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
2013-04-09 13:45:48 +02:00
|
|
|
return MSVCRT__spawnvpe(MSVCRT__P_OVERLAY, name, argv, envv);
|
2001-05-22 21:18:51 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wexecvp (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _execvp
|
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _wexecvp(const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv)
|
2008-01-07 14:23:46 +01:00
|
|
|
{
|
|
|
|
return _wexecvpe(name, argv, NULL);
|
|
|
|
}
|
|
|
|
|
2001-05-22 21:18:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _execvp (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-22 21:18:51 +02:00
|
|
|
*/
|
2013-04-09 13:45:48 +02:00
|
|
|
MSVCRT_intptr_t CDECL _execvp(const char* name, const char* const* argv)
|
2001-05-22 21:18:51 +02:00
|
|
|
{
|
|
|
|
return _execvpe(name, argv, NULL);
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnl (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnl
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wspawnl(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:32 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:23:32 +01:00
|
|
|
MSVCRT_wchar_t *args;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, name, args, NULL, 0);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-18 22:58:08 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnl (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-18 22:58:08 +02:00
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _spawnl(int flags, const char* name, const char* arg0, ...)
|
2001-05-18 22:58:08 +02:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args;
|
2005-11-03 14:17:51 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, nameW, args, NULL, 0);
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
2001-05-18 22:58:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnle (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnle
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wspawnle(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:32 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:23:32 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs = NULL;
|
|
|
|
const MSVCRT_wchar_t * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
while (va_arg( ap, MSVCRT_wchar_t * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const MSVCRT_wchar_t * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, name, args, envs, 0);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-14 04:29:51 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnle (MSVCRT.@)
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _spawnle(int flags, const char* name, const char* arg0, ...)
|
2003-11-14 04:29:51 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs = NULL;
|
|
|
|
const char * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:46 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
while (va_arg( ap, char * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const char * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos_aw(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:22:46 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, nameW, args, envs, 0);
|
2008-01-07 14:22:46 +01:00
|
|
|
|
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2003-11-14 04:29:51 +01:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnlp (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnlp
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wspawnlp(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:32 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args;
|
2008-01-07 14:23:32 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, name, args, NULL, 1);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
return ret;
|
|
|
|
}
|
2003-11-14 04:29:51 +01:00
|
|
|
|
2001-05-18 22:58:08 +02:00
|
|
|
/*********************************************************************
|
2001-05-22 21:18:51 +02:00
|
|
|
* _spawnlp (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-05-18 22:58:08 +02:00
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _spawnlp(int flags, const char* name, const char* arg0, ...)
|
2001-05-18 22:58:08 +02:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args;
|
2005-11-03 14:17:51 +01:00
|
|
|
MSVCRT_intptr_t ret;
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, nameW, args, NULL, 1);
|
2001-05-18 22:58:08 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
2001-05-18 22:58:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:23:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnlpe (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnlpe
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _wspawnlpe(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* arg0, ...)
|
2008-01-07 14:23:32 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs = NULL;
|
2008-01-07 14:23:32 +01:00
|
|
|
const MSVCRT_wchar_t * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
args = msvcrt_valisttos(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:23:32 +01:00
|
|
|
while (va_arg( ap, MSVCRT_wchar_t * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const MSVCRT_wchar_t * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, name, args, envs, 1);
|
2008-01-07 14:23:32 +01:00
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-14 04:29:51 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnlpe (MSVCRT.@)
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
MSVCRT_intptr_t WINAPIV _spawnlpe(int flags, const char* name, const char* arg0, ...)
|
2003-11-14 04:29:51 +01:00
|
|
|
{
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_list ap;
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs = NULL;
|
2008-01-07 14:22:46 +01:00
|
|
|
const char * const *envp;
|
|
|
|
MSVCRT_intptr_t ret;
|
2004-07-16 05:08:19 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
2004-07-16 05:08:19 +02:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
args = msvcrt_valisttos_aw(arg0, ap, ' ');
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2004-07-16 05:08:19 +02:00
|
|
|
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_start(ap, arg0);
|
2008-01-07 14:22:46 +01:00
|
|
|
while (va_arg( ap, char * ) != NULL) /*nothing*/;
|
|
|
|
envp = va_arg( ap, const char * const * );
|
|
|
|
if (envp) envs = msvcrt_argvtos_aw(envp, 0);
|
2009-01-02 21:46:35 +01:00
|
|
|
__ms_va_end(ap);
|
2004-07-16 05:08:19 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, nameW, args, envs, 1);
|
2004-07-16 05:08:19 +02:00
|
|
|
|
2008-01-07 14:22:46 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2003-11-14 04:29:51 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnve (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2010-03-29 00:00:26 +02:00
|
|
|
MSVCRT_intptr_t CDECL MSVCRT__spawnve(int flags, const char* name, const char* const* argv,
|
2006-06-13 11:21:19 +02:00
|
|
|
const char* const* envv)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2008-01-07 14:23:08 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs;
|
|
|
|
MSVCRT_intptr_t ret;
|
2006-04-05 20:37:01 +02:00
|
|
|
|
2008-01-07 14:23:08 +01:00
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
2006-04-05 20:37:01 +02:00
|
|
|
|
2008-01-07 14:23:08 +01:00
|
|
|
args = msvcrt_argvtos_aw(argv, ' ');
|
|
|
|
envs = msvcrt_argvtos_aw(envv, 0);
|
2006-04-05 20:37:01 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, nameW, args, envs, 0);
|
2006-04-05 20:37:01 +02:00
|
|
|
|
2008-01-07 14:23:08 +01:00
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
2006-08-09 01:17:41 +02:00
|
|
|
MSVCRT_free(envs);
|
2001-01-11 00:59:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-21 15:50:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnve (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnve
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_intptr_t CDECL MSVCRT__wspawnve(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv,
|
2007-09-21 15:50:01 +02:00
|
|
|
const MSVCRT_wchar_t* const* envv)
|
|
|
|
{
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs;
|
|
|
|
MSVCRT_intptr_t ret;
|
2007-09-21 15:50:01 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
args = msvcrt_argvtos(argv, ' ');
|
|
|
|
envs = msvcrt_argvtos(envv, 0);
|
2007-09-21 15:50:01 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
ret = msvcrt_spawn(flags, name, args, envs, 0);
|
2007-09-21 15:50:01 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_free(args);
|
2007-09-21 15:50:01 +02:00
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnv (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_intptr_t CDECL _spawnv(int flags, const char* name, const char* const* argv)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2010-03-29 00:00:26 +02:00
|
|
|
return MSVCRT__spawnve(flags, name, argv, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-09-21 15:50:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnv (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnv
|
|
|
|
*/
|
|
|
|
MSVCRT_intptr_t CDECL _wspawnv(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv)
|
|
|
|
{
|
2011-06-03 15:28:32 +02:00
|
|
|
return MSVCRT__wspawnve(flags, name, argv, NULL);
|
2007-09-21 15:50:01 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnvpe (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2010-03-29 00:00:26 +02:00
|
|
|
MSVCRT_intptr_t CDECL MSVCRT__spawnvpe(int flags, const char* name, const char* const* argv,
|
2006-06-13 11:21:19 +02:00
|
|
|
const char* const* envv)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *nameW, *args, *envs;
|
|
|
|
MSVCRT_intptr_t ret;
|
|
|
|
|
|
|
|
if (!(nameW = msvcrt_wstrdupa(name))) return -1;
|
|
|
|
|
|
|
|
args = msvcrt_argvtos_aw(argv, ' ');
|
|
|
|
envs = msvcrt_argvtos_aw(envv, 0);
|
|
|
|
|
|
|
|
ret = msvcrt_spawn(flags, nameW, args, envs, 1);
|
|
|
|
|
|
|
|
MSVCRT_free(nameW);
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-09-21 15:50:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnvpe (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnvpe
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
MSVCRT_intptr_t CDECL MSVCRT__wspawnvpe(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv,
|
2007-09-21 15:50:01 +02:00
|
|
|
const MSVCRT_wchar_t* const* envv)
|
|
|
|
{
|
2008-01-07 14:24:02 +01:00
|
|
|
MSVCRT_wchar_t *args, *envs;
|
|
|
|
MSVCRT_intptr_t ret;
|
2007-09-21 15:50:01 +02:00
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
args = msvcrt_argvtos(argv, ' ');
|
|
|
|
envs = msvcrt_argvtos(envv, 0);
|
|
|
|
|
|
|
|
ret = msvcrt_spawn(flags, name, args, envs, 1);
|
|
|
|
|
|
|
|
MSVCRT_free(args);
|
|
|
|
MSVCRT_free(envs);
|
|
|
|
return ret;
|
2007-09-21 15:50:01 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _spawnvp (MSVCRT.@)
|
2001-09-11 01:07:07 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Like on Windows, this function does not handle arguments with spaces
|
2001-09-11 01:07:07 +02:00
|
|
|
* or double-quotes.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_intptr_t CDECL _spawnvp(int flags, const char* name, const char* const* argv)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2010-03-29 00:00:26 +02:00
|
|
|
return MSVCRT__spawnvpe(flags, name, argv, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-09-21 15:50:01 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wspawnvp (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _spawnvp
|
|
|
|
*/
|
|
|
|
MSVCRT_intptr_t CDECL _wspawnvp(int flags, const MSVCRT_wchar_t* name, const MSVCRT_wchar_t* const* argv)
|
|
|
|
{
|
2011-06-03 15:28:32 +02:00
|
|
|
return MSVCRT__wspawnvpe(flags, name, argv, NULL);
|
2007-09-21 15:50:01 +02:00
|
|
|
}
|
|
|
|
|
2013-01-18 11:03:51 +01:00
|
|
|
static struct popen_handle {
|
|
|
|
MSVCRT_FILE *f;
|
|
|
|
HANDLE proc;
|
|
|
|
} *popen_handles;
|
|
|
|
static DWORD popen_handles_size;
|
|
|
|
|
|
|
|
void msvcrt_free_popen_data(void)
|
|
|
|
{
|
|
|
|
MSVCRT_free(popen_handles);
|
|
|
|
}
|
|
|
|
|
2003-08-20 05:34:20 +02:00
|
|
|
/*********************************************************************
|
2008-01-07 14:22:36 +01:00
|
|
|
* _wpopen (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _popen
|
2003-08-20 05:34:20 +02:00
|
|
|
*/
|
2008-01-07 14:22:36 +01:00
|
|
|
MSVCRT_FILE* CDECL MSVCRT__wpopen(const MSVCRT_wchar_t* command, const MSVCRT_wchar_t* mode)
|
2003-08-20 05:34:20 +02:00
|
|
|
{
|
2004-12-14 16:13:54 +01:00
|
|
|
MSVCRT_FILE *ret;
|
|
|
|
BOOL readPipe = TRUE;
|
2010-11-15 22:50:23 +01:00
|
|
|
int textmode, fds[2], fdToDup, fdToOpen, fdStdHandle = -1;
|
2008-01-07 14:22:36 +01:00
|
|
|
const MSVCRT_wchar_t *p;
|
|
|
|
MSVCRT_wchar_t *comspec, *fullcmd;
|
|
|
|
unsigned int len;
|
|
|
|
static const MSVCRT_wchar_t flag[] = {' ','/','c',' ',0};
|
2013-01-18 11:03:51 +01:00
|
|
|
struct popen_handle *container;
|
|
|
|
DWORD i;
|
2004-12-14 16:13:54 +01:00
|
|
|
|
2008-01-07 14:22:36 +01:00
|
|
|
TRACE("(command=%s, mode=%s)\n", debugstr_w(command), debugstr_w(mode));
|
2004-12-14 16:13:54 +01:00
|
|
|
|
|
|
|
if (!command || !mode)
|
|
|
|
return NULL;
|
|
|
|
|
2018-12-14 17:47:08 +01:00
|
|
|
textmode = *MSVCRT___p__fmode() & (MSVCRT__O_BINARY | MSVCRT__O_TEXT);
|
2004-12-14 16:13:54 +01:00
|
|
|
for (p = mode; *p; p++)
|
|
|
|
{
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case 'W':
|
|
|
|
case 'w':
|
|
|
|
readPipe = FALSE;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
textmode |= MSVCRT__O_BINARY;
|
|
|
|
textmode &= ~MSVCRT__O_TEXT;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
case 't':
|
|
|
|
textmode |= MSVCRT__O_TEXT;
|
|
|
|
textmode &= ~MSVCRT__O_BINARY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 16:33:34 +02:00
|
|
|
if (MSVCRT__pipe(fds, 0, textmode) == -1)
|
2004-12-14 16:13:54 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fdToDup = readPipe ? 1 : 0;
|
|
|
|
fdToOpen = readPipe ? 0 : 1;
|
|
|
|
|
2013-01-18 11:03:51 +01:00
|
|
|
_mlock(_POPEN_LOCK);
|
|
|
|
for(i=0; i<popen_handles_size; i++)
|
|
|
|
{
|
|
|
|
if (!popen_handles[i].f)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i==popen_handles_size)
|
|
|
|
{
|
|
|
|
i = (popen_handles_size ? popen_handles_size*2 : 8);
|
|
|
|
container = MSVCRT_realloc(popen_handles, i*sizeof(*container));
|
|
|
|
if (!container) goto error;
|
|
|
|
|
|
|
|
popen_handles = container;
|
|
|
|
container = popen_handles+popen_handles_size;
|
|
|
|
memset(container, 0, (i-popen_handles_size)*sizeof(*container));
|
|
|
|
popen_handles_size = i;
|
|
|
|
}
|
|
|
|
else container = popen_handles+i;
|
|
|
|
|
2007-09-18 16:33:34 +02:00
|
|
|
if ((fdStdHandle = MSVCRT__dup(fdToDup)) == -1)
|
2004-12-14 16:13:54 +01:00
|
|
|
goto error;
|
2007-09-18 16:33:34 +02:00
|
|
|
if (MSVCRT__dup2(fds[fdToDup], fdToDup) != 0)
|
2004-12-14 16:13:54 +01:00
|
|
|
goto error;
|
|
|
|
|
2007-09-18 16:33:34 +02:00
|
|
|
MSVCRT__close(fds[fdToDup]);
|
2004-12-14 16:13:54 +01:00
|
|
|
|
2008-01-07 14:22:36 +01:00
|
|
|
if (!(comspec = msvcrt_get_comspec())) goto error;
|
|
|
|
len = strlenW(comspec) + strlenW(flag) + strlenW(command) + 1;
|
|
|
|
|
2011-01-15 09:28:08 +01:00
|
|
|
if (!(fullcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, comspec);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:22:36 +01:00
|
|
|
strcpyW(fullcmd, comspec);
|
|
|
|
strcatW(fullcmd, flag);
|
|
|
|
strcatW(fullcmd, command);
|
|
|
|
|
2013-01-18 11:03:51 +01:00
|
|
|
if ((container->proc = (HANDLE)msvcrt_spawn(MSVCRT__P_NOWAIT, comspec, fullcmd, NULL, 1))
|
|
|
|
== INVALID_HANDLE_VALUE)
|
2004-12-14 16:13:54 +01:00
|
|
|
{
|
2007-09-18 16:33:34 +02:00
|
|
|
MSVCRT__close(fds[fdToOpen]);
|
2004-12-14 16:13:54 +01:00
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-07 14:22:36 +01:00
|
|
|
ret = MSVCRT__wfdopen(fds[fdToOpen], mode);
|
2004-12-14 16:13:54 +01:00
|
|
|
if (!ret)
|
2007-09-18 16:33:34 +02:00
|
|
|
MSVCRT__close(fds[fdToOpen]);
|
2013-01-18 11:03:51 +01:00
|
|
|
container->f = ret;
|
2004-12-14 16:13:54 +01:00
|
|
|
}
|
2013-01-18 11:03:51 +01:00
|
|
|
_munlock(_POPEN_LOCK);
|
2008-10-07 15:36:44 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, comspec);
|
2008-01-07 14:22:36 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, fullcmd);
|
2007-09-18 16:33:34 +02:00
|
|
|
MSVCRT__dup2(fdStdHandle, fdToDup);
|
|
|
|
MSVCRT__close(fdStdHandle);
|
2004-12-14 16:13:54 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
2013-01-18 11:03:51 +01:00
|
|
|
_munlock(_POPEN_LOCK);
|
2007-09-18 16:33:34 +02:00
|
|
|
if (fdStdHandle != -1) MSVCRT__close(fdStdHandle);
|
|
|
|
MSVCRT__close(fds[0]);
|
|
|
|
MSVCRT__close(fds[1]);
|
2003-08-20 05:34:20 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2008-01-07 14:22:36 +01:00
|
|
|
* _popen (MSVCRT.@)
|
2003-08-20 05:34:20 +02:00
|
|
|
*/
|
2008-01-07 14:22:36 +01:00
|
|
|
MSVCRT_FILE* CDECL MSVCRT__popen(const char* command, const char* mode)
|
2003-08-20 05:34:20 +02:00
|
|
|
{
|
2008-01-07 14:22:36 +01:00
|
|
|
MSVCRT_FILE *ret;
|
|
|
|
MSVCRT_wchar_t *cmdW, *modeW;
|
|
|
|
|
|
|
|
TRACE("(command=%s, mode=%s)\n", debugstr_a(command), debugstr_a(mode));
|
|
|
|
|
|
|
|
if (!command || !mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(cmdW = msvcrt_wstrdupa(command))) return NULL;
|
|
|
|
if (!(modeW = msvcrt_wstrdupa(mode)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdW);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = MSVCRT__wpopen(cmdW, modeW);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, modeW);
|
|
|
|
return ret;
|
2003-08-20 05:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _pclose (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT__pclose(MSVCRT_FILE* file)
|
2003-08-20 05:34:20 +02:00
|
|
|
{
|
2013-01-18 11:03:51 +01:00
|
|
|
HANDLE h;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(file != NULL)) return -1;
|
|
|
|
|
|
|
|
_mlock(_POPEN_LOCK);
|
|
|
|
for(i=0; i<popen_handles_size; i++)
|
|
|
|
{
|
|
|
|
if (popen_handles[i].f == file)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == popen_handles_size)
|
|
|
|
{
|
|
|
|
_munlock(_POPEN_LOCK);
|
|
|
|
*MSVCRT__errno() = MSVCRT_EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = popen_handles[i].proc;
|
|
|
|
popen_handles[i].f = NULL;
|
|
|
|
_munlock(_POPEN_LOCK);
|
|
|
|
|
|
|
|
MSVCRT_fclose(file);
|
|
|
|
if(WaitForSingleObject(h, INFINITE)==WAIT_FAILED || !GetExitCodeProcess(h, &i))
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
CloseHandle(h);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(h);
|
|
|
|
return i;
|
2003-08-20 05:34:20 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:22:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wsystem (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of system
|
|
|
|
*/
|
|
|
|
int CDECL _wsystem(const MSVCRT_wchar_t* cmd)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
MSVCRT_wchar_t *comspec, *fullcmd;
|
|
|
|
unsigned int len;
|
|
|
|
static const MSVCRT_wchar_t flag[] = {' ','/','c',' ',0};
|
|
|
|
|
2010-05-27 18:45:06 +02:00
|
|
|
comspec = msvcrt_get_comspec();
|
|
|
|
|
|
|
|
if (cmd == NULL)
|
|
|
|
{
|
|
|
|
if (comspec == NULL)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_ENOENT;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-15 09:28:13 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, comspec);
|
2010-05-27 18:45:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( comspec == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-01-07 14:22:23 +01:00
|
|
|
len = strlenW(comspec) + strlenW(flag) + strlenW(cmd) + 1;
|
|
|
|
|
|
|
|
if (!(fullcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, comspec);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpyW(fullcmd, comspec);
|
|
|
|
strcatW(fullcmd, flag);
|
|
|
|
strcatW(fullcmd, cmd);
|
|
|
|
|
2008-01-07 14:24:02 +01:00
|
|
|
res = msvcrt_spawn(MSVCRT__P_WAIT, comspec, fullcmd, NULL, 1);
|
2008-01-07 14:22:23 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, comspec);
|
|
|
|
HeapFree(GetProcessHeap(), 0, fullcmd);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* system (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_system(const char* cmd)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2008-01-07 14:22:23 +01:00
|
|
|
int res = -1;
|
|
|
|
MSVCRT_wchar_t *cmdW;
|
2001-09-11 01:07:07 +02:00
|
|
|
|
2010-05-27 18:45:06 +02:00
|
|
|
if (cmd == NULL)
|
|
|
|
return _wsystem(NULL);
|
|
|
|
|
2008-01-07 14:22:23 +01:00
|
|
|
if ((cmdW = msvcrt_wstrdupa(cmd)))
|
|
|
|
{
|
|
|
|
res = _wsystem(cmdW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdW);
|
|
|
|
}
|
|
|
|
return res;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _loaddll (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_intptr_t CDECL _loaddll(const char* dllname)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2005-11-03 14:17:51 +01:00
|
|
|
return (MSVCRT_intptr_t)LoadLibraryA(dllname);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _unloaddll (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _unloaddll(MSVCRT_intptr_t dll)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-10-04 02:27:10 +02:00
|
|
|
if (FreeLibrary((HMODULE)dll))
|
2001-01-11 00:59:25 +01:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int err = GetLastError();
|
2004-06-25 03:19:15 +02:00
|
|
|
msvcrt_set_errno(err);
|
2001-01-11 00:59:25 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2003-03-17 01:05:44 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdllprocaddr (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void * CDECL _getdllprocaddr(MSVCRT_intptr_t dll, const char *name, int ordinal)
|
2003-03-17 01:05:44 +01:00
|
|
|
{
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (ordinal != -1) return NULL;
|
|
|
|
return GetProcAddress( (HMODULE)dll, name );
|
|
|
|
}
|
|
|
|
if (HIWORD(ordinal)) return NULL;
|
|
|
|
return GetProcAddress( (HMODULE)dll, (LPCSTR)(ULONG_PTR)ordinal );
|
|
|
|
}
|
2013-03-27 16:13:43 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getpid (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _getpid(void)
|
|
|
|
{
|
|
|
|
return GetCurrentProcessId();
|
|
|
|
}
|
2014-04-17 13:07:21 +02:00
|
|
|
|
2018-01-07 06:05:31 +01:00
|
|
|
#if _MSVCR_VER>=110
|
2014-04-17 13:07:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtTerminateProcess (MSVCR110.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCR110__crtTerminateProcess(UINT exit_code)
|
|
|
|
{
|
|
|
|
return TerminateProcess(GetCurrentProcess(), exit_code);
|
|
|
|
}
|
2018-01-07 06:05:31 +01:00
|
|
|
#endif
|