mirror of
https://github.com/golang/sys.git
synced 2026-01-29 15:12:09 +03:00
plan9: use unsafe.Slice instead of unsafeheader package
Go 1.18 is the minimum supported Go version and unsafe.Slice was introduced in Go 1.17. Change-Id: I696dba9b932c522688ee55fdef43d8776f8afbe1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/428516 Reviewed-by: Benny Siegert <bsiegert@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
committed by
Benny Siegert
parent
d0df966e69
commit
87db552b00
@@ -29,8 +29,6 @@ import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/internal/unsafeheader"
|
||||
)
|
||||
|
||||
// ByteSliceFromString returns a NUL-terminated slice of bytes
|
||||
@@ -82,12 +80,7 @@ func BytePtrToString(p *byte) string {
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 1)
|
||||
}
|
||||
|
||||
var s []byte
|
||||
h := (*unsafeheader.Slice)(unsafe.Pointer(&s))
|
||||
h.Data = unsafe.Pointer(p)
|
||||
h.Len = n
|
||||
h.Cap = n
|
||||
|
||||
s := unsafe.Slice((*byte)(unsafe.Pointer(p)), n)
|
||||
return string(s)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user