mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 07:07:33 -04:00
unix: 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: Ie5f1fad01f219e7b7a190de2c49676f366ad3bc7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/428515 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Benny Siegert <bsiegert@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
committed by
Benny Siegert
parent
27713097b9
commit
aba9fc2a8f
+1
-8
@@ -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