Source file
src/os/sys_windows.go
1
2
3
4
5 package os
6
7 import (
8 "internal/syscall/windows"
9 "syscall"
10 )
11
12 func hostname() (name string, err error) {
13
14 const format = windows.ComputerNamePhysicalDnsHostname
15
16 n := uint32(64)
17 for {
18 b := make([]uint16, n)
19 err := windows.GetComputerNameEx(format, &b[0], &n)
20 if err == nil {
21 return syscall.UTF16ToString(b[:n]), nil
22 }
23 if err != syscall.ERROR_MORE_DATA {
24 return "", NewSyscallError("ComputerNameEx", err)
25 }
26
27
28
29 if n <= uint32(len(b)) {
30 return "", NewSyscallError("ComputerNameEx", err)
31 }
32 }
33 }
34
View as plain text