sys_uname.go 595 B

1234567891011121314151617181920212223242526
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // For systems which only store the hostname in uname (Solaris).
  5. package os
  6. import "syscall"
  7. func hostname() (name string, err error) {
  8. var u syscall.Utsname
  9. if errno := syscall.Uname(&u); errno != nil {
  10. return "", NewSyscallError("uname", errno)
  11. }
  12. b := make([]byte, len(u.Nodename))
  13. i := 0
  14. for ; i < len(u.Nodename); i++ {
  15. if u.Nodename[i] == 0 {
  16. break
  17. }
  18. b[i] = byte(u.Nodename[i])
  19. }
  20. return string(b[:i]), nil
  21. }