runtime/internal/lib/os: fix readdir for darwin-amd64
This commit is contained in:
@@ -13,7 +13,17 @@ func main() {
|
|||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
panic("No files found")
|
panic("No files found")
|
||||||
}
|
}
|
||||||
|
var check int
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
fmt.Printf("%s isDir[%t]\n", e.Name(), e.IsDir())
|
fmt.Printf("%s isDir[%t]\n", e.Name(), e.IsDir())
|
||||||
|
if !e.IsDir() {
|
||||||
|
switch e.Name() {
|
||||||
|
case "go.sum", "go.mod":
|
||||||
|
check++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if check != 2 {
|
||||||
|
panic("Bad readdir entries go.mod/go.sum")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
runtime/internal/clite/os/dir.go
Normal file
17
runtime/internal/clite/os/dir.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package os
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
|
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DIR struct {
|
||||||
|
Unused [0]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname Opendir C.opendir
|
||||||
|
func Opendir(name *c.Char) *DIR
|
||||||
|
|
||||||
|
//go:linkname Closedir C.closedir
|
||||||
|
func Closedir(dir *DIR) c.Int
|
||||||
17
runtime/internal/clite/os/dir_darwin_amd64.go
Normal file
17
runtime/internal/clite/os/dir_darwin_amd64.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package os
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
|
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||||
|
"github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:linkname Fdopendir C.fdopendir$INODE64
|
||||||
|
func Fdopendir(fd c.Int) *DIR
|
||||||
|
|
||||||
|
//go:linkname Readdir C.readdir$INODE64
|
||||||
|
func Readdir(dir *DIR) *syscall.Dirent
|
||||||
|
|
||||||
|
//go:linkname Fstatat C.fstatat$INODE64
|
||||||
|
func Fstatat(dirfd c.Int, path *c.Char, buf *StatT, flags c.Int) c.Int
|
||||||
20
runtime/internal/clite/os/dir_unix.go
Normal file
20
runtime/internal/clite/os/dir_unix.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build !(darwin && amd64)
|
||||||
|
// +build !darwin !amd64
|
||||||
|
|
||||||
|
package os
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
|
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||||
|
"github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:linkname Fdopendir C.fdopendir
|
||||||
|
func Fdopendir(fd c.Int) *DIR
|
||||||
|
|
||||||
|
//go:linkname Readdir C.readdir
|
||||||
|
func Readdir(dir *DIR) *syscall.Dirent
|
||||||
|
|
||||||
|
//go:linkname Fstatat C.fstatat
|
||||||
|
func Fstatat(dirfd c.Int, path *c.Char, buf *StatT, flags c.Int) c.Int
|
||||||
@@ -135,9 +135,6 @@ func Fchmodat(dirfd c.Int, path *c.Char, mode ModeT, flags c.Int) c.Int
|
|||||||
//go:linkname Fchownat C.fchownat
|
//go:linkname Fchownat C.fchownat
|
||||||
func Fchownat(dirfd c.Int, path *c.Char, owner UidT, group GidT, flags c.Int) c.Int
|
func Fchownat(dirfd c.Int, path *c.Char, owner UidT, group GidT, flags c.Int) c.Int
|
||||||
|
|
||||||
//go:linkname Fstatat C.fstatat
|
|
||||||
func Fstatat(dirfd c.Int, path *c.Char, buf *StatT, flags c.Int) c.Int
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
//go:linkname Open C.open
|
//go:linkname Open C.open
|
||||||
@@ -191,9 +188,6 @@ func Fchmod(fd c.Int, mode ModeT) c.Int
|
|||||||
//go:linkname Fchown C.fchown
|
//go:linkname Fchown C.fchown
|
||||||
func Fchown(fd c.Int, owner UidT, group GidT) c.Int
|
func Fchown(fd c.Int, owner UidT, group GidT) c.Int
|
||||||
|
|
||||||
//go:linkname Fstat C.fstat
|
|
||||||
func Fstat(fd c.Int, buf *StatT) c.Int
|
|
||||||
|
|
||||||
//go:linkname Isatty C.isatty
|
//go:linkname Isatty C.isatty
|
||||||
func Isatty(fd c.Int) c.Int
|
func Isatty(fd c.Int) c.Int
|
||||||
|
|
||||||
|
|||||||
@@ -14,3 +14,6 @@ func Stat(path *c.Char, buf *StatT) c.Int
|
|||||||
|
|
||||||
//go:linkname Lstat C.lstat
|
//go:linkname Lstat C.lstat
|
||||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||||
|
|
||||||
|
//go:linkname Fstat C.fstat
|
||||||
|
func Fstat(fd c.Int, buf *StatT) c.Int
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ func Stat(path *c.Char, buf *StatT) c.Int
|
|||||||
|
|
||||||
//go:linkname Lstat C.lstat64
|
//go:linkname Lstat C.lstat64
|
||||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||||
|
|
||||||
|
//go:linkname Fstat C.fstat64
|
||||||
|
func Fstat(fd c.Int, buf *StatT) c.Int
|
||||||
|
|||||||
@@ -82,30 +82,10 @@ func ReadDir(name string) ([]DirEntry, error) {
|
|||||||
return dirs, err
|
return dirs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:linkname c_fdopendir C.fdopendir
|
func readdir(dir *os.DIR) ([]syscall.Dirent, error) {
|
||||||
func c_fdopendir(fd c.Int) uintptr
|
|
||||||
|
|
||||||
func fdopendir(fd int) (dir uintptr, err error) {
|
|
||||||
return c_fdopendir(c.Int(fd)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:linkname c_closedir C.closedir
|
|
||||||
func c_closedir(dir uintptr) c.Int
|
|
||||||
|
|
||||||
func closedir(dir uintptr) error {
|
|
||||||
if c_closedir(dir) != 0 {
|
|
||||||
return syscall.Errno(os.Errno())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:linkname c_readdir C.readdir
|
|
||||||
func c_readdir(dir uintptr) *syscall.Dirent
|
|
||||||
|
|
||||||
func readdir(dir uintptr) ([]syscall.Dirent, error) {
|
|
||||||
var entries []syscall.Dirent
|
var entries []syscall.Dirent
|
||||||
for {
|
for {
|
||||||
dirent := c_readdir(dir)
|
dirent := os.Readdir(dir)
|
||||||
if dirent == nil {
|
if dirent == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -139,11 +119,11 @@ func (f *File) ReadDir(n int) (dirents []DirEntry, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open directory using file descriptor
|
// Open directory using file descriptor
|
||||||
dir, err := fdopendir(int(f.fd))
|
dir := os.Fdopendir(c.Int(f.fd))
|
||||||
if err != nil {
|
if dir == nil {
|
||||||
return nil, err
|
return nil, syscall.Errno(os.Errno())
|
||||||
}
|
}
|
||||||
defer closedir(dir)
|
defer os.Closedir(dir)
|
||||||
|
|
||||||
// Match Readdir and Readdirnames: don't return nil slices.
|
// Match Readdir and Readdirnames: don't return nil slices.
|
||||||
dirents = []DirEntry{}
|
dirents = []DirEntry{}
|
||||||
|
|||||||
Reference in New Issue
Block a user