Fix return value of GetWindowsDirectoryA/W and GetSystemDirectoryA/W.
[wine/wine-kai.git] / dlls / advapi32 / advapi.c
blob7f9e99dd3ca7d3d34a8a54a495bc0b7b8703807d
1 /*
2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
5 */
7 #include <errno.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <pwd.h>
13 #include "winbase.h"
14 #include "windef.h"
15 #include "winnls.h"
16 #include "winerror.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(advapi);
22 /******************************************************************************
23 * GetUserNameA [ADVAPI32.@]
25 * NOTE: lpSize returns the total length of the username, including the
26 * terminating null character.
28 BOOL WINAPI
29 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
31 size_t len;
32 char *name;
34 struct passwd *pwd = getpwuid( getuid() );
35 if (!pwd)
37 ERR("Username lookup failed: %s\n", strerror(errno));
38 return 0;
41 name = pwd->pw_name;
43 /* We need to include the null character when determining the size of the buffer. */
44 len = strlen(name) + 1;
45 if (len > *lpSize)
47 SetLastError(ERROR_MORE_DATA);
48 *lpSize = len;
49 return 0;
52 *lpSize = len;
53 strcpy(lpszName, name);
54 return 1;
57 /******************************************************************************
58 * GetUserNameW [ADVAPI32.@]
60 * PARAMS
61 * lpszName []
62 * lpSize []
64 BOOL WINAPI
65 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
67 LPSTR name = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *lpSize );
68 DWORD size = *lpSize;
69 BOOL res = GetUserNameA(name,lpSize);
71 /* FIXME: should set lpSize in WCHARs */
72 if (size && !MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, size ))
73 lpszName[size-1] = 0;
74 HeapFree( GetProcessHeap(), 0, name );
75 return res;