mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 08:37:31 -04:00
unix: fix Getdirentries emulation using Getdents on netbsd, openbsd
Call Seek if basep is not nil to read the current dir offset. Return EIO error if the offset doesn't fit into a 32-bit uintptr. Make Getdents public. Update golang/go#32498 Change-Id: Idfbc48d3fc3a6cc8a979242681e8882d39998285 Reviewed-on: https://go-review.googlesource.com/c/sys/+/182319 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
committed by
Tobias Klauser
parent
b47fdc9379
commit
15dcb6c006
+23
-2
@@ -120,9 +120,30 @@ func Pipe(p []int) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//sys getdents(fd int, buf []byte) (n int, err error)
|
//sys Getdents(fd int, buf []byte) (n int, err error)
|
||||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||||
return getdents(fd, buf)
|
n, err = Getdents(fd, buf)
|
||||||
|
if err != nil || basep == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var off int64
|
||||||
|
off, err = Seek(fd, 0, 1 /* SEEK_CUR */)
|
||||||
|
if err != nil {
|
||||||
|
*basep = ^uintptr(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*basep = uintptr(off)
|
||||||
|
if unsafe.Sizeof(*basep) == 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if off>>4 != 0 {
|
||||||
|
// We can't stuff the offset back into a uintptr, so any
|
||||||
|
// future calls would be suspect. Generate an error.
|
||||||
|
// EIO is allowed by getdirentries.
|
||||||
|
err = EIO
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImplementsGetwd = true
|
const ImplementsGetwd = true
|
||||||
|
|||||||
+23
-2
@@ -89,9 +89,30 @@ func Pipe(p []int) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//sys getdents(fd int, buf []byte) (n int, err error)
|
//sys Getdents(fd int, buf []byte) (n int, err error)
|
||||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||||
return getdents(fd, buf)
|
n, err = Getdents(fd, buf)
|
||||||
|
if err != nil || basep == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var off int64
|
||||||
|
off, err = Seek(fd, 0, 1 /* SEEK_CUR */)
|
||||||
|
if err != nil {
|
||||||
|
*basep = ^uintptr(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*basep = uintptr(off)
|
||||||
|
if unsafe.Sizeof(*basep) == 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if off>>4 != 0 {
|
||||||
|
// We can't stuff the offset back into a uintptr, so any
|
||||||
|
// future calls would be suspect. Generate an error.
|
||||||
|
// EIO was allowed by getdirentries.
|
||||||
|
err = EIO
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImplementsGetwd = true
|
const ImplementsGetwd = true
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ func pipe() (fd1 int, fd2 int, err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ func pipe() (fd1 int, fd2 int, err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ func pipe() (fd1 int, fd2 int, err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ func pipe() (fd1 int, fd2 int, err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ func pipe(p *[2]_C_int) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ func pipe(p *[2]_C_int) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ func pipe(p *[2]_C_int) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ func pipe(p *[2]_C_int) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func getdents(fd int, buf []byte) (n int, err error) {
|
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||||
var _p0 unsafe.Pointer
|
var _p0 unsafe.Pointer
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
_p0 = unsafe.Pointer(&buf[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user