Source file
src/time/sys_unix.go
1
2
3
4
5
6
7 package time
8
9 import (
10 "errors"
11 "syscall"
12 )
13
14
15 func interrupt() {
16 syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
17 }
18
19 func open(name string) (uintptr, error) {
20 fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
21 if err != nil {
22 return 0, err
23 }
24 return uintptr(fd), nil
25 }
26
27 func read(fd uintptr, buf []byte) (int, error) {
28 return syscall.Read(int(fd), buf)
29 }
30
31 func closefd(fd uintptr) {
32 syscall.Close(int(fd))
33 }
34
35 func preadn(fd uintptr, buf []byte, off int) error {
36 whence := seekStart
37 if off < 0 {
38 whence = seekEnd
39 }
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 }
55
View as plain text