Implement ResetDC and PHYSICALOFFSET[X|Y] devcaps.
[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 <errno.h>
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <pwd.h>
26
27 #include "winbase.h"
28 #include "windef.h"
29 #include "winnls.h"
30 #include "winerror.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
35
36 /******************************************************************************
37  * GetUserNameA [ADVAPI32.@]
38  *
39  * NOTE: lpSize returns the total length of the username, including the
40  * terminating null character.
41  */
42 BOOL WINAPI
43 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
44 {
45   size_t len;
46   char *name;
47
48   struct passwd *pwd = getpwuid( getuid() );
49   if (!pwd)
50   {
51     ERR("Username lookup failed: %s\n", strerror(errno));
52     return 0;
53   }
54
55   name = pwd->pw_name;
56
57   /* We need to include the null character when determining the size of the buffer. */
58   len = strlen(name) + 1;
59   if (len > *lpSize)
60   {
61     SetLastError(ERROR_MORE_DATA);
62     *lpSize = len;
63     return 0;
64   }
65
66   *lpSize = len;
67   strcpy(lpszName, name);
68   return 1;
69 }
70
71 /******************************************************************************
72  * GetUserNameW [ADVAPI32.@]
73  *
74  * PARAMS
75  *   lpszName []
76  *   lpSize   []
77  */
78 BOOL WINAPI
79 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
80 {
81         LPSTR name = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *lpSize );
82         DWORD   size = *lpSize;
83         BOOL res = GetUserNameA(name,lpSize);
84
85         /* FIXME: should set lpSize in WCHARs */
86         if (size && !MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, size ))
87             lpszName[size-1] = 0;
88         HeapFree( GetProcessHeap(), 0, name );
89         return res;
90 }