os: use unsafe.{Slice,StringData} instead of unsafeheader package

Change-Id: I213b078effa4b7049c44498d651de5b938e5404b
Reviewed-on: https://go-review.googlesource.com/c/go/+/428779
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Tobias Klauser 2022-09-07 14:07:12 +02:00 committed by Gopher Robot
parent e20106ac00
commit d75e91740a

View file

@ -43,7 +43,6 @@ import (
"errors"
"internal/poll"
"internal/testlog"
"internal/unsafeheader"
"io"
"io/fs"
"runtime"
@ -247,11 +246,7 @@ func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
// WriteString is like Write, but writes the contents of string s rather than
// a slice of bytes.
func (f *File) WriteString(s string) (n int, err error) {
var b []byte
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
hdr.Data = (*unsafeheader.String)(unsafe.Pointer(&s)).Data
hdr.Cap = len(s)
hdr.Len = len(s)
b := unsafe.Slice(unsafe.StringData(s), len(s))
return f.Write(b)
}