blob: b7fba0802c2b717fa30d33fa30c5d04a7cf4b80c [file] [log] [blame]
Brent Austinba3052e2015-04-21 16:08:23 -07001// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build plan9
6
7package time
8
9import (
10 "errors"
11 "syscall"
12)
13
14// for testing: whatever interrupts a sleep
15func interrupt() {
16 // cannot predict pid, don't want to kill group
17}
18
Brent Austinba3052e2015-04-21 16:08:23 -070019func open(name string) (uintptr, error) {
20 fd, err := syscall.Open(name, syscall.O_RDONLY)
21 if err != nil {
22 return 0, err
23 }
24 return uintptr(fd), nil
25}
26
Dan Willemsena3223282018-02-27 19:41:43 -080027func read(fd uintptr, buf []byte) (int, error) {
28 return syscall.Read(int(fd), buf)
29}
30
Brent Austinba3052e2015-04-21 16:08:23 -070031func closefd(fd uintptr) {
32 syscall.Close(int(fd))
33}
34
35func preadn(fd uintptr, buf []byte, off int) error {
Dan Willemsen38f2dba2016-07-08 14:54:35 -070036 whence := seekStart
Brent Austinba3052e2015-04-21 16:08:23 -070037 if off < 0 {
Dan Willemsen38f2dba2016-07-08 14:54:35 -070038 whence = seekEnd
Brent Austinba3052e2015-04-21 16:08:23 -070039 }
40 if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
41 return err
42 }
43 for len(buf) > 0 {
44 m, err := syscall.Read(int(fd), buf)
45 if m <= 0 {
46 if err == nil {
47 return errors.New("short read")
48 }
49 return err
50 }
51 buf = buf[m:]
52 }
53 return nil
54}