1998-04-13 14:21:30 +02:00
|
|
|
/*
|
|
|
|
* Process environment management
|
|
|
|
*
|
|
|
|
* Copyright 1996, 1998 Alexandre Julliard
|
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
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1998-04-13 14:21:30 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-06-18 05:23:22 +02:00
|
|
|
#include <assert.h>
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2000-11-28 23:40:56 +01:00
|
|
|
#include "winerror.h"
|
2002-05-17 01:16:01 +02:00
|
|
|
#include "wine/library.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2003-06-18 05:23:22 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2005-06-14 13:42:34 +02:00
|
|
|
#include "kernel_private.h"
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(environ);
|
2000-12-11 04:48:15 +01:00
|
|
|
|
2003-09-18 06:28:22 +02:00
|
|
|
/* Notes:
|
1998-04-13 14:21:30 +02:00
|
|
|
* - contrary to Microsoft docs, the environment strings do not appear
|
|
|
|
* to be sorted on Win95 (although they are on NT); so we don't bother
|
|
|
|
* to sort them either.
|
|
|
|
*/
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
static STARTUPINFOW startup_infoW;
|
|
|
|
static STARTUPINFOA startup_infoA;
|
|
|
|
|
1998-04-13 14:21:30 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetCommandLineA (KERNEL32.@)
|
2001-10-02 19:49:20 +02:00
|
|
|
*
|
|
|
|
* WARNING: there's a Windows incompatibility lurking here !
|
|
|
|
* Win32s always includes the full path of the program file,
|
|
|
|
* whereas Windows NT only returns the full file path plus arguments
|
|
|
|
* in case the program has been started with a full path.
|
|
|
|
* Win9x seems to have inherited NT behaviour.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2001-10-02 19:49:20 +02:00
|
|
|
* Note that both Start Menu Execute and Explorer start programs with
|
|
|
|
* fully specified quoted app file paths, which is why probably the only case
|
|
|
|
* where you'll see single file names is in case of direct launch
|
|
|
|
* via CreateProcess or WinExec.
|
|
|
|
*
|
|
|
|
* Perhaps we should take care of Win3.1 programs here (Win32s "feature").
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2001-10-02 19:49:20 +02:00
|
|
|
* References: MS KB article q102762.txt (special Win32s handling)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
2000-06-24 15:37:05 +02:00
|
|
|
LPSTR WINAPI GetCommandLineA(void)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
static char *cmdlineA; /* ASCII command line */
|
|
|
|
|
|
|
|
if (!cmdlineA) /* make an ansi version if we don't have it */
|
|
|
|
{
|
|
|
|
ANSI_STRING ansi;
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
|
|
|
cmdlineA = (RtlUnicodeStringToAnsiString( &ansi, &NtCurrentTeb()->Peb->ProcessParameters->CommandLine, TRUE) == STATUS_SUCCESS) ?
|
|
|
|
ansi.Buffer : NULL;
|
|
|
|
RtlReleasePebLock();
|
|
|
|
}
|
|
|
|
return cmdlineA;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetCommandLineW (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
2000-06-24 15:37:05 +02:00
|
|
|
LPWSTR WINAPI GetCommandLineW(void)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
return NtCurrentTeb()->Peb->ProcessParameters->CommandLine.Buffer;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetEnvironmentStringsA (KERNEL32.@)
|
2005-11-08 12:01:03 +01:00
|
|
|
* GetEnvironmentStrings (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
LPSTR WINAPI GetEnvironmentStringsA(void)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
LPWSTR ptrW;
|
|
|
|
unsigned len, slen;
|
|
|
|
LPSTR ret, ptrA;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
|
|
|
len = 1;
|
|
|
|
|
|
|
|
ptrW = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
|
|
|
while (*ptrW)
|
|
|
|
{
|
|
|
|
slen = strlenW(ptrW) + 1;
|
|
|
|
len += WideCharToMultiByte( CP_ACP, 0, ptrW, slen, NULL, 0, NULL, NULL );
|
|
|
|
ptrW += slen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )) != NULL)
|
|
|
|
{
|
|
|
|
ptrW = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
|
|
|
ptrA = ret;
|
|
|
|
while (*ptrW)
|
|
|
|
{
|
|
|
|
slen = strlenW(ptrW) + 1;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, ptrW, slen, ptrA, len, NULL, NULL );
|
|
|
|
ptrW += slen;
|
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
}
|
|
|
|
*ptrA = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetEnvironmentStringsW (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
LPWSTR WINAPI GetEnvironmentStringsW(void)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
return NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* FreeEnvironmentStringsA (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI FreeEnvironmentStringsA( LPSTR ptr )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
return HeapFree( GetProcessHeap(), 0, ptr );
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* FreeEnvironmentStringsW (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI FreeEnvironmentStringsW( LPWSTR ptr )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
return TRUE;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetEnvironmentVariableA (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_name;
|
|
|
|
PWSTR valueW;
|
|
|
|
DWORD ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
|
|
|
|
if (!name || !*name)
|
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
SetLastError(ERROR_ENVVAR_NOT_FOUND);
|
1998-04-13 14:21:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-08-20 02:22:29 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
if (!(valueW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz( &us_name, name );
|
|
|
|
SetLastError(0);
|
|
|
|
ret = GetEnvironmentVariableW( us_name.Buffer, valueW, size);
|
|
|
|
if (ret && ret < size)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, valueW, ret + 1, value, size, NULL, NULL );
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
/* this is needed to tell, with 0 as a return value, the difference between:
|
|
|
|
* - an error (GetLastError() != 0)
|
|
|
|
* - returning an empty string (in this case, we need to update the buffer)
|
|
|
|
*/
|
|
|
|
if (ret == 0 && size && GetLastError() == 0)
|
|
|
|
value[0] = '\0';
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &us_name );
|
|
|
|
HeapFree(GetProcessHeap(), 0, valueW);
|
|
|
|
|
2000-09-22 22:58:23 +02:00
|
|
|
return ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetEnvironmentVariableW (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
2003-06-18 05:23:22 +02:00
|
|
|
DWORD WINAPI GetEnvironmentVariableW( LPCWSTR name, LPWSTR val, DWORD size )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_name;
|
|
|
|
UNICODE_STRING us_value;
|
|
|
|
NTSTATUS status;
|
|
|
|
unsigned len;
|
2002-08-20 02:22:29 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%s %p %u)\n", debugstr_w(name), val, size);
|
2003-06-18 05:23:22 +02:00
|
|
|
|
|
|
|
if (!name || !*name)
|
2002-08-20 02:22:29 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
SetLastError(ERROR_ENVVAR_NOT_FOUND);
|
2002-08-20 02:22:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlInitUnicodeString(&us_name, name);
|
|
|
|
us_value.Length = 0;
|
|
|
|
us_value.MaximumLength = (size ? size - 1 : 0) * sizeof(WCHAR);
|
|
|
|
us_value.Buffer = val;
|
|
|
|
|
|
|
|
status = RtlQueryEnvironmentVariable_U(NULL, &us_name, &us_value);
|
|
|
|
len = us_value.Length / sizeof(WCHAR);
|
|
|
|
if (status != STATUS_SUCCESS)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return (status == STATUS_BUFFER_TOO_SMALL) ? len + 1 : 0;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
if (size) val[len] = '\0';
|
|
|
|
|
|
|
|
return us_value.Length / sizeof(WCHAR);
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetEnvironmentVariableA (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_name;
|
|
|
|
BOOL ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
if (!name)
|
2002-08-20 02:22:29 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
SetLastError(ERROR_ENVVAR_NOT_FOUND);
|
|
|
|
return 0;
|
2002-08-20 02:22:29 +02:00
|
|
|
}
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz( &us_name, name );
|
|
|
|
if (value)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_value;
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz( &us_value, value );
|
|
|
|
ret = SetEnvironmentVariableW( us_name.Buffer, us_value.Buffer );
|
|
|
|
RtlFreeUnicodeString( &us_value );
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
else ret = SetEnvironmentVariableW( us_name.Buffer, NULL );
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlFreeUnicodeString( &us_name );
|
1998-04-13 14:21:30 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetEnvironmentVariableW (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI SetEnvironmentVariableW( LPCWSTR name, LPCWSTR value )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("(%s %s)\n", debugstr_w(name), debugstr_w(value));
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_ENVVAR_NOT_FOUND);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&us_name, name);
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
UNICODE_STRING us_value;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&us_value, value);
|
|
|
|
status = RtlSetEnvironmentVariable(NULL, &us_name, &us_value);
|
|
|
|
}
|
|
|
|
else status = RtlSetEnvironmentVariable(NULL, &us_name, NULL);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ExpandEnvironmentStringsA (KERNEL32.@)
|
1998-04-13 14:21:30 +02:00
|
|
|
*
|
2008-01-11 09:52:16 +01:00
|
|
|
* See ExpandEnvironmentStringsW.
|
|
|
|
*
|
1998-04-13 14:21:30 +02:00
|
|
|
* Note: overlapping buffers are not supported; this is how it should be.
|
2003-06-18 05:23:22 +02:00
|
|
|
* FIXME: return value is wrong for MBCS
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI ExpandEnvironmentStringsA( LPCSTR src, LPSTR dst, DWORD count )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_src;
|
|
|
|
PWSTR dstW = NULL;
|
|
|
|
DWORD ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz( &us_src, src );
|
|
|
|
if (count)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
if (!(dstW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
|
|
|
|
return 0;
|
|
|
|
ret = ExpandEnvironmentStringsW( us_src.Buffer, dstW, count);
|
|
|
|
if (ret)
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, dstW, ret, dst, count, NULL, NULL );
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
else ret = ExpandEnvironmentStringsW( us_src.Buffer, NULL, 0);
|
1998-04-13 14:21:30 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
RtlFreeUnicodeString( &us_src );
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, dstW);
|
2003-06-18 05:23:22 +02:00
|
|
|
|
|
|
|
return ret;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ExpandEnvironmentStringsW (KERNEL32.@)
|
2008-01-11 09:52:16 +01:00
|
|
|
*
|
|
|
|
* Replaces references to environment variables of the form '%EnvVar%'
|
|
|
|
* by their value. If the environment variable does not exist, then the
|
|
|
|
* reference is left as is.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* src [I] The string to be expanded.
|
|
|
|
* dst [O] The buffer in which to put the expanded string.
|
|
|
|
* len [I] The buffer size, in characters.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The number of characters copied into the buffer. If the buffer is
|
|
|
|
* too small, then the required buffer size, in characters including the
|
|
|
|
* trailing '\0', is returned.
|
|
|
|
* If the function fails for some other reason, then it returns 0.
|
1998-04-13 14:21:30 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI ExpandEnvironmentStringsW( LPCWSTR src, LPWSTR dst, DWORD len )
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
UNICODE_STRING us_src;
|
|
|
|
UNICODE_STRING us_dst;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD res;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%s %p %u)\n", debugstr_w(src), dst, len);
|
2003-06-18 05:23:22 +02:00
|
|
|
|
|
|
|
RtlInitUnicodeString(&us_src, src);
|
2006-08-19 19:27:01 +02:00
|
|
|
|
2008-01-11 09:52:16 +01:00
|
|
|
/* make sure we don't overflow the maximum UNICODE_STRING size */
|
2009-12-14 13:58:24 +01:00
|
|
|
if (len > UNICODE_STRING_MAX_CHARS)
|
|
|
|
len = UNICODE_STRING_MAX_CHARS;
|
2006-08-19 19:27:01 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
us_dst.Length = 0;
|
|
|
|
us_dst.MaximumLength = len * sizeof(WCHAR);
|
|
|
|
us_dst.Buffer = dst;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
status = RtlExpandEnvironmentStrings_U(NULL, &us_src, &us_dst, &res);
|
|
|
|
res /= sizeof(WCHAR);
|
|
|
|
if (status != STATUS_SUCCESS)
|
1998-04-13 14:21:30 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) return 0;
|
|
|
|
if (len && dst) dst[len - 1] = '\0';
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
|
|
|
|
return res;
|
1998-04-13 14:21:30 +02:00
|
|
|
}
|
|
|
|
|
2000-08-10 00:33:42 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetStdHandle (KERNEL32.@)
|
2000-08-10 00:33:42 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI GetStdHandle( DWORD std_handle )
|
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
switch (std_handle)
|
2000-08-10 00:33:42 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
case STD_INPUT_HANDLE: return NtCurrentTeb()->Peb->ProcessParameters->hStdInput;
|
|
|
|
case STD_OUTPUT_HANDLE: return NtCurrentTeb()->Peb->ProcessParameters->hStdOutput;
|
|
|
|
case STD_ERROR_HANDLE: return NtCurrentTeb()->Peb->ProcessParameters->hStdError;
|
2000-08-10 00:33:42 +02:00
|
|
|
}
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetStdHandle (KERNEL32.@)
|
2000-08-10 00:33:42 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetStdHandle( DWORD std_handle, HANDLE handle )
|
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
switch (std_handle)
|
2000-08-10 00:33:42 +02:00
|
|
|
{
|
2003-06-18 05:23:22 +02:00
|
|
|
case STD_INPUT_HANDLE: NtCurrentTeb()->Peb->ProcessParameters->hStdInput = handle; return TRUE;
|
|
|
|
case STD_OUTPUT_HANDLE: NtCurrentTeb()->Peb->ProcessParameters->hStdOutput = handle; return TRUE;
|
|
|
|
case STD_ERROR_HANDLE: NtCurrentTeb()->Peb->ProcessParameters->hStdError = handle; return TRUE;
|
2000-08-10 00:33:42 +02:00
|
|
|
}
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetStartupInfoA (KERNEL32.@)
|
2000-08-10 00:33:42 +02:00
|
|
|
*/
|
|
|
|
VOID WINAPI GetStartupInfoA( LPSTARTUPINFOA info )
|
|
|
|
{
|
2008-03-03 23:27:46 +01:00
|
|
|
*info = startup_infoA;
|
2000-08-10 00:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* GetStartupInfoW (KERNEL32.@)
|
2000-08-10 00:33:42 +02:00
|
|
|
*/
|
|
|
|
VOID WINAPI GetStartupInfoW( LPSTARTUPINFOW info )
|
|
|
|
{
|
2008-03-03 23:27:46 +01:00
|
|
|
*info = startup_infoW;
|
2003-06-18 05:23:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ENV_CopyStartupInformation (internal)
|
|
|
|
*
|
|
|
|
* Creates the STARTUPINFO information from the ntdll information
|
|
|
|
*/
|
|
|
|
void ENV_CopyStartupInformation(void)
|
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS* rupp;
|
|
|
|
ANSI_STRING ansi;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
|
|
|
rupp = NtCurrentTeb()->Peb->ProcessParameters;
|
|
|
|
|
|
|
|
startup_infoW.cb = sizeof(startup_infoW);
|
|
|
|
startup_infoW.lpReserved = NULL;
|
|
|
|
startup_infoW.lpDesktop = rupp->Desktop.Buffer;
|
|
|
|
startup_infoW.lpTitle = rupp->WindowTitle.Buffer;
|
|
|
|
startup_infoW.dwX = rupp->dwX;
|
|
|
|
startup_infoW.dwY = rupp->dwY;
|
|
|
|
startup_infoW.dwXSize = rupp->dwXSize;
|
|
|
|
startup_infoW.dwYSize = rupp->dwYSize;
|
|
|
|
startup_infoW.dwXCountChars = rupp->dwXCountChars;
|
|
|
|
startup_infoW.dwYCountChars = rupp->dwYCountChars;
|
|
|
|
startup_infoW.dwFillAttribute = rupp->dwFillAttribute;
|
|
|
|
startup_infoW.dwFlags = rupp->dwFlags;
|
|
|
|
startup_infoW.wShowWindow = rupp->wShowWindow;
|
2004-10-25 23:47:23 +02:00
|
|
|
startup_infoW.cbReserved2 = rupp->RuntimeInfo.MaximumLength;
|
|
|
|
startup_infoW.lpReserved2 = rupp->RuntimeInfo.MaximumLength ? (void*)rupp->RuntimeInfo.Buffer : NULL;
|
2003-06-18 05:23:22 +02:00
|
|
|
startup_infoW.hStdInput = rupp->hStdInput;
|
|
|
|
startup_infoW.hStdOutput = rupp->hStdOutput;
|
|
|
|
startup_infoW.hStdError = rupp->hStdError;
|
|
|
|
|
2004-10-25 23:47:23 +02:00
|
|
|
startup_infoA.cb = sizeof(startup_infoA);
|
2003-06-18 05:23:22 +02:00
|
|
|
startup_infoA.lpReserved = NULL;
|
2010-06-08 11:53:58 +02:00
|
|
|
startup_infoA.lpDesktop = RtlUnicodeStringToAnsiString( &ansi, &rupp->Desktop, TRUE ) == STATUS_SUCCESS ?
|
2003-06-18 05:23:22 +02:00
|
|
|
ansi.Buffer : NULL;
|
2010-06-08 11:53:58 +02:00
|
|
|
startup_infoA.lpTitle = RtlUnicodeStringToAnsiString( &ansi, &rupp->WindowTitle, TRUE ) == STATUS_SUCCESS ?
|
2003-06-18 05:23:22 +02:00
|
|
|
ansi.Buffer : NULL;
|
|
|
|
startup_infoA.dwX = rupp->dwX;
|
|
|
|
startup_infoA.dwY = rupp->dwY;
|
|
|
|
startup_infoA.dwXSize = rupp->dwXSize;
|
|
|
|
startup_infoA.dwYSize = rupp->dwYSize;
|
|
|
|
startup_infoA.dwXCountChars = rupp->dwXCountChars;
|
|
|
|
startup_infoA.dwYCountChars = rupp->dwYCountChars;
|
|
|
|
startup_infoA.dwFillAttribute = rupp->dwFillAttribute;
|
|
|
|
startup_infoA.dwFlags = rupp->dwFlags;
|
|
|
|
startup_infoA.wShowWindow = rupp->wShowWindow;
|
2004-10-25 23:47:23 +02:00
|
|
|
startup_infoA.cbReserved2 = rupp->RuntimeInfo.MaximumLength;
|
|
|
|
startup_infoA.lpReserved2 = rupp->RuntimeInfo.MaximumLength ? (void*)rupp->RuntimeInfo.Buffer : NULL;
|
2003-06-18 05:23:22 +02:00
|
|
|
startup_infoA.hStdInput = rupp->hStdInput;
|
|
|
|
startup_infoA.hStdOutput = rupp->hStdOutput;
|
|
|
|
startup_infoA.hStdError = rupp->hStdError;
|
|
|
|
|
|
|
|
RtlReleasePebLock();
|
2000-08-10 00:33:42 +02:00
|
|
|
}
|