diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
commit | 519725bb3c075ee2462c929f5997cb068e18466a (patch) | |
tree | 5b162e8488ad147a645048c073577821b4a2bee9 /src/pkg/os/stat_windows.go | |
parent | 842623c5dd2819d980ca9c58048d6bc6ed82475f (diff) | |
download | golang-upstream-weekly/2012.03.22.tar.gz |
Imported Upstream version 2012.03.22upstream-weekly/2012.03.22
Diffstat (limited to 'src/pkg/os/stat_windows.go')
-rw-r--r-- | src/pkg/os/stat_windows.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/pkg/os/stat_windows.go b/src/pkg/os/stat_windows.go index 19e215e93..75351c805 100644 --- a/src/pkg/os/stat_windows.go +++ b/src/pkg/os/stat_windows.go @@ -21,6 +21,9 @@ func (file *File) Stat() (fi FileInfo, err error) { // I don't know any better way to do that for directory return Stat(file.name) } + if file.name == DevNull { + return statDevNull() + } var d syscall.ByHandleFileInformation e := syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d) if e != nil { @@ -41,6 +44,9 @@ func Stat(name string) (fi FileInfo, err error) { if len(name) == 0 { return nil, &PathError{"Stat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)} } + if name == DevNull { + return statDevNull() + } var d syscall.Win32FileAttributeData e := syscall.GetFileAttributesEx(syscall.StringToUTF16Ptr(name), syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&d))) if e != nil { @@ -69,6 +75,22 @@ func Lstat(name string) (fi FileInfo, err error) { return Stat(name) } +// statDevNull return FileInfo structure describing DevNull file ("NUL"). +// It creates invented data, since none of windows api will return +// that information. +func statDevNull() (fi FileInfo, err error) { + return &fileStat{ + name: DevNull, + mode: ModeDevice | ModeCharDevice | 0666, + sys: &winSys{ + // hopefully this will work for SameFile + vol: 0, + idxhi: 0, + idxlo: 0, + }, + }, nil +} + // basename removes trailing slashes and the leading // directory name and drive letter from path name. func basename(name string) string { @@ -199,7 +221,7 @@ func (s *winSys) loadFileId() error { } s.Lock() defer s.Unlock() - h, e := syscall.CreateFile(syscall.StringToUTF16Ptr(s.path), syscall.GENERIC_READ, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, 0, 0) + h, e := syscall.CreateFile(syscall.StringToUTF16Ptr(s.path), 0, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) if e != nil { return e } |