Source file
src/time/sys_unix.go
1
2
3
4
5
6
7 package time
8
9 import (
10 "errors"
11 "runtime"
12 "syscall"
13 )
14
15
16 func interrupt() {
17
18
19
20
21
22 if runtime.GOOS != "wasip1" {
23 syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
24 }
25 }
26
27 func open(name string) (uintptr, error) {
28 fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
29 if err != nil {
30 return 0, err
31 }
32 return uintptr(fd), nil
33 }
34
35 func read(fd uintptr, buf []byte) (int, error) {
36 return syscall.Read(int(fd), buf)
37 }
38
39 func closefd(fd uintptr) {
40 syscall.Close(int(fd))
41 }
42
43 func preadn(fd uintptr, buf []byte, off int) error {
44 whence := seekStart
45 if off < 0 {
46 whence = seekEnd
47 }
48 if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
49 return err
50 }
51 for len(buf) > 0 {
52 m, err := syscall.Read(int(fd), buf)
53 if m <= 0 {
54 if err == nil {
55 return errors.New("short read")
56 }
57 return err
58 }
59 buf = buf[m:]
60 }
61 return nil
62 }
63
View as plain text