all: simplify unsafe.Slice usage in {Byte,UTF16}PtrToString

On windows, use unsafe.Slice instead of unsafeheader as already the case
for unix and plan9.

The pointers are already *byte/*uint16, so the type conversion can be
omitted as well.

Change-Id: Ida7264cc0c1948bf563ed91d51e637edcdafb77a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/430515
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
diff --git a/plan9/syscall.go b/plan9/syscall.go
index ea97128..67e5b01 100644
--- a/plan9/syscall.go
+++ b/plan9/syscall.go
@@ -80,8 +80,7 @@
 		ptr = unsafe.Pointer(uintptr(ptr) + 1)
 	}
 
-	s := unsafe.Slice((*byte)(unsafe.Pointer(p)), n)
-	return string(s)
+	return string(unsafe.Slice(p, n))
 }
 
 // Single-word zero for use when we need a valid pointer to 0 bytes.
diff --git a/unix/syscall.go b/unix/syscall.go
index 9916e5e..63e8c83 100644
--- a/unix/syscall.go
+++ b/unix/syscall.go
@@ -80,8 +80,7 @@
 		ptr = unsafe.Pointer(uintptr(ptr) + 1)
 	}
 
-	s := unsafe.Slice((*byte)(unsafe.Pointer(p)), n)
-	return string(s)
+	return string(unsafe.Slice(p, n))
 }
 
 // Single-word zero for use when we need a valid pointer to 0 bytes.
diff --git a/windows/syscall.go b/windows/syscall.go
index 72074d5..8732cdb 100644
--- a/windows/syscall.go
+++ b/windows/syscall.go
@@ -30,8 +30,6 @@
 	"strings"
 	"syscall"
 	"unsafe"
-
-	"golang.org/x/sys/internal/unsafeheader"
 )
 
 // ByteSliceFromString returns a NUL-terminated slice of bytes
@@ -83,13 +81,7 @@
 		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
-
-	return string(s)
+	return string(unsafe.Slice(p, n))
 }
 
 // Single-word zero for use when we need a valid pointer to 0 bytes.
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index 996cc53..29737b2 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -138,13 +138,7 @@
 		ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*p))
 	}
 
-	var s []uint16
-	h := (*unsafeheader.Slice)(unsafe.Pointer(&s))
-	h.Data = unsafe.Pointer(p)
-	h.Len = n
-	h.Cap = n
-
-	return string(utf16.Decode(s))
+	return string(utf16.Decode(unsafe.Slice(p, n)))
 }
 
 func Getpagesize() int { return 4096 }