blob: 07a7905f4721fd4133e77c9e837eddf38ed0634f [file] [log] [blame]
Yuval Pavel Zholkoverc256f0a2011-04-02 14:28:58 -07001// 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// Plan 9-specific
6
7package os
8
Alex Brainman994e0642012-01-17 16:51:54 +11009func hostname() (name string, err error) {
Rob Pike8a90fd32011-04-04 23:42:14 -070010 f, err := Open("#c/sysname")
Yuval Pavel Zholkoverc256f0a2011-04-02 14:28:58 -070011 if err != nil {
12 return "", err
13 }
14 defer f.Close()
15
16 var buf [128]byte
17 n, err := f.Read(buf[:len(buf)-1])
18
19 if err != nil {
20 return "", err
21 }
22 if n > 0 {
23 buf[n] = 0
24 }
25 return string(buf[0:n]), nil
26}