]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: fix build
authorMikio Hara <mikioh.mikioh@gmail.com>
Thu, 7 Apr 2011 19:03:45 +0000 (12:03 -0700)
committerRob Pike <r@golang.org>
Thu, 7 Apr 2011 19:03:45 +0000 (12:03 -0700)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4368050

src/pkg/syscall/syscall_bsd.go
src/pkg/syscall/syscall_darwin.go
src/pkg/syscall/syscall_freebsd.go

index 95ec1a66fd9f8b930a8b85f4279404b60671258f..9f1244f134aaef98bf72bcc9ced680b7e58b2eca 100644 (file)
@@ -74,35 +74,6 @@ func ReadDirent(fd int, buf []byte) (n int, errno int) {
        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),
 // 0x7F (stopped), or a signal number that caused an exit.
 // The 0x80 bit is whether there was a core dump.
index 1ed2c47c463a420015f8d6c1fa2db7a3de4ad479..30b57cf5560a1085f8e80250266843f650493c62 100644 (file)
@@ -12,6 +12,8 @@
 
 package syscall
 
+import "unsafe"
+
 const OS = "darwin"
 
 type SockaddrDatalink struct {
@@ -26,6 +28,34 @@ type SockaddrDatalink struct {
        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
  */
index a980b96aa4fcb2a3abdf66cb6d8c8b6b9d2f9806..242503dd71233f44cc1157338c1ee62592e228ac 100644 (file)
@@ -12,6 +12,8 @@
 
 package syscall
 
+import "unsafe"
+
 const OS = "freebsd"
 
 type SockaddrDatalink struct {
@@ -26,6 +28,34 @@ type SockaddrDatalink struct {
        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
  */