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.
12 func (file
*File
) readdir(n
int) ([]FileInfo
, error
) {
13 // If this file has no dirinfo, create one.
14 if file
.dirinfo
== nil {
15 file
.dirinfo
= new(dirInfo
)
23 fi
:= make([]FileInfo
, 0, size
) // Empty with room to grow.
25 // Refill the buffer if necessary.
27 nb
, err
:= file
.Read(d
.buf
[:])
29 // Update the buffer state before checking for errors.
30 d
.bufp
, d
.nbuf
= 0, nb
36 return fi
, &PathError
{"readdir", file
.name
, err
}
38 if nb
< syscall
.STATFIXLEN
{
39 return fi
, &PathError
{"readdir", file
.name
, syscall
.ErrShortStat
}
43 // Get a record from the buffer.
45 m
:= int(uint16(b
[0])|
uint16(b
[1])<<8) + 2
46 if m
< syscall
.STATFIXLEN
{
47 return fi
, &PathError
{"readdir", file
.name
, syscall
.ErrShortStat
}
50 dir
, err
:= syscall
.UnmarshalDir(b
[:m
])
52 return fi
, &PathError
{"readdir", file
.name
, err
}
54 fi
= append(fi
, fileInfoFromStat(dir
))
60 if n
>= 0 && len(fi
) == 0 {
66 func (file
*File
) readdirnames(n
int) (names
[]string, err error
) {
67 fi
, err
:= file
.Readdir(n
)
68 names
= make([]string, len(fi
))
70 names
[i
] = fi
[i
].Name()