Fixed GetComputerNameEx last error.

This commit is contained in:
Armin Novak 2017-02-27 10:52:59 +01:00
parent 8a22052b61
commit 71d9a83c60

View File

@ -394,6 +394,12 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
int length;
char hostname[256];
if (!lpnSize)
{
SetLastError(ERROR_BAD_ARGUMENTS);
return FALSE;
}
if (gethostname(hostname, sizeof(hostname)) == -1)
return FALSE;
@ -424,8 +430,24 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
int length;
char hostname[256];
if (!lpnSize)
{
SetLastError(ERROR_BAD_ARGUMENTS);
return FALSE;
}
if ((NameType == ComputerNameNetBIOS) || (NameType == ComputerNamePhysicalNetBIOS))
return GetComputerNameA(lpBuffer, lpnSize);
{
BOOL rc = GetComputerNameA(lpBuffer, lpnSize);
if (!rc)
{
if (GetLastError() == ERROR_BUFFER_OVERFLOW)
SetLastError(ERROR_MORE_DATA);
}
return rc;
}
if (gethostname(hostname, sizeof(hostname)) == -1)
return FALSE;
@ -461,10 +483,32 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
return TRUE;
}
BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD lpnSize)
{
WLog_ERR(TAG, "GetComputerNameExW unimplemented");
BOOL rc;
LPSTR lpABuffer = NULL;
if (!lpnSize)
{
SetLastError(ERROR_BAD_ARGUMENTS);
return FALSE;
}
if (*lpnSize > 0)
{
lpABuffer = calloc(*lpnSize, sizeof(CHAR));
if (!lpABuffer)
return FALSE;
}
rc = GetComputerNameExA(NameType, lpABuffer, lpnSize);
if (rc && (*lpnSize > 0))
ConvertToUnicode(CP_UTF8, 0, lpABuffer, *lpnSize, &lpBuffer, *lpnSize);
free(lpABuffer);
return rc;
}
#endif