mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
util: Introduce qemu_get_host_name()
This function offers operating system agnostic way to fetch host name. It is implemented for both POSIX-like and Windows systems. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
844bd70b56
commit
e47f4765af
3 changed files with 58 additions and 0 deletions
|
@ -808,3 +808,16 @@ bool qemu_write_pidfile(const char *filename, Error **errp)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
char *qemu_get_host_name(Error **errp)
|
||||
{
|
||||
wchar_t tmp[MAX_COMPUTERNAME_LENGTH + 1];
|
||||
DWORD size = G_N_ELEMENTS(tmp);
|
||||
|
||||
if (GetComputerNameW(tmp, &size) == 0) {
|
||||
error_setg_win32(errp, GetLastError(), "failed close handle");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue