mirror of
https://github.com/golang/go
synced 2024-11-22 23:50:03 -07:00
os: Plan 9: avoid doing zero-length writes.
Plan 9 I/O preserves message boundaries, while Go library code is written for UNIX-like operating systems which do not. Avoid doing zero-length writes in package os. R=rsc, rminnich, ality, rminnich, r CC=golang-dev https://golang.org/cl/7406046
This commit is contained in:
parent
56a0bafdb6
commit
722ee1f479
@ -244,13 +244,23 @@ func (f *File) pread(b []byte, off int64) (n int, err error) {
|
||||
|
||||
// write writes len(b) bytes to the File.
|
||||
// It returns the number of bytes written and an error, if any.
|
||||
// Since Plan 9 preserves message boundaries, never allow
|
||||
// a zero-byte write.
|
||||
func (f *File) write(b []byte) (n int, err error) {
|
||||
if len(b) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return syscall.Write(f.fd, b)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Since Plan 9 preserves message boundaries, never allow
|
||||
// a zero-byte write.
|
||||
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
|
||||
if len(b) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return syscall.Pwrite(f.fd, b, off)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user