2 * Copyright 2020 Brendan Shanks for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define SECURITY_WIN32
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(whoami
);
27 static int output_write(const WCHAR
* str
, int len
)
30 if (!WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE
), str
, len
, &count
, NULL
))
35 /* On Windows WriteConsoleW() fails if the output is redirected. So fall
36 * back to WriteFile() with OEM code page.
38 lenA
= WideCharToMultiByte(GetOEMCP(), 0, str
, len
,
40 strA
= HeapAlloc(GetProcessHeap(), 0, lenA
);
44 WideCharToMultiByte(GetOEMCP(), 0, str
, len
, strA
, lenA
,
46 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE
), strA
, lenA
, &count
, FALSE
);
47 HeapFree(GetProcessHeap(), 0, strA
);
52 int __cdecl
wmain(int argc
, WCHAR
*argv
[])
62 WINE_FIXME("unsupported arguments:");
63 for (i
= 0; i
< argc
; i
++)
64 WINE_FIXME(" %s", wine_dbgstr_w(argv
[i
]));
68 result
= GetUserNameExW(NameSamCompatible
, NULL
, &size
);
69 if (result
|| GetLastError() != ERROR_MORE_DATA
)
71 WINE_ERR("GetUserNameExW failed, result %d, error %ld\n", result
, GetLastError());
75 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
78 WINE_ERR("Memory allocation failed\n");
82 result
= GetUserNameExW(NameSamCompatible
, buf
, &size
);
85 output_write(buf
, size
);
86 output_write(L
"\r\n", 2);
89 WINE_ERR("GetUserNameExW failed, error %ld\n", GetLastError());
91 HeapFree(GetProcessHeap(), 0, buf
);