* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PURPOSE: Computer name functions
- * FILE: lib/kernel32/misc/computername.c
+ * FILE: dll/win32/kernel32/client/compname.c
* PROGRAMER: Eric Kohl
*/
ULONG ReturnSize;
NTSTATUS Status;
+ if (lpBuffer != NULL && *nSize > 0)
+ lpBuffer[0] = 0;
+
RtlInitUnicodeString(&KeyName, RegistryKey);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
if (!NT_SUCCESS(Status))
{
- *nSize = ReturnSize;
+ *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
goto failed;
}
if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
{
- *nSize = ReturnSize;
+ *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
Status = STATUS_BUFFER_OVERFLOW;
goto failed;
}
BOOL ret = TRUE;
DWORD HostSize;
+ if ((nSize == NULL) ||
+ (lpBuffer == NULL && *nSize > 0))
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
switch (NameType)
{
case ComputerNameNetBIOS:
UNICODE_STRING UnicodeString;
ANSI_STRING AnsiString;
BOOL Result;
- PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
+ PWCHAR TempBuffer = NULL;
- if (!TempBuffer)
+ if ((nSize == NULL) ||
+ (lpBuffer == NULL && *nSize > 0))
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
+ if (*nSize > 0)
+ {
+ TempBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR));
+ if (!TempBuffer)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+ }
+
AnsiString.MaximumLength = (USHORT)*nSize;
AnsiString.Length = 0;
AnsiString.Buffer = lpBuffer;
if (Result)
{
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
- UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
+ UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR);
UnicodeString.Buffer = TempBuffer;
RtlUnicodeStringToAnsiString(&AnsiString,
GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
{
BOOL ret;
+
ret = GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
- if(!ret && GetLastError() == ERROR_MORE_DATA)
- SetLastError(ERROR_BUFFER_OVERFLOW);
- return ret;
+ if (!ret && GetLastError() == ERROR_MORE_DATA)
+ SetLastError(ERROR_BUFFER_OVERFLOW);
+
+ return ret;
}