]> Cypherpunks repositories - gostls13.git/commitdiff
os: remove stuttering return value names
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 17 Jul 2015 15:26:29 +0000 (08:26 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 18 Jul 2015 01:34:21 +0000 (01:34 +0000)
Old style. Make it compliant with our code review comments document.

Also, make WriteString's return parameter named 'n', not 'ret', for
consistency.

Noticed during another documentation review.

Change-Id: Ie88910c5841f8353bc5c0152e2168b497578e15e
Reviewed-on: https://go-review.googlesource.com/12324
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/file.go
src/os/file_plan9.go
src/os/file_posix.go
src/os/file_unix.go
src/os/file_windows.go
src/os/stat_plan9.go
src/os/stat_windows.go

index f1366110cc5410d3ddabc759392e2fa3b89e0bbe..8c0e3ffe1ba7dd7fc86fe06aac0723a121e85424 100644 (file)
@@ -192,7 +192,7 @@ func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
 
 // WriteString is like Write, but writes the contents of string s rather than
 // a slice of bytes.
-func (f *File) WriteString(s string) (ret int, err error) {
+func (f *File) WriteString(s string) (n int, err error) {
        if f == nil {
                return 0, ErrInvalid
        }
@@ -242,16 +242,16 @@ func (f *File) Chdir() error {
 // the returned file can be used for reading; the associated file
 // descriptor has mode O_RDONLY.
 // If there is an error, it will be of type *PathError.
-func Open(name string) (file *File, err error) {
+func Open(name string) (*File, error) {
        return OpenFile(name, O_RDONLY, 0)
 }
 
-// Create creates the named file mode 0666 (before umask), truncating
-// it if it already exists.  If successful, methods on the returned
+// Create creates the named file with mode 0666 (before umask), truncating
+// it if it already exists. If successful, methods on the returned
 // File can be used for I/O; the associated file descriptor has mode
 // O_RDWR.
 // If there is an error, it will be of type *PathError.
-func Create(name string) (file *File, err error) {
+func Create(name string) (*File, error) {
        return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
 }
 
index 6850884d58d1b698f0a898959981d01cfd83b487..085ebc4c8a649f300027e7d37232970d749e644e 100644 (file)
@@ -79,7 +79,7 @@ func syscallMode(i FileMode) (o uint32) {
 // (O_RDONLY etc.) and perm, (0666 etc.) if applicable.  If successful,
 // methods on the returned File can be used for I/O.
 // If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
+func OpenFile(name string, flag int, perm FileMode) (*File, error) {
        var (
                fd     int
                e      error
@@ -159,7 +159,7 @@ func (file *file) close() error {
 
 // Stat returns the FileInfo structure describing file.
 // If there is an error, it will be of type *PathError.
-func (f *File) Stat() (fi FileInfo, err error) {
+func (f *File) Stat() (FileInfo, error) {
        if f == nil {
                return nil, ErrInvalid
        }
@@ -224,7 +224,7 @@ func (f *File) Chmod(mode FileMode) error {
 // Sync commits the current contents of the file to stable storage.
 // Typically, this means flushing the file system's in-memory copy
 // of recently written data to disk.
-func (f *File) Sync() (err error) {
+func (f *File) Sync() error {
        if f == nil {
                return ErrInvalid
        }
index 8f10617e4bbf61fc00739869aeb2e905a3ada9ca..6d8076fdf5cddea285f48b29ac90dbda5397b902 100644 (file)
@@ -114,7 +114,7 @@ func (f *File) Truncate(size int64) error {
 // Sync commits the current contents of the file to stable storage.
 // Typically, this means flushing the file system's in-memory copy
 // of recently written data to disk.
-func (f *File) Sync() (err error) {
+func (f *File) Sync() error {
        if f == nil {
                return ErrInvalid
        }
index 142f885276a97fbab3039dbec190672137bcecb9..0677707ee074c05fba37a9b2fff62e517cd236ba 100644 (file)
@@ -82,7 +82,7 @@ const DevNull = "/dev/null"
 // (O_RDONLY etc.) and perm, (0666 etc.) if applicable.  If successful,
 // methods on the returned File can be used for I/O.
 // If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
+func OpenFile(name string, flag int, perm FileMode) (*File, error) {
        chmod := false
        if !supportsCreateWithStickyBit && flag&O_CREATE != 0 && perm&ModeSticky != 0 {
                if _, err := Stat(name); IsNotExist(err) {
@@ -135,12 +135,12 @@ func (file *file) close() error {
 
 // Stat returns the FileInfo structure describing file.
 // If there is an error, it will be of type *PathError.
-func (f *File) Stat() (fi FileInfo, err error) {
+func (f *File) Stat() (FileInfo, error) {
        if f == nil {
                return nil, ErrInvalid
        }
        var stat syscall.Stat_t
-       err = syscall.Fstat(f.fd, &stat)
+       err := syscall.Fstat(f.fd, &stat)
        if err != nil {
                return nil, &PathError{"stat", f.name, err}
        }
@@ -149,9 +149,9 @@ func (f *File) Stat() (fi FileInfo, err error) {
 
 // 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) {
        var stat syscall.Stat_t
-       err = syscall.Stat(name, &stat)
+       err := syscall.Stat(name, &stat)
        if err != nil {
                return nil, &PathError{"stat", name, err}
        }
@@ -162,9 +162,9 @@ 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) {
        var stat syscall.Stat_t
-       err = syscall.Lstat(name, &stat)
+       err := syscall.Lstat(name, &stat)
        if err != nil {
                return nil, &PathError{"lstat", name, err}
        }
index 9444ac5d6f0e060311c4df7cd5ad8207f0dd79fd..89b1d27fceea7f9debaa68a734de1deb54343d6b 100644 (file)
@@ -134,7 +134,7 @@ func openDir(name string) (file *File, err error) {
 // (O_RDONLY etc.) and perm, (0666 etc.) if applicable.  If successful,
 // methods on the returned File can be used for I/O.
 // If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
+func OpenFile(name string, flag int, perm FileMode) (*File, error) {
        if name == "" {
                return nil, &PathError{"open", name, syscall.ENOENT}
        }
index ddb304fd944b8f8d13c8f1ad363c0bfdb7715657..fa4bd83aefb25d48e7cdbea5d67de985206a851e 100644 (file)
@@ -90,7 +90,7 @@ func dirstat(arg interface{}) (*syscall.Dir, error) {
 
 // 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
@@ -102,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)
 }
 
index f396c1db315e5fe08febaf3ac05490e3df2c682f..966163b2babcd3a1d7796eee6595ab9a75a1f64e 100644 (file)
@@ -11,7 +11,7 @@ import (
 
 // Stat returns the FileInfo structure describing file.
 // If there is an error, it will be of type *PathError.
-func (file *File) Stat() (fi FileInfo, err error) {
+func (file *File) Stat() (FileInfo, error) {
        if file == nil {
                return nil, ErrInvalid
        }
@@ -48,28 +48,29 @@ func (file *File) Stat() (fi FileInfo, err error) {
 
 // Stat returns a FileInfo structure 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) {
+       var fi FileInfo
+       var err error
        for {
                fi, err = Lstat(name)
                if err != nil {
-                       return
+                       return fi, err
                }
                if fi.Mode()&ModeSymlink == 0 {
-                       return
+                       return fi, nil
                }
                name, err = Readlink(name)
                if err != nil {
-                       return
+                       return fi, err
                }
        }
-       return fi, err
 }
 
 // Lstat returns the FileInfo structure describing the named file.
 // 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) {
        if len(name) == 0 {
                return nil, &PathError{"Lstat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
        }