2011-09-16 17:47:21 +02: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.
|
|
|
|
|
2018-09-24 23:46:21 +02:00
|
|
|
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
package time
|
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"syscall"
|
|
|
|
)
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
// for testing: whatever interrupts a sleep
|
|
|
|
func interrupt() {
|
2011-12-13 20:16:27 +01:00
|
|
|
syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
|
2011-10-27 01:57:58 +02:00
|
|
|
}
|
2012-01-12 02:31:45 +01:00
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
func open(name string) (uintptr, error) {
|
|
|
|
fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return uintptr(fd), nil
|
|
|
|
}
|
|
|
|
|
2018-01-09 02:23:08 +01:00
|
|
|
func read(fd uintptr, buf []byte) (int, error) {
|
|
|
|
return syscall.Read(int(fd), buf)
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
func closefd(fd uintptr) {
|
|
|
|
syscall.Close(int(fd))
|
|
|
|
}
|
|
|
|
|
|
|
|
func preadn(fd uintptr, buf []byte, off int) error {
|
2016-07-22 20:15:38 +02:00
|
|
|
whence := seekStart
|
2012-03-02 21:01:37 +01:00
|
|
|
if off < 0 {
|
2016-07-22 20:15:38 +02:00
|
|
|
whence = seekEnd
|
2012-03-02 21:01:37 +01: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
|
|
|
|
}
|