patch: fmt, os, runtime, syscall, time

This commit is contained in:
xushiwei
2024-06-26 17:17:10 +08:00
parent fd0cb4c458
commit 48a1384197
30 changed files with 5373 additions and 24 deletions

View File

@@ -128,20 +128,15 @@ func (f *File) Write(b []byte) (n int, err error) {
return 0, err
}
n, e := f.write(b)
if n < 0 {
n = 0
}
if n != len(b) {
err = io.ErrShortWrite
}
// TODO(xsw):
// epipecheck(f, e)
if e != nil {
err = f.wrapErr("write", e)
} else if n != len(b) {
err = io.ErrShortWrite
}
return n, err
}

View File

@@ -5,6 +5,7 @@
package os
import (
"io"
"io/fs"
"syscall"
"unsafe"
@@ -38,22 +39,25 @@ func NewFile(fd uintptr, name string) *File {
// 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 = int(os.Write(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b))))
if n != len(b) {
err = syscall.Errno(os.Errno)
func (f *File) write(b []byte) (int, error) {
ret := os.Write(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)))
if ret >= 0 {
return int(ret), nil
}
return
return 0, syscall.Errno(os.Errno)
}
// 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 = int(os.Read(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b))))
if n != len(b) {
err = syscall.Errno(os.Errno)
func (f *File) read(b []byte) (int, error) {
ret := os.Read(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)))
if ret > 0 {
return int(ret), nil
}
return
if ret == 0 {
return 0, io.EOF
}
return 0, syscall.Errno(os.Errno)
}
// checkValid checks whether f is valid for use.