1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: use GetComputerNameW to retrieve hostname on Windows (#9861)

This commit is contained in:
Marcos Diaz
2021-04-24 12:22:04 +02:00
committed by GitHub
parent dee4904bee
commit 187895c93c
2 changed files with 9 additions and 2 deletions

View File

@@ -390,8 +390,13 @@ pub fn uname() Uname {
}
pub fn hostname() string {
// TODO: use C.GetComputerName(&u16, u32) int instead
return execute('cmd /c hostname').output
hostname := [255]u16{}
size := u32(255)
res := C.GetComputerNameW(&hostname[0], &size)
if !res {
return error(get_error_msg(int(C.GetLastError())))
}
return unsafe { string_from_wide(&hostname[0]) }
}
pub fn loginname() string {