1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 func libc_opendir(*byte) *syscall.DIR
17 func libc_closedir(*syscall.DIR) int
19 // FIXME: pathconf returns long, not int.
21 func libc_pathconf(*byte, int) int
23 func clen(n []byte) int {
24 for i := 0; i < len(n); i++ {
34 func (file *File) readdirnames(n int) (names []string, err error) {
36 var dummy syscall.Dirent
37 elen = (int(unsafe.Offsetof(dummy.Name)) +
38 libc_pathconf(syscall.StringBytePtr(file.name), syscall.PC_NAME_MAX) +
42 if file.dirinfo == nil {
43 file.dirinfo = new(dirInfo)
44 file.dirinfo.buf = make([]byte, elen)
45 file.dirinfo.dir = libc_opendir(syscall.StringBytePtr(file.name))
48 entry_dirent := unsafe.Pointer(&file.dirinfo.buf[0]).(*syscall.Dirent)
56 names = make([]string, 0, size) // Empty with room to grow.
58 dir := file.dirinfo.dir
60 return names, NewSyscallError("opendir", syscall.GetErrno())
64 var result *syscall.Dirent
65 i := libc_readdir_r(dir, entry_dirent, &result)
67 return names, NewSyscallError("readdir_r", i)
72 var name = string(result.Name[0:clen(result.Name[0:])])
73 if name == "." || name == ".." { // Useless names
76 names = append(names, name)
79 if n >= 0 && len(names) == 0 {