Commit c54ed66c authored by Mikio Hara's avatar Mikio Hara Committed by Rob Pike

syscall: fix build

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4368050
parent 2aceea63
...@@ -74,35 +74,6 @@ func ReadDirent(fd int, buf []byte) (n int, errno int) { ...@@ -74,35 +74,6 @@ func ReadDirent(fd int, buf []byte) (n int, errno int) {
return Getdirentries(fd, buf, new(uintptr)) return Getdirentries(fd, buf, new(uintptr))
} }
// ParseDirent parses up to max directory entries in buf,
// appending the names to names. It returns the number
// bytes consumed from buf, the number of entries added
// to names, and the new names slice.
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
origlen := len(buf)
for max != 0 && len(buf) > 0 {
dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
if dirent.Reclen == 0 {
buf = nil
break
}
buf = buf[dirent.Reclen:]
if dirent.Ino == 0 { // File absent in directory.
continue
}
bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
var name = string(bytes[0:dirent.Namlen])
if name == "." || name == ".." { // Useless names
continue
}
max--
count++
names = append(names, name)
}
return origlen - len(buf), count, names
}
// Wait status is 7 bits at bottom, either 0 (exited), // Wait status is 7 bits at bottom, either 0 (exited),
// 0x7F (stopped), or a signal number that caused an exit. // 0x7F (stopped), or a signal number that caused an exit.
// The 0x80 bit is whether there was a core dump. // The 0x80 bit is whether there was a core dump.
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
package syscall package syscall
import "unsafe"
const OS = "darwin" const OS = "darwin"
type SockaddrDatalink struct { type SockaddrDatalink struct {
...@@ -26,6 +28,34 @@ type SockaddrDatalink struct { ...@@ -26,6 +28,34 @@ type SockaddrDatalink struct {
raw RawSockaddrDatalink raw RawSockaddrDatalink
} }
// ParseDirent parses up to max directory entries in buf,
// appending the names to names. It returns the number
// bytes consumed from buf, the number of entries added
// to names, and the new names slice.
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
origlen := len(buf)
for max != 0 && len(buf) > 0 {
dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
if dirent.Reclen == 0 {
buf = nil
break
}
buf = buf[dirent.Reclen:]
if dirent.Ino == 0 { // File absent in directory.
continue
}
bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
var name = string(bytes[0:dirent.Namlen])
if name == "." || name == ".." { // Useless names
continue
}
max--
count++
names = append(names, name)
}
return origlen - len(buf), count, names
}
/* /*
* Wrapped * Wrapped
*/ */
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
package syscall package syscall
import "unsafe"
const OS = "freebsd" const OS = "freebsd"
type SockaddrDatalink struct { type SockaddrDatalink struct {
...@@ -26,6 +28,34 @@ type SockaddrDatalink struct { ...@@ -26,6 +28,34 @@ type SockaddrDatalink struct {
raw RawSockaddrDatalink raw RawSockaddrDatalink
} }
// ParseDirent parses up to max directory entries in buf,
// appending the names to names. It returns the number
// bytes consumed from buf, the number of entries added
// to names, and the new names slice.
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
origlen := len(buf)
for max != 0 && len(buf) > 0 {
dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
if dirent.Reclen == 0 {
buf = nil
break
}
buf = buf[dirent.Reclen:]
if dirent.Fileno == 0 { // File absent in directory.
continue
}
bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
var name = string(bytes[0:dirent.Namlen])
if name == "." || name == ".." { // Useless names
continue
}
max--
count++
names = append(names, name)
}
return origlen - len(buf), count, names
}
/* /*
* Exposed directly * Exposed directly
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment