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 p
:= syscall
.StringBytePtr(file
.name
)
46 syscall
.Entersyscall()
52 entry_dirent
:= (*syscall
.Dirent
)(unsafe
.Pointer(&file
.dirinfo
.buf
[0]))
60 names
= make([]string, 0, size
) // Empty with room to grow.
62 dir
:= file
.dirinfo
.dir
64 return names
, NewSyscallError("opendir", syscall
.GetErrno())
68 var result
*syscall
.Dirent
70 syscall
.Entersyscall()
71 i
:= libc_readdir_r(dir
, entry_dirent
, pr
)
74 return names
, NewSyscallError("readdir_r", i
)
79 var name
= string(result
.Name
[0:clen(result
.Name
[0:])])
80 if name
== "." || name
== ".." { // Useless names
83 names
= append(names
, name
)
86 if n
>= 0 && len(names
) == 0 {