pkg syscall (windows-386), const CREATE_NEW_PROCESS_GROUP ideal-int
pkg syscall (windows-386), const CTRL_BREAK_EVENT ideal-int
pkg syscall (windows-386), const CTRL_C_EVENT ideal-int
-pkg syscall (windows-386), func FindFirstFile1(*uint16, *Win32finddata1) (Handle, error)
-pkg syscall (windows-386), func FindNextFile1(Handle, *Win32finddata1) error
pkg syscall (windows-386), func GetCurrentProcessId() uint32
pkg syscall (windows-386), func Getsockopt(Handle, int32, int32, *byte, *int32) error
pkg syscall (windows-386), type SysProcAttr struct, CreationFlags uint32
-pkg syscall (windows-386), type Win32finddata1 struct
-pkg syscall (windows-386), type Win32finddata1 struct, AlternateFileName [14]uint16
-pkg syscall (windows-386), type Win32finddata1 struct, CreationTime Filetime
-pkg syscall (windows-386), type Win32finddata1 struct, FileAttributes uint32
-pkg syscall (windows-386), type Win32finddata1 struct, FileName [MAX_PATH]uint16
-pkg syscall (windows-386), type Win32finddata1 struct, FileSizeHigh uint32
-pkg syscall (windows-386), type Win32finddata1 struct, FileSizeLow uint32
-pkg syscall (windows-386), type Win32finddata1 struct, LastAccessTime Filetime
-pkg syscall (windows-386), type Win32finddata1 struct, LastWriteTime Filetime
-pkg syscall (windows-386), type Win32finddata1 struct, Reserved0 uint32
-pkg syscall (windows-386), type Win32finddata1 struct, Reserved1 uint32
pkg syscall (windows-amd64), const CREATE_NEW_PROCESS_GROUP ideal-int
pkg syscall (windows-amd64), const CTRL_BREAK_EVENT ideal-int
pkg syscall (windows-amd64), const CTRL_C_EVENT ideal-int
-pkg syscall (windows-amd64), func FindFirstFile1(*uint16, *Win32finddata1) (Handle, error)
-pkg syscall (windows-amd64), func FindNextFile1(Handle, *Win32finddata1) error
pkg syscall (windows-amd64), func GetCurrentProcessId() uint32
pkg syscall (windows-amd64), func Getsockopt(Handle, int32, int32, *byte, *int32) error
pkg syscall (windows-amd64), type SysProcAttr struct, CreationFlags uint32
-pkg syscall (windows-amd64), type Win32finddata1 struct
-pkg syscall (windows-amd64), type Win32finddata1 struct, AlternateFileName [14]uint16
-pkg syscall (windows-amd64), type Win32finddata1 struct, CreationTime Filetime
-pkg syscall (windows-amd64), type Win32finddata1 struct, FileAttributes uint32
-pkg syscall (windows-amd64), type Win32finddata1 struct, FileName [MAX_PATH]uint16
-pkg syscall (windows-amd64), type Win32finddata1 struct, FileSizeHigh uint32
-pkg syscall (windows-amd64), type Win32finddata1 struct, FileSizeLow uint32
-pkg syscall (windows-amd64), type Win32finddata1 struct, LastAccessTime Filetime
-pkg syscall (windows-amd64), type Win32finddata1 struct, LastWriteTime Filetime
-pkg syscall (windows-amd64), type Win32finddata1 struct, Reserved0 uint32
-pkg syscall (windows-amd64), type Win32finddata1 struct, Reserved1 uint32
// Auxiliary information if the File describes a directory
type dirInfo struct {
- data syscall.Win32finddata1
+ data syscall.Win32finddata
needdata bool
path string
}
func openDir(name string) (file *File, err error) {
d := new(dirInfo)
- r, e := syscall.FindFirstFile1(syscall.StringToUTF16Ptr(name+`\*`), &d.data)
+ r, e := syscall.FindFirstFile(syscall.StringToUTF16Ptr(name+`\*`), &d.data)
if e != nil {
return nil, &PathError{"open", name, e}
}
d := &file.dirinfo.data
for n != 0 {
if file.dirinfo.needdata {
- e := syscall.FindNextFile1(syscall.Handle(file.fd), d)
+ e := syscall.FindNextFile(syscall.Handle(file.fd), d)
if e != nil {
if e == syscall.ERROR_NO_MORE_FILES {
break
package syscall
import (
- errorspkg "errors"
"unicode/utf16"
"unsafe"
)
//sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff]
//sys CloseHandle(handle Handle) (err error)
//sys GetStdHandle(stdhandle int) (handle Handle, err error) [failretval==InvalidHandle]
-//sys FindFirstFile1(name *uint16, data *Win32finddata1) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstFileW
-//sys FindNextFile1(handle Handle, data *Win32finddata1) (err error) = FindNextFileW
+//sys findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstFileW
+//sys findNextFile1(handle Handle, data *win32finddata1) (err error) = FindNextFileW
//sys FindClose(handle Handle) (err error)
//sys GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error)
//sys GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) = GetCurrentDirectoryW
func Getpid() (pid int) { return int(GetCurrentProcessId()) }
func FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error) {
- return InvalidHandle, errorspkg.New("FindFirstFile is broken, use FindFirstFile1 instead")
+ // NOTE(rsc): The Win32finddata struct is wrong for the system call:
+ // the two paths are each one uint16 short. Use the correct struct,
+ // a win32finddata1, and then copy the results out.
+ // There is no loss of expressivity here, because the final
+ // uint16, if it is used, is supposed to be a NUL, and Go doesn't need that.
+ // For Go 1.1, we might avoid the allocation of win32finddata1 here
+ // by adding a final Bug [2]uint16 field to the struct and then
+ // adjusting the fields in the result directly.
+ var data1 win32finddata1
+ handle, err = findFirstFile1(name, &data1)
+ if err == nil {
+ copyFindData(data, &data1)
+ }
+ return
}
func FindNextFile(handle Handle, data *Win32finddata) (err error) {
- return errorspkg.New("FindNextFile is broken, use FindNextFile1 instead")
+ var data1 win32finddata1
+ err = findNextFile1(handle, &data1)
+ if err == nil {
+ copyFindData(data, &data1)
+ }
+ return
}
// TODO(brainman): fix all needed for os
return
}
-func FindFirstFile1(name *uint16, data *Win32finddata1) (handle Handle, err error) {
+func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
r0, _, e1 := Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
handle = Handle(r0)
if handle == InvalidHandle {
return
}
-func FindNextFile1(handle Handle, data *Win32finddata1) (err error) {
+func findNextFile1(handle Handle, data *win32finddata1) (err error) {
r1, _, e1 := Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
if int(r1) == 0 {
if e1 != 0 {
return
}
-func FindFirstFile1(name *uint16, data *Win32finddata1) (handle Handle, err error) {
+func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
r0, _, e1 := Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
handle = Handle(r0)
if handle == InvalidHandle {
return
}
-func FindNextFile1(handle Handle, data *Win32finddata1) (err error) {
+func findNextFile1(handle Handle, data *win32finddata1) (err error) {
r1, _, e1 := Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
if int(r1) == 0 {
if e1 != 0 {
return ft
}
-// Win32finddata is an incorrect struct definition, preserved for
-// backwards compatibility. Use Win32finddata1 and the
-// FindFirstFile1 and FindNextFile1 functions instead.
type Win32finddata struct {
FileAttributes uint32
CreationTime Filetime
AlternateFileName [13]uint16
}
-type Win32finddata1 struct {
+// This is the actual system call structure.
+// Win32finddata is what we committed to in Go 1.
+type win32finddata1 struct {
FileAttributes uint32
CreationTime Filetime
LastAccessTime Filetime
AlternateFileName [14]uint16
}
+func copyFindData(dst *Win32finddata, src *win32finddata1) {
+ dst.FileAttributes = src.FileAttributes
+ dst.CreationTime = src.CreationTime
+ dst.LastAccessTime = src.LastAccessTime
+ dst.LastWriteTime = src.LastWriteTime
+ dst.FileSizeHigh = src.FileSizeHigh
+ dst.FileSizeLow = src.FileSizeLow
+ dst.Reserved0 = src.Reserved0
+ dst.Reserved1 = src.Reserved1
+
+ // The src is 1 element shorter than dst. Zero that last one.
+ copy(dst.FileName[:], src.FileName[:])
+ dst.FileName[len(dst.FileName)-1] = 0
+ copy(dst.AlternateFileName[:], src.AlternateFileName[:])
+ src.AlternateFileName[len(dst.AlternateFileName)-1] = 0
+}
+
type ByHandleFileInformation struct {
FileAttributes uint32
CreationTime Filetime