forked from powersj/godirwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readdir_windows.go
66 lines (52 loc) · 1.35 KB
/
readdir_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// +build windows
package godirwalk
import "os"
// MinimumScratchBufferSize specifies the minimum size of the scratch buffer
// that ReadDirents, ReadDirnames, Scanner, and Walk will use when reading file
// entries from the operating system. During program startup it is initialized
// to the result from calling `os.Getpagesize()` for non Windows environments,
// and 0 for Windows.
var MinimumScratchBufferSize = 0
func newScratchBuffer() []byte { return nil }
func readDirents(osDirname string, _ []byte) ([]*Dirent, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
fileinfos, err := dh.Readdir(-1)
if err != nil {
_ = dh.Close()
return nil, err
}
entries := make([]*Dirent, len(fileinfos))
for i, fi := range fileinfos {
entries[i] = &Dirent{
name: fi.Name(),
path: osDirname,
modeType: fi.Mode() & os.ModeType,
}
}
if err = dh.Close(); err != nil {
return nil, err
}
return entries, nil
}
func readDirnames(osDirname string, _ []byte) ([]string, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
fileinfos, err := dh.Readdir(-1)
if err != nil {
_ = dh.Close()
return nil, err
}
entries := make([]string, len(fileinfos))
for i, fi := range fileinfos {
entries[i] = fi.Name()
}
if err = dh.Close(); err != nil {
return nil, err
}
return entries, nil
}