]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] syscall: correct Win32finddata definition
authorAlex Brainman <alex.brainman@gmail.com>
Wed, 13 Jun 2012 20:24:37 +0000 (16:24 -0400)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 13 Jun 2012 20:24:37 +0000 (16:24 -0400)
««« backport 45d1063d8520
syscall: correct Win32finddata definition

Fixes #3685.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6261053

»»»

api/next.txt
src/pkg/os/file_windows.go
src/pkg/syscall/syscall_windows.go
src/pkg/syscall/syscall_windows_test.go [new file with mode: 0644]
src/pkg/syscall/zsyscall_windows_386.go
src/pkg/syscall/zsyscall_windows_amd64.go
src/pkg/syscall/ztypes_windows.go

index 506f088616e13c72181481d321048451ae9f2292..687fdb8a5b00771d1fa4f97d3d0c791a01af8e10 100644 (file)
@@ -419,10 +419,36 @@ pkg syscall (darwin-amd64-cgo), type Termios struct, Pad_cgo_0 [4]byte
 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), 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), 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
index 88fa77bb848e5182d21073ff986c798056b6fe9a..df0e71d6802a31e734a9f9b6453abb2d814617fe 100644 (file)
@@ -50,7 +50,7 @@ func NewFile(fd uintptr, name string) *File {
 
 // Auxiliary information if the File describes a directory
 type dirInfo struct {
-       data     syscall.Win32finddata
+       data     syscall.Win32finddata1
        needdata bool
        path     string
 }
@@ -76,7 +76,7 @@ func openFile(name string, flag int, perm FileMode) (file *File, err error) {
 
 func openDir(name string) (file *File, err error) {
        d := new(dirInfo)
-       r, e := syscall.FindFirstFile(syscall.StringToUTF16Ptr(name+`\*`), &d.data)
+       r, e := syscall.FindFirstFile1(syscall.StringToUTF16Ptr(name+`\*`), &d.data)
        if e != nil {
                return nil, &PathError{"open", name, e}
        }
@@ -159,7 +159,7 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) {
        d := &file.dirinfo.data
        for n != 0 {
                if file.dirinfo.needdata {
-                       e := syscall.FindNextFile(syscall.Handle(file.fd), d)
+                       e := syscall.FindNextFile1(syscall.Handle(file.fd), d)
                        if e != nil {
                                if e == syscall.ERROR_NO_MORE_FILES {
                                        break
index 65ffffa2b9ca9ade0f8a8fec8d118aa08e146fb7..b9cd233785ece5ff0ca3df4c758cc85737979713 100644 (file)
@@ -7,6 +7,7 @@
 package syscall
 
 import (
+       errorspkg "errors"
        "unicode/utf16"
        "unsafe"
 )
@@ -129,8 +130,8 @@ func NewCallback(fn interface{}) uintptr
 //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  FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstFileW
-//sys  FindNextFile(handle Handle, data *Win32finddata) (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
@@ -686,6 +687,14 @@ func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (err error) {
 
 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")
+}
+
+func FindNextFile(handle Handle, data *Win32finddata) (err error) {
+       return errorspkg.New("FindNextFile is broken, use FindNextFile1 instead")
+}
+
 // TODO(brainman): fix all needed for os
 func Getppid() (ppid int) { return -1 }
 
diff --git a/src/pkg/syscall/syscall_windows_test.go b/src/pkg/syscall/syscall_windows_test.go
new file mode 100644 (file)
index 0000000..495eb46
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2012 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 syscall_test
+
+import (
+       "io/ioutil"
+       "os"
+       "path/filepath"
+       "syscall"
+       "testing"
+)
+
+func TestWin32finddata(t *testing.T) {
+       dir, err := ioutil.TempDir("", "go-build")
+       if err != nil {
+               t.Fatalf("failed to create temp directory: %v", err)
+       }
+       defer os.RemoveAll(dir)
+
+       path := filepath.Join(dir, "long_name.and_extension")
+       f, err := os.Create(path)
+       if err != nil {
+               t.Fatalf("failed to create %v: %v", path, err)
+       }
+       f.Close()
+
+       type X struct {
+               fd  syscall.Win32finddata1
+               got byte
+               pad [10]byte // to protect ourselves
+
+       }
+       var want byte = 2 // it is unlikely to have this character in the filename
+       x := X{got: want}
+
+       h, err := syscall.FindFirstFile1(syscall.StringToUTF16Ptr(path), &(x.fd))
+       if err != nil {
+               t.Fatalf("FindFirstFile failed: %v", err)
+       }
+       err = syscall.FindClose(h)
+       if err != nil {
+               t.Fatalf("FindClose failed: %v", err)
+       }
+
+       if x.got != want {
+               t.Fatalf("memory corruption: want=%d got=%d", want, x.got)
+       }
+}
index dd97f7fcd2fc3ff18935ecbb99ec016bdc603d57..4580eb1c46ee69883084d65367dd818d0140ea91 100644 (file)
@@ -309,7 +309,7 @@ func GetStdHandle(stdhandle int) (handle Handle, err error) {
        return
 }
 
-func FindFirstFile(name *uint16, data *Win32finddata) (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 {
@@ -322,7 +322,7 @@ func FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error)
        return
 }
 
-func FindNextFile(handle Handle, data *Win32finddata) (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 {
index a45c61defd1178378702b966a208bbf09072667f..7f66e1a00ba3c5c1fcbf515af698c77e4c7214e5 100644 (file)
@@ -309,7 +309,7 @@ func GetStdHandle(stdhandle int) (handle Handle, err error) {
        return
 }
 
-func FindFirstFile(name *uint16, data *Win32finddata) (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 {
@@ -322,7 +322,7 @@ func FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error)
        return
 }
 
-func FindNextFile(handle Handle, data *Win32finddata) (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 {
index 54168bb98a37577a53a151d7ddb72c0fb0a47b6d..8a443b72d000dfee9b85ec1dbeaf4aacfcaab8d4 100644 (file)
@@ -334,6 +334,9 @@ func NsecToFiletime(nsec int64) (ft Filetime) {
        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
@@ -347,6 +350,19 @@ type Win32finddata struct {
        AlternateFileName [13]uint16
 }
 
+type Win32finddata1 struct {
+       FileAttributes    uint32
+       CreationTime      Filetime
+       LastAccessTime    Filetime
+       LastWriteTime     Filetime
+       FileSizeHigh      uint32
+       FileSizeLow       uint32
+       Reserved0         uint32
+       Reserved1         uint32
+       FileName          [MAX_PATH]uint16
+       AlternateFileName [14]uint16
+}
+
 type ByHandleFileInformation struct {
        FileAttributes     uint32
        CreationTime       Filetime