mfplat: Implement GetContiguousLength() for d3d11 buffer.
[wine/zf.git] / dlls / kernel32 / computername.c
blob7c2003664e8cd879bcf558aa62520e06c31639ed
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1999 Peter Ganten
6 * Copyright 2002 Martin Wilck
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <string.h>
25 #include <stdlib.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winnls.h"
33 #include "winternl.h"
34 #include "wine/exception.h"
36 #include "kernel_private.h"
39 /***********************************************************************
40 * GetComputerNameW (KERNEL32.@)
42 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
44 BOOL ret = GetComputerNameExW( ComputerNameNetBIOS, name, size );
45 if (!ret && GetLastError() == ERROR_MORE_DATA) SetLastError( ERROR_BUFFER_OVERFLOW );
46 return ret;
49 /***********************************************************************
50 * GetComputerNameA (KERNEL32.@)
52 BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
54 WCHAR nameW[ MAX_COMPUTERNAME_LENGTH + 1 ];
55 DWORD sizeW = MAX_COMPUTERNAME_LENGTH + 1;
56 unsigned int len;
57 BOOL ret;
59 if ( !GetComputerNameW (nameW, &sizeW) ) return FALSE;
61 len = WideCharToMultiByte ( CP_ACP, 0, nameW, -1, NULL, 0, NULL, 0 );
62 /* for compatibility with Win9x */
63 __TRY
65 if ( *size < len )
67 *size = len;
68 SetLastError( ERROR_BUFFER_OVERFLOW );
69 ret = FALSE;
71 else
73 WideCharToMultiByte ( CP_ACP, 0, nameW, -1, name, len, NULL, 0 );
74 *size = len - 1;
75 ret = TRUE;
78 __EXCEPT_PAGE_FAULT
80 SetLastError( ERROR_INVALID_PARAMETER );
81 ret = FALSE;
83 __ENDTRY
85 return ret;
88 /***********************************************************************
89 * DnsHostnameToComputerNameA (KERNEL32.@)
91 BOOL WINAPI DnsHostnameToComputerNameA(LPCSTR hostname,
92 LPSTR computername, LPDWORD size)
94 WCHAR *hostW, nameW[MAX_COMPUTERNAME_LENGTH + 1];
95 DWORD len;
96 BOOL ret;
98 if (!hostname || !size) return FALSE;
99 len = MultiByteToWideChar( CP_ACP, 0, hostname, -1, NULL, 0 );
100 if (!(hostW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
101 MultiByteToWideChar( CP_ACP, 0, hostname, -1, hostW, len );
102 len = ARRAY_SIZE(nameW);
103 if ((ret = DnsHostnameToComputerNameW( hostW, nameW, &len )))
105 if (!computername || !WideCharToMultiByte( CP_ACP, 0, nameW, -1, computername, *size, NULL, NULL ))
106 *size = WideCharToMultiByte( CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL );
107 else
108 *size = strlen(computername);
110 HeapFree( GetProcessHeap(), 0, hostW );
111 return TRUE;
114 /***********************************************************************
115 * DnsHostnameToComputerNameW (KERNEL32.@)
117 BOOL WINAPI DnsHostnameToComputerNameW(LPCWSTR hostname,
118 LPWSTR computername, LPDWORD size)
120 return DnsHostnameToComputerNameExW( hostname, computername, size );