1
0
mirror of https://github.com/golang/go synced 2024-10-04 11:11:21 -06:00
go/src/os/dir_windows.go
Hiroshi Ioka 664c4a1f87 os: consolidate files
Code movement only.

If someone finds function 'foo' in "foo_linux.go",
they will expect that the Window version of 'foo' exists in "foo_windows.go".

Current code doesn't follow this manner.

For example, 'sameFile' exists in "file_unix.go",
"stat_plan9.go" and "types_windows.go".

The CL address that problem by following rules:

* readdir family => dir.go, dir_$GOOS.go
* stat family => stat.go, stat_$GOOS.go
* path-functions => path_$GOOS.go
* sameFile => types.go, types_$GOOS.go
* process-functions => exec.go, exec_$GOOS.go
* hostname => sys.go, sys_$GOOS.go

Change-Id: Ic3c64663ce0b2a364d7a414351cd3c772e70187b
Reviewed-on: https://go-review.googlesource.com/27035
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-16 00:15:36 +00:00

79 lines
1.7 KiB
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os
import (
"io"
"syscall"
)
func (file *File) readdir(n int) (fi []FileInfo, err error) {
if file == nil {
return nil, syscall.EINVAL
}
if !file.isdir() {
return nil, &PathError{"Readdir", file.name, syscall.ENOTDIR}
}
if !file.dirinfo.isempty && file.fd == syscall.InvalidHandle {
return nil, syscall.EINVAL
}
wantAll := n <= 0
size := n
if wantAll {
n = -1
size = 100
}
fi = make([]FileInfo, 0, size) // Empty with room to grow.
d := &file.dirinfo.data
for n != 0 && !file.dirinfo.isempty {
if file.dirinfo.needdata {
e := syscall.FindNextFile(file.fd, d)
if e != nil {
if e == syscall.ERROR_NO_MORE_FILES {
break
} else {
err = &PathError{"FindNextFile", file.name, e}
if !wantAll {
fi = nil
}
return
}
}
}
file.dirinfo.needdata = true
name := syscall.UTF16ToString(d.FileName[0:])
if name == "." || name == ".." { // Useless names
continue
}
f := &fileStat{
name: name,
sys: syscall.Win32FileAttributeData{
FileAttributes: d.FileAttributes,
CreationTime: d.CreationTime,
LastAccessTime: d.LastAccessTime,
LastWriteTime: d.LastWriteTime,
FileSizeHigh: d.FileSizeHigh,
FileSizeLow: d.FileSizeLow,
},
path: file.dirinfo.path + `\` + name,
}
n--
fi = append(fi, f)
}
if !wantAll && len(fi) == 0 {
return fi, io.EOF
}
return fi, nil
}
func (file *File) readdirnames(n int) (names []string, err error) {
fis, err := file.Readdir(n)
names = make([]string, len(fis))
for i, fi := range fis {
names[i] = fi.Name()
}
return names, err
}