diff options
Diffstat (limited to 'llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go')
| -rw-r--r-- | llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go b/llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go index 25c9a8c14b3..fa4bd83aefb 100644 --- a/llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go +++ b/llgo/third_party/gofrontend/libgo/go/os/stat_plan9.go @@ -9,6 +9,8 @@ import ( "time" ) +const _BIT16SZ = 2 + func sameFile(fs1, fs2 *fileStat) bool { a := fs1.sys.(*syscall.Dir) b := fs2.sys.(*syscall.Dir) @@ -41,16 +43,14 @@ func fileInfoFromStat(d *syscall.Dir) FileInfo { // arg is an open *File or a path string. func dirstat(arg interface{}) (*syscall.Dir, error) { var name string + var err error - // This is big enough for most stat messages - // and rounded to a multiple of 128 bytes. - size := (syscall.STATFIXLEN + 16*4 + 128) &^ 128 + size := syscall.STATFIXLEN + 16*4 for i := 0; i < 2; i++ { - buf := make([]byte, size) + buf := make([]byte, _BIT16SZ+size) var n int - var err error switch a := arg.(type) { case *File: name = a.name @@ -61,34 +61,36 @@ func dirstat(arg interface{}) (*syscall.Dir, error) { default: panic("phase error in dirstat") } - if err != nil { + + if n < _BIT16SZ { return nil, &PathError{"stat", name, err} } - if n < syscall.STATFIXLEN { - return nil, &PathError{"stat", name, syscall.ErrShortStat} - } // Pull the real size out of the stat message. size = int(uint16(buf[0]) | uint16(buf[1])<<8) // If the stat message is larger than our buffer we will // go around the loop and allocate one that is big enough. - if size > n { - continue + if size <= n { + d, err := syscall.UnmarshalDir(buf[:n]) + if err != nil { + return nil, &PathError{"stat", name, err} + } + return d, nil } - d, err := syscall.UnmarshalDir(buf[:n]) - if err != nil { - return nil, &PathError{"stat", name, err} - } - return d, nil } - return nil, &PathError{"stat", name, syscall.ErrBadStat} + + if err == nil { + err = syscall.ErrBadStat + } + + return nil, &PathError{"stat", name, err} } // Stat returns a FileInfo describing the named file. // If there is an error, it will be of type *PathError. -func Stat(name string) (fi FileInfo, err error) { +func Stat(name string) (FileInfo, error) { d, err := dirstat(name) if err != nil { return nil, err @@ -100,7 +102,7 @@ func Stat(name string) (fi FileInfo, err error) { // If the file is a symbolic link, the returned FileInfo // describes the symbolic link. Lstat makes no attempt to follow the link. // If there is an error, it will be of type *PathError. -func Lstat(name string) (fi FileInfo, err error) { +func Lstat(name string) (FileInfo, error) { return Stat(name) } |

