Changed the country's name to "IL" to conform to commonly held
[wine] / dlls / advapi32 / advapi.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <pwd.h>
29
30 #include "winbase.h"
31 #include "windef.h"
32 #include "winnls.h"
33 #include "winerror.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
38
39 /******************************************************************************
40  * GetUserNameA [ADVAPI32.@]
41  *
42  * NOTE: lpSize returns the total length of the username, including the
43  * terminating null character.
44  */
45 BOOL WINAPI
46 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
47 {
48   size_t len;
49   char *name;
50
51   struct passwd *pwd = getpwuid( getuid() );
52   if (!pwd)
53   {
54     ERR("Username lookup failed: %s\n", strerror(errno));
55     return 0;
56   }
57
58   name = pwd->pw_name;
59
60   /* We need to include the null character when determining the size of the buffer. */
61   len = strlen(name) + 1;
62   if (len > *lpSize)
63   {
64     SetLastError(ERROR_MORE_DATA);
65     *lpSize = len;
66     return 0;
67   }
68
69   *lpSize = len;
70   strcpy(lpszName, name);
71   return 1;
72 }
73
74 /******************************************************************************
75  * GetUserNameW [ADVAPI32.@]
76  *
77  * PARAMS
78  *   lpszName []
79  *   lpSize   []
80  */
81 BOOL WINAPI
82 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
83 {
84         LPSTR name = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *lpSize );
85         DWORD   size = *lpSize;
86         BOOL res = GetUserNameA(name,lpSize);
87
88         /* FIXME: should set lpSize in WCHARs */
89         if (size && !MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, size ))
90             lpszName[size-1] = 0;
91         HeapFree( GetProcessHeap(), 0, name );
92         return res;
93 }
94
95 /******************************************************************************
96  * AbortSystemShutdownA [ADVAPI32.@]
97  *
98  * PARAMS
99  *      lpMachineName
100  */
101 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
102 {
103     TRACE("stub %s (harmless)\n", lpMachineName);
104     return TRUE;
105 }
106
107 /******************************************************************************
108  * AbortSystemShutdownW [ADVAPI32.@]
109  *
110  * PARAMS
111  *      lpMachineName
112  */
113 BOOL WINAPI AbortSystemShutdownW( LPCWSTR lpMachineName )
114 {
115     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
116     return TRUE;
117 }