sys_plan9.go 473 B

123456789101112131415161718192021222324252627
  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. // Plan 9-specific
  5. package os
  6. func hostname() (name string, err error) {
  7. f, err := Open("#c/sysname")
  8. if err != nil {
  9. return "", err
  10. }
  11. defer f.Close()
  12. var buf [128]byte
  13. n, err := f.Read(buf[:len(buf)-1])
  14. if err != nil {
  15. return "", err
  16. }
  17. if n > 0 {
  18. buf[n] = 0
  19. }
  20. return string(buf[0:n]), nil
  21. }