Skip to content

x/sys/unix: Utsname is using [65]int8 for all its struct members #20753

@mvo5

Description

@mvo5

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mvo/devel/go"
GORACE=""
GOROOT="/usr/lib/go-1.7"
GOTOOLDIR="/usr/lib/go-1.7/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build701945664=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I want to get information from unix.Uname() - this works fine, however the fact that Utsname has all members as int8 is making working with the result a bit cumbersome. It would be simpler if this would be a [65]byte instead because than the bytes package can be used on it. Unless I miss something the only ways to convert this are:

package main

import (
	"bytes"
	"golang.org/x/sys/unix"
	"unsafe"
)

func main() {
	var utsname unix.Utsname
	unix.Uname(&utsname)

	// convert using unsafe.Pointer()
        p := (*[len(utsname.Machine)]byte)(unsafe.Pointer(&utsname.Machine))
	println(string(p[:]))
	
	// iterate and convert
	buf := make([]byte, 0, len(utsname.Machine))
	for _, i := range utsname.Machine {
		buf = append(buf, byte(i))
	}
	println(string(buf))
}

What did you expect to see?

Ideally a simple println(string(utsname.Machine[:])) would be enough to convert it to a string without the need for the unsafe.Pointer() casting.

I am happy to work on a PR if there is a chance for this to get accepted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions