os: implement os.(*File).WriteAt (#3697)

os: implement os.(*File).WriteAt

Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
This commit is contained in:
Achille
2023-05-05 00:40:15 -07:00
committed by GitHub
parent 1d5c5ca2ef
commit 602f35a5ca
8 changed files with 152 additions and 17 deletions
+15 -3
View File
@@ -35,8 +35,9 @@ func rename(oldname, newname string) error {
}
type file struct {
handle FileHandle
name string
handle FileHandle
name string
appendMode bool
}
func (f *file) close() error {
@@ -44,7 +45,7 @@ func (f *file) close() error {
}
func NewFile(fd uintptr, name string) *File {
return &File{&file{unixFileHandle(fd), name}}
return &File{&file{handle: unixFileHandle(fd), name: name}}
}
func Pipe() (r *File, w *File, err error) {
@@ -84,6 +85,17 @@ func (f unixFileHandle) ReadAt(b []byte, offset int64) (n int, err error) {
return -1, ErrNotImplemented
}
// WriteAt writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
// WriteAt returns a non-nil error when n != len(b).
//
// If file was opened with the O_APPEND flag, WriteAt returns an error.
//
// TODO: move to file_anyos once WriteAt is implemented for windows.
func (f unixFileHandle) WriteAt(b []byte, offset int64) (n int, err error) {
return -1, ErrNotImplemented
}
// Seek wraps syscall.Seek.
func (f unixFileHandle) Seek(offset int64, whence int) (int64, error) {
newoffset, err := syscall.Seek(syscallFd(f), offset, whence)