LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package syscall_test | 5 package syscall_test |
6 | 6 |
7 import ( | 7 import ( |
8 "io/ioutil" | 8 "io/ioutil" |
9 "os" | 9 "os" |
10 "path/filepath" | 10 "path/filepath" |
11 "syscall" | 11 "syscall" |
12 "testing" | 12 "testing" |
13 ) | 13 ) |
14 | 14 |
15 func TestWin32finddata(t *testing.T) { | 15 func TestWin32finddata(t *testing.T) { |
16 dir, err := ioutil.TempDir("", "go-build") | 16 dir, err := ioutil.TempDir("", "go-build") |
17 if err != nil { | 17 if err != nil { |
18 t.Fatalf("failed to create temp directory: %v", err) | 18 t.Fatalf("failed to create temp directory: %v", err) |
19 } | 19 } |
20 defer os.RemoveAll(dir) | 20 defer os.RemoveAll(dir) |
21 | 21 |
22 path := filepath.Join(dir, "long_name.and_extension") | 22 path := filepath.Join(dir, "long_name.and_extension") |
23 f, err := os.Create(path) | 23 f, err := os.Create(path) |
24 if err != nil { | 24 if err != nil { |
25 t.Fatalf("failed to create %v: %v", path, err) | 25 t.Fatalf("failed to create %v: %v", path, err) |
26 } | 26 } |
27 f.Close() | 27 f.Close() |
28 | 28 |
29 type X struct { | 29 type X struct { |
30 » » fd syscall.Win32finddata | 30 » » fd syscall.Win32finddata1 |
31 got byte | 31 got byte |
32 pad [10]byte // to protect ourselves | 32 pad [10]byte // to protect ourselves |
33 | 33 |
34 } | 34 } |
35 var want byte = 2 // it is unlikely to have this character in the filena
me | 35 var want byte = 2 // it is unlikely to have this character in the filena
me |
36 x := X{got: want} | 36 x := X{got: want} |
37 | 37 |
38 » h, err := syscall.FindFirstFile(syscall.StringToUTF16Ptr(path), &(x.fd)) | 38 » h, err := syscall.FindFirstFile1(syscall.StringToUTF16Ptr(path), &(x.fd)
) |
39 if err != nil { | 39 if err != nil { |
40 t.Fatalf("FindFirstFile failed: %v", err) | 40 t.Fatalf("FindFirstFile failed: %v", err) |
41 } | 41 } |
42 err = syscall.FindClose(h) | 42 err = syscall.FindClose(h) |
43 if err != nil { | 43 if err != nil { |
44 t.Fatalf("FindClose failed: %v", err) | 44 t.Fatalf("FindClose failed: %v", err) |
45 } | 45 } |
46 | 46 |
47 if x.got != want { | 47 if x.got != want { |
48 t.Fatalf("memory corruption: want=%d got=%d", want, x.got) | 48 t.Fatalf("memory corruption: want=%d got=%d", want, x.got) |
49 } | 49 } |
50 } | 50 } |
LEFT | RIGHT |