2011-01-28 02:44:55 +01:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// For systems which only store the hostname in uname (Solaris).
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
|
|
|
import "syscall"
|
|
|
|
|
2011-12-06 19:13:04 +01:00
|
|
|
func Hostname() (name string, err error) {
|
2011-01-28 02:44:55 +01:00
|
|
|
var u syscall.Utsname
|
2011-12-13 20:18:34 +01:00
|
|
|
if errno := syscall.Uname(&u); errno != nil {
|
2011-01-28 02:44:55 +01:00
|
|
|
return "", NewSyscallError("uname", errno)
|
|
|
|
}
|
|
|
|
b := make([]byte, len(u.Nodename))
|
|
|
|
i := 0
|
|
|
|
for ; i < len(u.Nodename); i++ {
|
|
|
|
if u.Nodename[i] == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
b[i] = byte(u.Nodename[i])
|
|
|
|
}
|
|
|
|
return string(b[:i]), nil
|
|
|
|
}
|