Fixed up Get/SetConsoleTitleAW().

svn path=/trunk/; revision=4225
This commit is contained in:
Marty Dill 2003-03-02 01:23:19 +00:00
parent cb819643dd
commit 20a78cdf13

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.52 2003/02/24 23:24:55 hbirr Exp $ /* $Id: console.c,v 1.53 2003/03/02 01:23:19 mdill Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -2144,7 +2144,6 @@ GenerateConsoleCtrlEvent(
/*-------------------------------------------------------------- /*--------------------------------------------------------------
* GetConsoleTitleW * GetConsoleTitleW
*/ */
#define MAX_CONSOLE_TITLE_LENGTH 80
WINBASEAPI WINBASEAPI
DWORD DWORD
@ -2154,60 +2153,43 @@ GetConsoleTitleW(
DWORD nSize DWORD nSize
) )
{ {
union { CSRSS_API_REQUEST Request;
CSRSS_API_REQUEST quest; PCSRSS_API_REPLY Reply;
CSRSS_API_REPLY ply; NTSTATUS Status;
} Re;
NTSTATUS Status;
/* Marshall data */ Reply = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
Re.quest.Type = CSRSS_GET_TITLE;
Re.quest.Data.GetTitleRequest.ConsoleHandle =
GetStdHandle (STD_INPUT_HANDLE);
/* Call CSRSS */ if(Reply == NULL)
Status = CsrClientCallServer ( {
& Re.quest, SetLastError(ERROR_OUTOFMEMORY);
& Re.ply, return 0;
(sizeof (CSRSS_GET_TITLE_REQUEST) + }
sizeof (LPC_MESSAGE) +
sizeof (ULONG)),
sizeof (CSRSS_API_REPLY)
);
if ( !NT_SUCCESS(Status)
|| !NT_SUCCESS (Status = Re.ply.Status)
)
{
SetLastErrorByStatus (Status);
return (0);
}
/* Convert size in characters to size in bytes */ Request.Type = CSRSS_GET_TITLE;
nSize = sizeof (WCHAR) * nSize; Request.Data.GetTitleRequest.ConsoleHandle = GetStdHandle(STD_INPUT_HANDLE);
/* Unmarshall data */ Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
if (nSize < Re.ply.Data.GetTitleReply.Length) if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Reply->Status)))
{ {
DbgPrint ("%s: ret=%d\n", __FUNCTION__, Re.ply.Data.GetTitleReply.Length); SetLastErrorByStatus(Status);
nSize /= sizeof (WCHAR); RtlFreeHeap(GetProcessHeap(), 0, Reply);
if (nSize > 1) return 0;
{ }
wcsncpy (
lpConsoleTitle,
Re.ply.Data.GetTitleReply.Title,
(nSize - 1)
);
/* Add null */
lpConsoleTitle [nSize --] = L'\0';
}
}
else
{
nSize = Re.ply.Data.GetTitleReply.Length / sizeof (WCHAR);
wcscpy (lpConsoleTitle, Re.ply.Data.GetTitleReply.Title);
}
return nSize; if(nSize * sizeof(WCHAR) < Reply->Data.GetTitleReply.Length)
{
wcsncpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title, nSize - 1);
lpConsoleTitle[nSize--] = L'\0';
}
else
{
nSize = Reply->Data.GetTitleReply.Length / sizeof (WCHAR);
wcscpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title);
lpConsoleTitle[nSize] = L'\0';
}
RtlFreeHeap(GetProcessHeap(), 0, Reply);
return nSize;
} }
@ -2224,14 +2206,14 @@ GetConsoleTitleA(
DWORD nSize DWORD nSize
) )
{ {
wchar_t WideTitle [MAX_CONSOLE_TITLE_LENGTH]; wchar_t WideTitle [CSRSS_MAX_TITLE_LENGTH];
DWORD nWideTitle = sizeof WideTitle; DWORD nWideTitle = sizeof WideTitle;
// DWORD nWritten; DWORD nWritten;
if (!lpConsoleTitle || !nSize) return 0; if (!lpConsoleTitle || !nSize) return 0;
nWideTitle = GetConsoleTitleW( (LPWSTR) WideTitle, nWideTitle ); nWideTitle = GetConsoleTitleW( (LPWSTR) WideTitle, nWideTitle );
if (!nWideTitle) return 0; if (!nWideTitle) return 0;
#if 0
if ( (nWritten = WideCharToMultiByte( if ( (nWritten = WideCharToMultiByte(
CP_ACP, // ANSI code page CP_ACP, // ANSI code page
0, // performance and mapping flags 0, // performance and mapping flags
@ -2246,7 +2228,7 @@ GetConsoleTitleA(
lpConsoleTitle[nWritten] = '\0'; lpConsoleTitle[nWritten] = '\0';
return nWritten; return nWritten;
} }
#endif
return 0; return 0;
} }
@ -2285,10 +2267,8 @@ SetConsoleTitleW(
Request->Data.SetTitleRequest.Length = c; Request->Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(Request,
&Reply, &Reply,
sizeof(CSRSS_SET_TITLE_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c + c * sizeof(WCHAR),
sizeof( LPC_MESSAGE ) +
sizeof( ULONG ),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
@ -2338,10 +2318,8 @@ SetConsoleTitleA(
Request->Data.SetTitleRequest.Length = c; Request->Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(Request,
&Reply, &Reply,
sizeof(CSRSS_SET_TITLE_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c + c * sizeof(WCHAR),
sizeof( LPC_MESSAGE ) +
sizeof( ULONG ),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )