|
| 1 | +package syscall |
| 2 | + |
| 3 | +// Most code here has been copied from the Go sources: |
| 4 | +// https://github.com/golang/go/blob/go1.12/src/syscall/syscall_js.go |
| 5 | +// It has the following copyright note: |
| 6 | +// |
| 7 | +// Copyright 2018 The Go Authors. All rights reserved. |
| 8 | +// Use of this source code is governed by a BSD-style |
| 9 | +// license that can be found in the LICENSE file. |
| 10 | + |
| 11 | +// An Errno is an unsigned number describing an error condition. |
| 12 | +// It implements the error interface. The zero Errno is by convention |
| 13 | +// a non-error, so code to convert from Errno to error should use: |
| 14 | +// err = nil |
| 15 | +// if errno != 0 { |
| 16 | +// err = errno |
| 17 | +// } |
| 18 | +type Errno uintptr |
| 19 | + |
| 20 | +func (e Errno) Error() string { |
| 21 | + if 0 <= int(e) && int(e) < len(errorstr) { |
| 22 | + s := errorstr[e] |
| 23 | + if s != "" { |
| 24 | + return s |
| 25 | + } |
| 26 | + } |
| 27 | + return "errno " + itoa(int(e)) |
| 28 | +} |
| 29 | + |
| 30 | +func (e Errno) Temporary() bool { |
| 31 | + return e == EINTR || e == EMFILE || e.Timeout() |
| 32 | +} |
| 33 | + |
| 34 | +func (e Errno) Timeout() bool { |
| 35 | + return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT |
| 36 | +} |
| 37 | + |
| 38 | +// A Signal is a number describing a process signal. |
| 39 | +// It implements the os.Signal interface. |
| 40 | +type Signal int |
| 41 | + |
| 42 | +const ( |
| 43 | + _ Signal = iota |
| 44 | + SIGCHLD |
| 45 | + SIGINT |
| 46 | + SIGKILL |
| 47 | + SIGTRAP |
| 48 | + SIGQUIT |
| 49 | + SIGTERM |
| 50 | +) |
| 51 | + |
| 52 | +// File system |
| 53 | + |
| 54 | +const ( |
| 55 | + Stdin = 0 |
| 56 | + Stdout = 1 |
| 57 | + Stderr = 2 |
| 58 | +) |
| 59 | + |
| 60 | +const ( |
| 61 | + O_RDONLY = 0 |
| 62 | + O_WRONLY = 1 |
| 63 | + O_RDWR = 2 |
| 64 | + |
| 65 | + O_CREAT = 0100 |
| 66 | + O_CREATE = O_CREAT |
| 67 | + O_TRUNC = 01000 |
| 68 | + O_APPEND = 02000 |
| 69 | + O_EXCL = 0200 |
| 70 | + O_SYNC = 010000 |
| 71 | + |
| 72 | + O_CLOEXEC = 0 |
| 73 | +) |
| 74 | + |
| 75 | +func Getenv(key string) (value string, found bool) { |
| 76 | + return "", false // stub |
| 77 | +} |
| 78 | + |
| 79 | +func Open(path string, mode int, perm uint32) (fd int, err error) { |
| 80 | + return 0, ENOSYS |
| 81 | +} |
| 82 | + |
| 83 | +func Read(fd int, p []byte) (n int, err error) { |
| 84 | + return 0, ENOSYS |
| 85 | +} |
| 86 | + |
| 87 | +func Seek(fd int, offset int64, whence int) (off int64, err error) { |
| 88 | + return 0, ENOSYS |
| 89 | +} |
| 90 | + |
| 91 | +func Close(fd int) (err error) { |
| 92 | + return ENOSYS |
| 93 | +} |
| 94 | + |
| 95 | +// Processes |
| 96 | + |
| 97 | +type WaitStatus uint32 |
| 98 | + |
| 99 | +func (w WaitStatus) Exited() bool { return false } |
| 100 | +func (w WaitStatus) ExitStatus() int { return 0 } |
| 101 | +func (w WaitStatus) Signaled() bool { return false } |
| 102 | +func (w WaitStatus) Signal() Signal { return 0 } |
| 103 | +func (w WaitStatus) CoreDump() bool { return false } |
| 104 | +func (w WaitStatus) Stopped() bool { return false } |
| 105 | +func (w WaitStatus) Continued() bool { return false } |
| 106 | +func (w WaitStatus) StopSignal() Signal { return 0 } |
| 107 | +func (w WaitStatus) TrapCause() int { return 0 } |
| 108 | + |
| 109 | +// XXX made up |
| 110 | +type Rusage struct { |
| 111 | + Utime Timeval |
| 112 | + Stime Timeval |
| 113 | +} |
| 114 | + |
| 115 | +// XXX made up |
| 116 | +type ProcAttr struct { |
| 117 | + Dir string |
| 118 | + Env []string |
| 119 | + Files []uintptr |
| 120 | + Sys *SysProcAttr |
| 121 | +} |
| 122 | + |
| 123 | +type SysProcAttr struct { |
| 124 | +} |
| 125 | + |
| 126 | +func Getegid() int { return 1 } |
| 127 | +func Geteuid() int { return 1 } |
| 128 | +func Getgid() int { return 1 } |
| 129 | +func Getgroups() ([]int, error) { return []int{1}, nil } |
| 130 | +func Getppid() int { return 2 } |
| 131 | +func Getpid() int { return 3 } |
| 132 | +func Gettimeofday(tv *Timeval) error { return ENOSYS } |
| 133 | +func Getuid() int { return 1 } |
| 134 | +func Kill(pid int, signum Signal) error { return ENOSYS } |
| 135 | +func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { |
| 136 | + return 0, ENOSYS |
| 137 | +} |
| 138 | +func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) { |
| 139 | + return 0, 0, ENOSYS |
| 140 | +} |
| 141 | +func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) { |
| 142 | + return 0, ENOSYS |
| 143 | +} |
| 144 | + |
| 145 | +type Timeval struct { |
| 146 | + Sec int64 |
| 147 | + Usec int64 |
| 148 | +} |
0 commit comments