[WHOAMI]: Use the conutils (stream) library for console output (see also r65894).

CORE-8965 CORE-10504

svn path=/trunk/; revision=73111
This commit is contained in:
Hermès Bélusca-Maïto 2016-11-03 16:30:48 +00:00
parent 79c7b07668
commit cfbf8660bc
2 changed files with 12 additions and 60 deletions

View file

@ -1,5 +1,8 @@
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
add_executable(whoami whoami.c whoami.rc)
set_module_type(whoami win32cui UNICODE)
target_link_libraries(whoami conutils ${PSEH_LIB})
add_importlibs(whoami user32 secur32 advapi32 msvcrt kernel32)
add_cd_file(TARGET whoami DESTINATION reactos/system32 FOR all)

View file

@ -6,69 +6,16 @@
* PROGRAMMERS: Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
*/
#define SECURITY_WIN32
#include <security.h>
#include <sddl.h>
#include <strsafe.h>
#include <conutils.h>
#include "resource.h"
/* Unicode (W) to ANSI OEM wrapper function, as console and Unicode don't mix well, sigh */
static void WhoamiOemConversion_printf(const WCHAR *lpSourceFormatW, ...)
{
CHAR *lpBufferA = NULL;
WCHAR *lpBufferW = NULL;
UINT Size;
va_list Args;
/* first let's find out the final output'ed length of the wprintf routine */
va_start(Args, lpSourceFormatW);
Size = _vscwprintf(lpSourceFormatW, Args);
va_end(Args);
/* allocate a proportional memory chunk taking into account the char width */
lpBufferW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (Size + 1) * sizeof(WCHAR));
if (!lpBufferW)
return;
/* do wprintf to this newly allocated buffer of ours */
va_start(Args, lpSourceFormatW);
_vsnwprintf(lpBufferW, Size, lpSourceFormatW, Args);
va_end(Args);
/* allocate a similarly sized buffer for the ANSI/OEM version of our string */
lpBufferA = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (Size + 1) * sizeof(CHAR));
if (!lpBufferA)
{
HeapFree(GetProcessHeap(), 0, lpBufferW);
return;
}
/* convert our Unicode/Wide char string into a proper ANSI/OEM
string that our console may understand, at least in theory */
CharToOemBuffW(lpBufferW,
lpBufferA,
Size);
/* print the converted OEM string into the console's output and call it a day */
printf("%s", lpBufferA);
/* clean everything up */
HeapFree(GetProcessHeap(), 0, lpBufferW);
HeapFree(GetProcessHeap(), 0, lpBufferA);
}
#define wprintf WhoamiOemConversion_printf
#define wprintf(...) ConPrintf(StdOut, ##__VA_ARGS__)
BOOL NoHeader = FALSE;
UINT NoHeaderArgCount = 0;
@ -194,7 +141,6 @@ void WhoamiPrintHeader(int HeaderId)
while (Length--)
wprintf(L"-");
/* _putws seems to be broken in ReactOS' CRT ??? */
wprintf(L"\n\n");
}
@ -718,13 +664,16 @@ int WhoamiPriv(void)
int wmain(int argc, WCHAR* argv[])
{
INT i;
BYTE WamBit = 0;
#define WAM_USER 1<<0
#define WAM_GROUPS 1<<1
#define WAM_PRIV 1<<2
INT i;
BYTE WamBit = 0;
/* Initialize the Console Standard Streams */
ConInitStdStreams();
/* * * * * * * * * * * * * * * *
* A: no parameters whatsoever */