diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2022-08-09 10:15:27 +0200 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-08-18 16:15:06 +0000 |
commit | c7c78f1a3a4c94043c140962f2916a69e466d255 (patch) | |
tree | 609ff40d3674fddc73ef27ee8257af61a06c6b17 /src/cmd/internal/osinfo/os_unix.go | |
parent | 760c180d3bb2464b1e91402630c8f0d1e79180b3 (diff) | |
download | go-c7c78f1a3a4c94043c140962f2916a69e466d255.tar.gz go-c7c78f1a3a4c94043c140962f2916a69e466d255.zip |
cmd/internal/osinfo: use unix.ByteSliceToString
The golang.org/x/sys/unix package is already imported for Utsname and
Uname. Use ByteSliceToString from that package as well to replace the
locally defined utsString helper which serves the same purpose and
matches ByteSliceToString's implementation.
Change-Id: I5d9de186a5aeb1feed1387beedefbcd260fe22ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/415654
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/cmd/internal/osinfo/os_unix.go')
-rw-r--r-- | src/cmd/internal/osinfo/os_unix.go | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/cmd/internal/osinfo/os_unix.go b/src/cmd/internal/osinfo/os_unix.go index fab9e08f82..b989f0afb4 100644 --- a/src/cmd/internal/osinfo/os_unix.go +++ b/src/cmd/internal/osinfo/os_unix.go @@ -6,19 +6,7 @@ package osinfo -import ( - "bytes" - - "golang.org/x/sys/unix" -) - -func utsString(b []byte) string { - i := bytes.IndexByte(b, 0) - if i == -1 { - return string(b) - } - return string(b[:i]) -} +import "golang.org/x/sys/unix" // Version returns the OS version name/number. func Version() (string, error) { @@ -27,10 +15,10 @@ func Version() (string, error) { return "", err } - sysname := utsString(uts.Sysname[:]) - release := utsString(uts.Release[:]) - version := utsString(uts.Version[:]) - machine := utsString(uts.Machine[:]) + sysname := unix.ByteSliceToString(uts.Sysname[:]) + release := unix.ByteSliceToString(uts.Release[:]) + version := unix.ByteSliceToString(uts.Version[:]) + machine := unix.ByteSliceToString(uts.Machine[:]) return sysname + " " + release + " " + version + " " + machine, nil } |