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