implemented undocumented GetConsoleInputExeNameA/W() and SetConsoleInputExeNameA/W() used by NT's cmd.exe

svn path=/trunk/; revision=12177
This commit is contained in:
Thomas Bluemel 2004-12-18 13:26:57 +00:00
parent a653ae39ad
commit db7aca35ef
7 changed files with 167 additions and 52 deletions

View file

@ -1,4 +1,4 @@
/* $Id: move.c,v 1.15 2004/12/04 15:38:22 hbirr Exp $
/* $Id: move.c,v 1.16 2004/12/18 13:26:57 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -18,14 +18,6 @@
/* GLOBALS *****************************************************************/
#if defined(__GNUC__)
void * alloca(size_t size);
#elif defined(_MSC_VER)
void* _alloca(size_t size);
#else
#error Unknown compiler for alloca intrinsic stack allocation "function"
#endif
/* FUNCTIONS ****************************************************************/
static BOOL

View file

@ -36,3 +36,5 @@
#include <rosrtl/registry.h>
#include "include/kernel32.h"
#include <pseh/framebased.h>

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.85 2004/12/18 00:28:16 gdalsnes Exp $
/* $Id: console.c,v 1.86 2004/12/18 13:26:57 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -31,6 +31,7 @@ static BOOL IgnoreCtrlEvents = FALSE;
static PHANDLER_ROUTINE* CtrlHandlers = NULL;
static ULONG NrCtrlHandlers = 0;
static WCHAR InputExeName[MAX_PATH + 1] = L"";
/* Default Console Control Handler *******************************************/
@ -3412,4 +3413,160 @@ BOOL STDCALL SetConsoleIcon(HICON hicon)
return NT_SUCCESS(Status);
}
/*--------------------------------------------------------------
* SetConsoleInputExeNameW
*
* @implemented
*/
BOOL STDCALL
SetConsoleInputExeNameW(LPCWSTR lpInputExeName)
{
int lenName = lstrlenW(lpInputExeName);
if(lenName < 1 ||
lenName > (sizeof(InputExeName) / sizeof(InputExeName[0])) - 1)
{
/* Fail if string is empty or too long */
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
RtlEnterCriticalSection(&ConsoleLock);
RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR));
InputExeName[lenName] = L'\0';
RtlLeaveCriticalSection(&ConsoleLock);
return TRUE;
}
/*--------------------------------------------------------------
* SetConsoleInputExeNameA
*
* @implemented
*/
BOOL STDCALL
SetConsoleInputExeNameA(LPCSTR lpInputExeName)
{
ANSI_STRING InputExeNameA;
UNICODE_STRING InputExeNameU;
NTSTATUS Status;
BOOL Ret;
RtlInitAnsiString(&InputExeNameA, lpInputExeName);
if(InputExeNameA.Length < sizeof(InputExeNameA.Buffer[0]) ||
InputExeNameA.Length >= (sizeof(InputExeName) / sizeof(InputExeName[0])) - 1)
{
/* Fail if string is empty or too long */
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
Status = RtlAnsiStringToUnicodeString(&InputExeNameU, &InputExeNameA, TRUE);
if(NT_SUCCESS(Status))
{
Ret = SetConsoleInputExeNameW(InputExeNameU.Buffer);
RtlFreeUnicodeString(&InputExeNameU);
}
else
{
SetLastErrorByStatus(Status);
Ret = FALSE;
}
return Ret;
}
/*--------------------------------------------------------------
* GetConsoleInputExeNameW
*
* @implemented
*/
DWORD STDCALL
GetConsoleInputExeNameW(DWORD nBufferLength, LPWSTR lpBuffer)
{
int lenName;
RtlEnterCriticalSection(&ConsoleLock);
lenName = lstrlenW(InputExeName);
if(lenName >= nBufferLength)
{
/* buffer is not large enough, return the required size */
RtlLeaveCriticalSection(&ConsoleLock);
return lenName + 1;
}
/* wrap copying into SEH as we may copy to invalid buffer and in case of an
exception the console lock would've never been released, which would cause
further calls (if the exception was handled by the caller) to recursively
acquire the lock... */
_SEH_TRY
{
RtlCopyMemory(lpBuffer, InputExeName, (lenName + 1) * sizeof(WCHAR));
}
_SEH_HANDLE
{
lenName = 0;
SetLastErrorByStatus(_SEH_GetExceptionCode());
}
_SEH_END;
RtlLeaveCriticalSection(&ConsoleLock);
return lenName;
}
/*--------------------------------------------------------------
* GetConsoleInputExeNameA
*
* @implemented
*/
DWORD STDCALL
GetConsoleInputExeNameA(DWORD nBufferLength, LPSTR lpBuffer)
{
WCHAR *Buffer;
DWORD Ret;
if(nBufferLength > 0)
{
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, nBufferLength * sizeof(WCHAR));
if(Buffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
}
else
{
Buffer = NULL;
}
Ret = GetConsoleInputExeNameW(nBufferLength, Buffer);
if(nBufferLength > 0)
{
if(Ret > 0)
{
UNICODE_STRING BufferU;
ANSI_STRING BufferA;
RtlInitUnicodeString(&BufferU, Buffer);
BufferA.Length = 0;
BufferA.MaximumLength = nBufferLength;
BufferA.Buffer = lpBuffer;
RtlUnicodeStringToAnsiString(&BufferA, &BufferU, FALSE);
}
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
}
return Ret;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: ldr.c,v 1.21 2004/06/13 20:04:56 navaraf Exp $
/* $Id: ldr.c,v 1.22 2004/12/18 13:26:57 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT : ReactOS user mode libraries
@ -73,6 +73,8 @@ LoadLibraryExA (
(void)hFile;
DbgPrint("LoadLibraryExA: 0x%x (=%s) 0x%x, 0x%x\n", lpLibFileName, lpLibFileName ? lpLibFileName : "NULL", hFile, dwFlags);
RtlInitAnsiString (&LibFileName,
(LPSTR)lpLibFileName);

View file

@ -1,4 +1,4 @@
/* $Id: stubs.c,v 1.100 2004/12/09 19:11:07 weiden Exp $
/* $Id: stubs.c,v 1.101 2004/12/18 13:26:57 weiden Exp $
*
* KERNEL32.DLL stubs (STUB functions)
* Remove from this file, if you implement them.
@ -1670,24 +1670,6 @@ BOOL STDCALL SetHandleContext(HANDLE hnd,DWORD context)
return 0;
}
/*
* @unimplemented
*/
BOOL STDCALL SetConsoleInputExeNameA(LPCSTR name)
{
STUB;
return 0;
}
/*
* @unimplemented
*/
BOOL STDCALL SetConsoleInputExeNameW(LPCWSTR name)
{
STUB;
return 0;
}
/*
* @unimplemented
*/
@ -1730,24 +1712,6 @@ NTSTATUS STDCALL CreateNlsSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescri
return 0;
}
/*
* @unimplemented
*/
BOOL STDCALL GetConsoleInputExeNameA(ULONG length,LPCSTR name)
{
STUB;
return 0;
}
/*
* @unimplemented
*/
BOOL STDCALL GetConsoleInputExeNameW(ULONG length,LPCWSTR name)
{
STUB;
return 0;
}
/*
* @unimplemented
*/

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.90 2004/12/13 13:32:24 navaraf Exp $
/* $Id: create.c,v 1.91 2004/12/18 13:26:57 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -12,7 +12,6 @@
/* INCLUDES ****************************************************************/
#include <k32.h>
#include <pseh/framebased.h>
#define NDEBUG
#include "../include/debug.h"

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.59 2004/12/13 13:32:24 navaraf Exp $
/* $Id: thread.c,v 1.60 2004/12/18 13:26:57 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -14,7 +14,6 @@
/* INCLUDES ******************************************************************/
#include <k32.h>
#include <pseh/framebased.h>
#define NDEBUG
#include "../include/debug.h"