github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/os/sys_plan9.go (about)

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