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
28 #define WIN32_NO_STATUS
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
);
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;
59 if ( !GetComputerNameW (nameW
, &sizeW
) ) return FALSE
;
61 len
= WideCharToMultiByte ( CP_ACP
, 0, nameW
, -1, NULL
, 0, NULL
, 0 );
62 /* for compatibility with Win9x */
68 SetLastError( ERROR_BUFFER_OVERFLOW
);
73 WideCharToMultiByte ( CP_ACP
, 0, nameW
, -1, name
, len
, NULL
, 0 );
80 SetLastError( ERROR_INVALID_PARAMETER
);
88 /***********************************************************************
89 * DnsHostnameToComputerNameA (KERNEL32.@)
91 BOOL WINAPI
DnsHostnameToComputerNameA(LPCSTR hostname
,
92 LPSTR computername
, LPDWORD size
)
94 WCHAR
*hostW
, nameW
[MAX_COMPUTERNAME_LENGTH
+ 1];
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
);
108 *size
= strlen(computername
);
110 HeapFree( GetProcessHeap(), 0, hostW
);
114 /***********************************************************************
115 * DnsHostnameToComputerNameW (KERNEL32.@)
117 BOOL WINAPI
DnsHostnameToComputerNameW(LPCWSTR hostname
,
118 LPWSTR computername
, LPDWORD size
)
120 return DnsHostnameToComputerNameExW( hostname
, computername
, size
);