Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 "syscall" | 7 import "syscall" |
8 | 8 |
9 func fileInfoFromStat(fi *FileInfo, d *Dir) *FileInfo { | 9 func fileInfoFromStat(fi *FileInfo, d *Dir) *FileInfo { |
10 fi.Dev = uint64(d.Qid.Vers) | uint64(d.Qid.Type<<32) | 10 fi.Dev = uint64(d.Qid.Vers) | uint64(d.Qid.Type<<32) |
(...skipping 18 matching lines...) Expand all Loading... | |
29 func dirstat(arg interface{}) (fi *FileInfo, err Error) { | 29 func dirstat(arg interface{}) (fi *FileInfo, err Error) { |
30 var name string | 30 var name string |
31 nd := syscall.STATFIXLEN + 16*4 | 31 nd := syscall.STATFIXLEN + 16*4 |
32 | 32 |
33 for i := 0; i < 2; i++ { /* should work by the second try */ | 33 for i := 0; i < 2; i++ { /* should work by the second try */ |
34 buf := make([]byte, nd) | 34 buf := make([]byte, nd) |
35 | 35 |
36 var n int | 36 var n int |
37 var e syscall.Error | 37 var e syscall.Error |
38 | 38 |
39 » » switch syscall_arg := arg.(type) { | 39 » » switch syscallArg := arg.(type) { |
40 case *File: | 40 case *File: |
41 » » » name = syscall_arg.name | 41 » » » name = syscallArg.name |
42 » » » n, e = syscall.Fstat(syscall_arg.fd, buf) | 42 » » » n, e = syscall.Fstat(syscallArg.fd, buf) |
43 case string: | 43 case string: |
44 » » » name = syscall_arg | 44 » » » name = syscallArg |
45 n, e = syscall.Stat(name, buf) | 45 n, e = syscall.Stat(name, buf) |
46 } | 46 } |
47 | 47 |
48 if e != nil { | 48 if e != nil { |
49 return nil, &PathError{"stat", name, e} | 49 return nil, &PathError{"stat", name, e} |
50 } | 50 } |
51 | 51 |
52 if n < syscall.STATFIXLEN { | 52 if n < syscall.STATFIXLEN { |
53 return nil, &PathError{"stat", name, Eshortstat} | 53 return nil, &PathError{"stat", name, Eshortstat} |
54 } | 54 } |
(...skipping 14 matching lines...) Expand all Loading... | |
69 | 69 |
70 return nil, &PathError{"stat", name, Ebadstat} | 70 return nil, &PathError{"stat", name, Ebadstat} |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 // Stat returns a FileInfo structure describing the named file and an error, if any. | 74 // Stat returns a FileInfo structure describing the named file and an error, if any. |
75 func Stat(name string) (fi *FileInfo, err Error) { | 75 func Stat(name string) (fi *FileInfo, err Error) { |
76 return dirstat(name) | 76 return dirstat(name) |
77 } | 77 } |
78 | 78 |
79 // Lstat returns the FileInfo structure describing the named file and an | |
80 // error, if any. If the file is a symbolic link (though Plan 9 does not have s ymbolic links),· | |
81 // the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. | |
79 func Lstat(name string) (fi *FileInfo, err Error) { | 82 func Lstat(name string) (fi *FileInfo, err Error) { |
r
2011/03/31 22:57:46
copy the comment for Lstat from file.go
paulzhol
2011/04/01 20:16:44
Done.
| |
80 return dirstat(name) | 83 return dirstat(name) |
81 } | 84 } |
LEFT | RIGHT |