...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package fileutil
19
20 import (
21 "os"
22 "syscall"
23 )
24
25 const (
26
27 PrivateDirMode = 0777
28 )
29
30
31 func OpenDir(path string) (*os.File, error) {
32 fd, err := openDir(path)
33 if err != nil {
34 return nil, err
35 }
36 return os.NewFile(uintptr(fd), path), nil
37 }
38
39 func openDir(path string) (fd syscall.Handle, err error) {
40 if len(path) == 0 {
41 return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND
42 }
43 pathp, err := syscall.UTF16PtrFromString(path)
44 if err != nil {
45 return syscall.InvalidHandle, err
46 }
47 access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE)
48 sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE)
49 createmode := uint32(syscall.OPEN_EXISTING)
50 fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS)
51 return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0)
52 }
53
View as plain text