Skip to content

Commit

Permalink
host: use unix.ByteSliceToString
Browse files Browse the repository at this point in the history
Use ByteSliceToString provided in golang.org/x/sys/unix to convert
\0-terminated byte slices to strings.
  • Loading branch information
tklauser committed Dec 7, 2022
1 parent 3b918eb commit f9a5834
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion host/host_linux.go
Expand Up @@ -319,7 +319,7 @@ func KernelVersionWithContext(ctx context.Context) (version string, err error) {
if err != nil {
return "", err
}
return string(utsname.Release[:bytes.IndexByte(utsname.Release[:], 0)]), nil
return unix.ByteSliceToString(utsname.Release[:]), nil
}

func getSlackwareVersion(contents []string) string {
Expand Down
11 changes: 5 additions & 6 deletions host/host_posix.go
Expand Up @@ -3,14 +3,13 @@

package host

import (
"bytes"

"golang.org/x/sys/unix"
)
import "golang.org/x/sys/unix"

func KernelArch() (string, error) {
var utsname unix.Utsname
err := unix.Uname(&utsname)
return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), err
if err != nil {
return "", err
}
return unix.ByteSliceToString(utsname.Machine[:]), nil
}

0 comments on commit f9a5834

Please sign in to comment.