Merge pull request #1173 from luoliwoshang/os/direntNamePtr

os:direntNamePtr for array
This commit is contained in:
xushiwei
2025-08-07 16:59:56 +08:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

19
_demo/readdir/main.go Normal file
View File

@@ -0,0 +1,19 @@
package main
import (
"fmt"
"os"
)
func main() {
entries, err := os.ReadDir("../")
if err != nil {
panic(err)
}
if len(entries) == 0 {
panic("No files found")
}
for _, e := range entries {
fmt.Printf("%s isDir[%t]\n", e.Name(), e.IsDir())
}
}

View File

@@ -120,6 +120,14 @@ func direntNamePtr(name any) *byte {
return name return name
case []byte: case []byte:
return &name[0] return &name[0]
case [1024]int8:
return (*byte)(unsafe.Pointer(&name[0]))
case [512]int8:
return (*byte)(unsafe.Pointer(&name[0]))
case [256]int8:
return (*byte)(unsafe.Pointer(&name[0]))
case [256]uint8:
return (*byte)(unsafe.Pointer(&name[0]))
default: default:
panic("invalid type") panic("invalid type")
} }