// Copyright 2009 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.

package os

import (
	
	
)

func hostname() ( string,  error) {
	// Try uname first, as it's only one system call and reading
	// from /proc is not allowed on Android.
	var  syscall.Utsname
	 = syscall.Uname(&)

	var  [512]byte // Enough for a DNS name.
	for ,  := range .Nodename[:] {
		[] = uint8()
		if  == 0 {
			 = string([:])
			break
		}
	}
	// If we got a name and it's not potentially truncated
	// (Nodename is 65 bytes), return it.
	if  == nil && len() > 0 && len() < 64 {
		return , nil
	}
	if runtime.GOOS == "android" {
		if  != "" {
			return , nil
		}
		return "localhost", nil
	}

	,  := Open("/proc/sys/kernel/hostname")
	if  != nil {
		return "", 
	}
	defer .Close()

	,  := .Read([:])
	if  != nil {
		return "", 
	}

	if  > 0 && [-1] == '\n' {
		--
	}
	return string([:]), nil
}