syscall: simplify code using unsafe.Slice

Updates #54854

Change-Id: Ibaf4eea14a6259cdbca79e9e95db1602966f18e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/428176
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
cuiweixie 2022-09-03 18:18:30 +08:00 committed by Gopher Robot
parent 4fe4601d37
commit ba1ef54c1e

View file

@ -310,12 +310,7 @@ func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
break
}
// Copy entry into return buffer.
s := struct {
ptr unsafe.Pointer
siz int
cap int
}{ptr: unsafe.Pointer(&entry), siz: reclen, cap: reclen}
copy(buf, *(*[]byte)(unsafe.Pointer(&s)))
copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen))
buf = buf[reclen:]
n += reclen
cnt++