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.
15 func libc_opendir(*byte) *syscall
.DIR
18 func libc_closedir(*syscall
.DIR
) int
20 // FIXME: pathconf returns long, not int.
22 func libc_pathconf(*byte, int) int
24 func clen(n
[]byte) int {
25 for i
:= 0; i
< len(n
); i
++ {
35 func (file
*File
) readdirnames(n
int) (names
[]string, err error
) {
36 if file
.dirinfo
== nil {
37 p
, err
:= syscall
.BytePtrFromString(file
.name
)
42 elen
:= int(atomic
.LoadInt32(&nameMax
))
44 syscall
.Entersyscall()
45 plen
:= libc_pathconf(p
, syscall
.PC_NAME_MAX
)
50 var dummy syscall
.Dirent
51 elen
= int(unsafe
.Offsetof(dummy
.Name
)) + plen
+ 1
52 atomic
.StoreInt32(&nameMax
, int32(elen
))
55 syscall
.Entersyscall()
57 errno
:= syscall
.GetErrno()
60 return nil, &PathError
{"opendir", file
.name
, errno
}
63 file
.dirinfo
= new(dirInfo
)
64 file
.dirinfo
.buf
= make([]byte, elen
)
68 entryDirent
:= (*syscall
.Dirent
)(unsafe
.Pointer(&file
.dirinfo
.buf
[0]))
76 names
= make([]string, 0, size
) // Empty with room to grow.
79 var dirent
*syscall
.Dirent
81 syscall
.Entersyscall()
82 i
:= libc_readdir_r(file
.dirinfo
.dir
, entryDirent
, pr
)
85 return names
, NewSyscallError("readdir_r", i
)
90 bytes
:= (*[10000]byte)(unsafe
.Pointer(&dirent
.Name
[0]))
91 var name
= string(bytes
[0:clen(bytes
[:])])
92 if name
== "." || name
== ".." { // Useless names
95 names
= append(names
, name
)
98 if n
>= 0 && len(names
) == 0 {