Fixed GetComputerNameEx last error.
This commit is contained in:
parent
8a22052b61
commit
71d9a83c60
@ -394,6 +394,12 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
|||||||
int length;
|
int length;
|
||||||
char hostname[256];
|
char hostname[256];
|
||||||
|
|
||||||
|
if (!lpnSize)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (gethostname(hostname, sizeof(hostname)) == -1)
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -424,8 +430,24 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
|
|||||||
int length;
|
int length;
|
||||||
char hostname[256];
|
char hostname[256];
|
||||||
|
|
||||||
|
if (!lpnSize)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((NameType == ComputerNameNetBIOS) || (NameType == ComputerNamePhysicalNetBIOS))
|
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)
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -461,10 +483,32 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
|
|||||||
return TRUE;
|
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;
|
||||||
return FALSE;
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user