mirror of
https://github.com/golang/go
synced 2024-11-20 05:04:43 -07:00
os: do not assume syscall.Write will write everything
Fixes #3323. R=golang-dev, remyoudompheng, gri CC=golang-dev https://golang.org/cl/5837047
This commit is contained in:
parent
20760e4335
commit
b7b3652414
@ -173,7 +173,21 @@ func (f *File) pread(b []byte, off int64) (n int, err error) {
|
|||||||
// write writes len(b) bytes to the File.
|
// write writes len(b) bytes to the File.
|
||||||
// It returns the number of bytes written and an error, if any.
|
// It returns the number of bytes written and an error, if any.
|
||||||
func (f *File) write(b []byte) (n int, err error) {
|
func (f *File) write(b []byte) (n int, err error) {
|
||||||
return syscall.Write(f.fd, b)
|
for {
|
||||||
|
m, err := syscall.Write(f.fd, b)
|
||||||
|
n += m
|
||||||
|
|
||||||
|
// If the syscall wrote some data but not all (short write)
|
||||||
|
// or it returned EINTR, then assume it stopped early for
|
||||||
|
// reasons that are uninteresting to the caller, and try again.
|
||||||
|
if 0 < m && m < len(b) || err == syscall.EINTR {
|
||||||
|
b = b[m:]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
// pwrite writes len(b) bytes to the File starting at byte offset off.
|
// pwrite writes len(b) bytes to the File starting at byte offset off.
|
||||||
|
Loading…
Reference in New Issue
Block a user