1 // Copyright 2018 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.
17 const direntSize = 8 + 8 + 2 + 256
24 func direntIno(buf []byte) (uint64, bool) {
28 func direntReclen(buf []byte) (uint64, bool) {
29 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
32 func direntNamlen(buf []byte) (uint64, bool) {
33 reclen, ok := direntReclen(buf)
37 return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
42 // An Errno is an unsigned number describing an error condition.
43 // It implements the error interface. The zero Errno is by convention
44 // a non-error, so code to convert from Errno to error should use:
51 // Errno values can be tested against error values using errors.Is.
54 // _, _, err := syscall.Syscall(...)
55 // if errors.Is(err, fs.ErrNotExist) ...
58 func (e Errno) Error() string {
59 if 0 <= int(e) && int(e) < len(errorstr) {
65 return "errno " + itoa.Itoa(int(e))
68 func (e Errno) Is(target error) bool {
70 case oserror.ErrPermission:
71 return e == EACCES || e == EPERM
72 case oserror.ErrExist:
73 return e == EEXIST || e == ENOTEMPTY
74 case oserror.ErrNotExist:
76 case errorspkg.ErrUnsupported:
77 return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
82 func (e Errno) Temporary() bool {
83 return e == EINTR || e == EMFILE || e.Timeout()
86 func (e Errno) Timeout() bool {
87 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
90 // A Signal is a number describing a process signal.
91 // It implements the os.Signal interface.
104 func (s Signal) Signal() {}
106 func (s Signal) String() string {
107 if 0 <= s && int(s) < len(signals) {
113 return "signal " + itoa.Itoa(int(s))
116 var signals = [...]string{}
165 S_IFSHM_SYSV = 0000300000
166 S_IFSEMA = 0000270000
167 S_IFCOND = 0000260000
168 S_IFMUTEX = 0000250000
170 S_IFBOUNDSOCK = 0000230000
171 S_IFSOCKADDR = 0000220000
172 S_IFDSOCK = 0000210000
174 S_IFSOCK = 0000140000
228 // Not supported - just enough for package os.
230 var ForkLock sync.RWMutex
232 type WaitStatus uint32
234 func (w WaitStatus) Exited() bool { return false }
235 func (w WaitStatus) ExitStatus() int { return 0 }
236 func (w WaitStatus) Signaled() bool { return false }
237 func (w WaitStatus) Signal() Signal { return 0 }
238 func (w WaitStatus) CoreDump() bool { return false }
239 func (w WaitStatus) Stopped() bool { return false }
240 func (w WaitStatus) Continued() bool { return false }
241 func (w WaitStatus) StopSignal() Signal { return 0 }
242 func (w WaitStatus) TrapCause() int { return 0 }
251 type ProcAttr struct {
258 type SysProcAttr struct {
261 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
265 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
269 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
273 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
277 func Sysctl(key string) (string, error) {
278 if key == "kern.hostname" {
284 const ImplementsGetwd = true
286 func Getwd() (wd string, err error) {
287 var buf [PathMax]byte
288 n, err := Getcwd(buf[0:])
292 return string(buf[:n]), nil
296 return jsProcess.Call("getuid").Int()
300 return jsProcess.Call("getgid").Int()
304 return jsProcess.Call("geteuid").Int()
308 return jsProcess.Call("getegid").Int()
311 func Getgroups() (groups []int, err error) {
312 defer recoverErr(&err)
313 array := jsProcess.Call("getgroups")
314 groups = make([]int, array.Length())
315 for i := range groups {
316 groups[i] = array.Index(i).Int()
322 return jsProcess.Get("pid").Int()
326 return jsProcess.Get("ppid").Int()
329 func Umask(mask int) (oldmask int) {
330 return jsProcess.Call("umask", mask).Int()
333 func Gettimeofday(tv *Timeval) error { return ENOSYS }
335 func Kill(pid int, signum Signal) error { return ENOSYS }
336 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
339 func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
342 func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
346 type Iovec struct{} // dummy
348 type Timespec struct {
353 type Timeval struct {
358 func setTimespec(sec, nsec int64) Timespec {
359 return Timespec{Sec: sec, Nsec: nsec}
362 func setTimeval(sec, usec int64) Timeval {
363 return Timeval{Sec: sec, Usec: usec}