Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: src/pkg/os/stat_windows.go

Issue 5298073: code review 5298073: os: use error, io.EOF (Closed)
Patch Set: diff -r f751618f828b https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/os/stat_plan9.go ('k') | src/pkg/os/sys_bsd.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 os 5 package os
6 6
7 import ( 7 import (
8 "unsafe" 8 "unsafe"
9 "syscall" 9 "syscall"
10 ) 10 )
11 11
12 // Stat returns the FileInfo structure describing file. 12 // Stat returns the FileInfo structure describing file.
13 // It returns the FileInfo and an error, if any. 13 // It returns the FileInfo and an error, if any.
14 func (file *File) Stat() (fi *FileInfo, err Error) { 14 func (file *File) Stat() (fi *FileInfo, err error) {
15 if file == nil || file.fd < 0 { 15 if file == nil || file.fd < 0 {
16 return nil, EINVAL 16 return nil, EINVAL
17 } 17 }
18 if file.isdir() { 18 if file.isdir() {
19 // I don't know any better way to do that for directory 19 // I don't know any better way to do that for directory
20 return Stat(file.name) 20 return Stat(file.name)
21 } 21 }
22 var d syscall.ByHandleFileInformation 22 var d syscall.ByHandleFileInformation
23 e := syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d) 23 e := syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d)
24 if e != 0 { 24 if e != 0 {
25 return nil, &PathError{"GetFileInformationByHandle", file.name, Errno(e)} 25 return nil, &PathError{"GetFileInformationByHandle", file.name, Errno(e)}
26 } 26 }
27 return setFileInfo(new(FileInfo), basename(file.name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTim e), nil 27 return setFileInfo(new(FileInfo), basename(file.name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTim e), nil
28 } 28 }
29 29
30 // Stat returns a FileInfo structure describing the named file and an error, if any. 30 // Stat returns a FileInfo structure describing the named file and an error, if any.
31 // If name names a valid symbolic link, the returned FileInfo describes 31 // If name names a valid symbolic link, the returned FileInfo describes
32 // the file pointed at by the link and has fi.FollowedSymlink set to true. 32 // the file pointed at by the link and has fi.FollowedSymlink set to true.
33 // If name names an invalid symbolic link, the returned FileInfo describes 33 // If name names an invalid symbolic link, the returned FileInfo describes
34 // the link itself and has fi.FollowedSymlink set to false. 34 // the link itself and has fi.FollowedSymlink set to false.
35 func Stat(name string) (fi *FileInfo, err Error) { 35 func Stat(name string) (fi *FileInfo, err error) {
36 if len(name) == 0 { 36 if len(name) == 0 {
37 return nil, &PathError{"Stat", name, Errno(syscall.ERROR_PATH_NO T_FOUND)} 37 return nil, &PathError{"Stat", name, Errno(syscall.ERROR_PATH_NO T_FOUND)}
38 } 38 }
39 var d syscall.Win32FileAttributeData 39 var d syscall.Win32FileAttributeData
40 e := syscall.GetFileAttributesEx(syscall.StringToUTF16Ptr(name), syscall .GetFileExInfoStandard, (*byte)(unsafe.Pointer(&d))) 40 e := syscall.GetFileAttributesEx(syscall.StringToUTF16Ptr(name), syscall .GetFileExInfoStandard, (*byte)(unsafe.Pointer(&d)))
41 if e != 0 { 41 if e != 0 {
42 return nil, &PathError{"GetFileAttributesEx", name, Errno(e)} 42 return nil, &PathError{"GetFileAttributesEx", name, Errno(e)}
43 } 43 }
44 return setFileInfo(new(FileInfo), basename(name), d.FileAttributes, d.Fi leSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), n il 44 return setFileInfo(new(FileInfo), basename(name), d.FileAttributes, d.Fi leSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), n il
45 } 45 }
46 46
47 // Lstat returns the FileInfo structure describing the named file and an 47 // Lstat returns the FileInfo structure describing the named file and an
48 // error, if any. If the file is a symbolic link, the returned FileInfo 48 // error, if any. If the file is a symbolic link, the returned FileInfo
49 // describes the symbolic link. Lstat makes no attempt to follow the link. 49 // describes the symbolic link. Lstat makes no attempt to follow the link.
50 func Lstat(name string) (fi *FileInfo, err Error) { 50 func Lstat(name string) (fi *FileInfo, err error) {
51 // No links on Windows 51 // No links on Windows
52 return Stat(name) 52 return Stat(name)
53 } 53 }
54 54
55 // basename removes trailing slashes and the leading 55 // basename removes trailing slashes and the leading
56 // directory name and drive letter from path name. 56 // directory name and drive letter from path name.
57 func basename(name string) string { 57 func basename(name string) string {
58 // Remove drive letter 58 // Remove drive letter
59 if len(name) == 2 && name[1] == ':' { 59 if len(name) == 2 && name[1] == ':' {
60 name = "." 60 name = "."
(...skipping 28 matching lines...) Expand all
89 fi.Mode = fi.Mode | 0666 89 fi.Mode = fi.Mode | 0666
90 } 90 }
91 fi.Size = int64(sizehi)<<32 + int64(sizelo) 91 fi.Size = int64(sizehi)<<32 + int64(sizelo)
92 fi.Name = name 92 fi.Name = name
93 fi.FollowedSymlink = false 93 fi.FollowedSymlink = false
94 fi.Atime_ns = atime.Nanoseconds() 94 fi.Atime_ns = atime.Nanoseconds()
95 fi.Mtime_ns = wtime.Nanoseconds() 95 fi.Mtime_ns = wtime.Nanoseconds()
96 fi.Ctime_ns = ctime.Nanoseconds() 96 fi.Ctime_ns = ctime.Nanoseconds()
97 return fi 97 return fi
98 } 98 }
OLDNEW
« no previous file with comments | « src/pkg/os/stat_plan9.go ('k') | src/pkg/os/sys_bsd.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b