2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
36 /******************************************************************************
37 * GetUserNameA [ADVAPI32.@]
39 * NOTE: lpSize returns the total length of the username, including the
40 * terminating null character.
43 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
48 struct passwd *pwd = getpwuid( getuid() );
51 ERR("Username lookup failed: %s\n", strerror(errno));
57 /* We need to include the null character when determining the size of the buffer. */
58 len = strlen(name) + 1;
61 SetLastError(ERROR_MORE_DATA);
67 strcpy(lpszName, name);
71 /******************************************************************************
72 * GetUserNameW [ADVAPI32.@]
79 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
81 LPSTR name = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *lpSize );
83 BOOL res = GetUserNameA(name,lpSize);
85 /* FIXME: should set lpSize in WCHARs */
86 if (size && !MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, size ))
88 HeapFree( GetProcessHeap(), 0, name );