]> Cypherpunks repositories - gostls13.git/commitdiff
os: merge common Unix/Windows methods
authorIan Lance Taylor <iant@golang.org>
Thu, 19 Mar 2020 20:58:48 +0000 (13:58 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 20 Mar 2020 00:26:13 +0000 (00:26 +0000)
Several method implementations were identical in file_unix.go and
file_windows.go. Merge them into file_posix.go.

Change-Id: I8bcfad468829530f81f52fe426b3a8c042e7bbd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/224138
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/os/file_posix.go
src/os/file_unix.go
src/os/file_windows.go

index c3635ddd289bdf8c59126ec001cc495c7cf479f0..24ea554b62ce0a34faa80eef22612c72ccaaff3b 100644 (file)
@@ -7,12 +7,57 @@
 package os
 
 import (
+       "runtime"
        "syscall"
        "time"
 )
 
 func sigpipe() // implemented in package runtime
 
+// Close closes the File, rendering it unusable for I/O.
+// On files that support SetDeadline, any pending I/O operations will
+// be canceled and return immediately with an error.
+// Close will return an error if it has already been called.
+func (f *File) Close() error {
+       if f == nil {
+               return ErrInvalid
+       }
+       return f.file.close()
+}
+
+// read reads up to len(b) bytes from the File.
+// It returns the number of bytes read and an error, if any.
+func (f *File) read(b []byte) (n int, err error) {
+       n, err = f.pfd.Read(b)
+       runtime.KeepAlive(f)
+       return n, err
+}
+
+// pread reads len(b) bytes from the File starting at byte offset off.
+// It returns the number of bytes read and the error, if any.
+// EOF is signaled by a zero count with err set to nil.
+func (f *File) pread(b []byte, off int64) (n int, err error) {
+       n, err = f.pfd.Pread(b, off)
+       runtime.KeepAlive(f)
+       return n, err
+}
+
+// write writes len(b) bytes to the File.
+// It returns the number of bytes written and an error, if any.
+func (f *File) write(b []byte) (n int, err error) {
+       n, err = f.pfd.Write(b)
+       runtime.KeepAlive(f)
+       return n, err
+}
+
+// pwrite writes len(b) bytes to the File starting at byte offset off.
+// It returns the number of bytes written and an error, if any.
+func (f *File) pwrite(b []byte, off int64) (n int, err error) {
+       n, err = f.pfd.Pwrite(b, off)
+       runtime.KeepAlive(f)
+       return n, err
+}
+
 // syscallMode returns the syscall-specific mode bits from Go's portable mode bits.
 func syscallMode(i FileMode) (o uint32) {
        o |= uint32(i.Perm())
index 32e4442e5d06740dc229a539cc90eceeb746ec3c..b93e2bd56af0dd98603d93d7778d3bcb0e7057c3 100644 (file)
@@ -226,17 +226,6 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
        return newFile(uintptr(r), name, kindOpenFile), nil
 }
 
-// Close closes the File, rendering it unusable for I/O.
-// On files that support SetDeadline, any pending I/O operations will
-// be canceled and return immediately with an error.
-// Close will return an error if it has already been called.
-func (f *File) Close() error {
-       if f == nil {
-               return ErrInvalid
-       }
-       return f.file.close()
-}
-
 func (file *file) close() error {
        if file == nil {
                return syscall.EINVAL
@@ -257,39 +246,6 @@ func (file *file) close() error {
        return err
 }
 
-// read reads up to len(b) bytes from the File.
-// It returns the number of bytes read and an error, if any.
-func (f *File) read(b []byte) (n int, err error) {
-       n, err = f.pfd.Read(b)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// pread reads len(b) bytes from the File starting at byte offset off.
-// It returns the number of bytes read and the error, if any.
-// EOF is signaled by a zero count with err set to nil.
-func (f *File) pread(b []byte, off int64) (n int, err error) {
-       n, err = f.pfd.Pread(b, off)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// write writes len(b) bytes to the File.
-// It returns the number of bytes written and an error, if any.
-func (f *File) write(b []byte) (n int, err error) {
-       n, err = f.pfd.Write(b)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// pwrite writes len(b) bytes to the File starting at byte offset off.
-// It returns the number of bytes written and an error, if any.
-func (f *File) pwrite(b []byte, off int64) (n int, err error) {
-       n, err = f.pfd.Pwrite(b, off)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
 // seek sets the offset for the next Read or Write on file to offset, interpreted
 // according to whence: 0 means relative to the origin of the file, 1 means
 // relative to the current offset, and 2 means relative to the end.
index 96f934d039917ff7262996899ee32e8ed1c3f76d..0d8c0fd20de5a25c066b2c3d7d2f55e7cb0666f0 100644 (file)
@@ -182,17 +182,6 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
        return nil, &PathError{"open", name, errf}
 }
 
-// Close closes the File, rendering it unusable for I/O.
-// On files that support SetDeadline, any pending I/O operations will
-// be canceled and return immediately with an error.
-// Close will return an error if it has already been called.
-func (file *File) Close() error {
-       if file == nil {
-               return ErrInvalid
-       }
-       return file.file.close()
-}
-
 func (file *file) close() error {
        if file == nil {
                return syscall.EINVAL
@@ -214,39 +203,6 @@ func (file *file) close() error {
        return err
 }
 
-// read reads up to len(b) bytes from the File.
-// It returns the number of bytes read and an error, if any.
-func (f *File) read(b []byte) (n int, err error) {
-       n, err = f.pfd.Read(b)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// pread reads len(b) bytes from the File starting at byte offset off.
-// It returns the number of bytes read and the error, if any.
-// EOF is signaled by a zero count with err set to 0.
-func (f *File) pread(b []byte, off int64) (n int, err error) {
-       n, err = f.pfd.Pread(b, off)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// write writes len(b) bytes to the File.
-// It returns the number of bytes written and an error, if any.
-func (f *File) write(b []byte) (n int, err error) {
-       n, err = f.pfd.Write(b)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
-// pwrite writes len(b) bytes to the File starting at byte offset off.
-// It returns the number of bytes written and an error, if any.
-func (f *File) pwrite(b []byte, off int64) (n int, err error) {
-       n, err = f.pfd.Pwrite(b, off)
-       runtime.KeepAlive(f)
-       return n, err
-}
-
 // seek sets the offset for the next Read or Write on file to offset, interpreted
 // according to whence: 0 means relative to the origin of the file, 1 means
 // relative to the current offset, and 2 means relative to the end.