2012-03-27 23:13:14 +00:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build plan9
|
|
|
|
|
|
|
|
package time
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// for testing: whatever interrupts a sleep
|
|
|
|
func interrupt() {
|
|
|
|
// cannot predict pid, don't want to kill group
|
|
|
|
}
|
|
|
|
|
|
|
|
func open(name string) (uintptr, error) {
|
|
|
|
fd, err := syscall.Open(name, syscall.O_RDONLY)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return uintptr(fd), nil
|
|
|
|
}
|
|
|
|
|
2018-12-28 15:30:48 +00:00
|
|
|
func read(fd uintptr, buf []byte) (int, error) {
|
|
|
|
return syscall.Read(int(fd), buf)
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:13:14 +00:00
|
|
|
func closefd(fd uintptr) {
|
|
|
|
syscall.Close(int(fd))
|
|
|
|
}
|
|
|
|
|
|
|
|
func preadn(fd uintptr, buf []byte, off int) error {
|
2017-10-07 00:16:47 +00:00
|
|
|
whence := seekStart
|
2012-03-27 23:13:14 +00:00
|
|
|
if off < 0 {
|
2017-10-07 00:16:47 +00:00
|
|
|
whence = seekEnd
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for len(buf) > 0 {
|
|
|
|
m, err := syscall.Read(int(fd), buf)
|
|
|
|
if m <= 0 {
|
|
|
|
if err == nil {
|
|
|
|
return errors.New("short read")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
buf = buf[m:]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|