61 a[i] = _Gid_t(v) |
61 a[i] = _Gid_t(v) |
62 } |
62 } |
63 return setgroups(len(a), &a[0]) |
63 return setgroups(len(a), &a[0]) |
64 } |
64 } |
65 |
65 |
66 func ReadDirent(fd int, buf []byte) (n int, err error) { |
|
67 // Final argument is (basep *uintptr) and the syscall doesn't take nil. |
|
68 // 64 bits should be enough. (32 bits isn't even on 386). Since the |
|
69 // actual system call is getdirentries64, 64 is a good guess. |
|
70 // TODO(rsc): Can we use a single global basep for all calls? |
|
71 var base = (*uintptr)(unsafe.Pointer(new(uint64))) |
|
72 return Getdirentries(fd, buf, base) |
|
73 } |
|
74 |
|
75 // Wait status is 7 bits at bottom, either 0 (exited), |
66 // Wait status is 7 bits at bottom, either 0 (exited), |
76 // 0x7F (stopped), or a signal number that caused an exit. |
67 // 0x7F (stopped), or a signal number that caused an exit. |
77 // The 0x80 bit is whether there was a core dump. |
68 // The 0x80 bit is whether there was a core dump. |
78 // An extra number (exit code, signal causing a stop) |
69 // An extra number (exit code, signal causing a stop) |
79 // is in the high bits. |
70 // is in the high bits. |
109 } |
101 } |
110 |
102 |
111 func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 } |
103 func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 } |
112 |
104 |
113 func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP } |
105 func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP } |
|
106 |
|
107 func (w WaitStatus) Killed() bool { return w&mask == killed && syscall.Signal(w>>shift) != SIGKILL } |
114 |
108 |
115 func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP } |
109 func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP } |
116 |
110 |
117 func (w WaitStatus) StopSignal() syscall.Signal { |
111 func (w WaitStatus) StopSignal() syscall.Signal { |
118 if !w.Stopped() { |
112 if !w.Stopped() { |
417 event = unsafe.Pointer(&events[0]) |
411 event = unsafe.Pointer(&events[0]) |
418 } |
412 } |
419 return kevent(kq, change, len(changes), event, len(events), timeout) |
413 return kevent(kq, change, len(changes), event, len(events), timeout) |
420 } |
414 } |
421 |
415 |
422 //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL |
|
423 |
|
424 // sysctlmib translates name to mib number and appends any additional args. |
416 // sysctlmib translates name to mib number and appends any additional args. |
425 func sysctlmib(name string, args ...int) ([]_C_int, error) { |
417 func sysctlmib(name string, args ...int) ([]_C_int, error) { |
426 // Translate name to mib number. |
418 // Translate name to mib number. |
427 mib, err := nametomib(name) |
419 mib, err := nametomib(name) |
428 if err != nil { |
420 if err != nil { |
514 } |
506 } |
515 |
507 |
516 // The actual call may return less than the original reported required |
508 // The actual call may return less than the original reported required |
517 // size so ensure we deal with that. |
509 // size so ensure we deal with that. |
518 return buf[:n], nil |
510 return buf[:n], nil |
|
511 } |
|
512 |
|
513 func SysctlClockinfo(name string) (*Clockinfo, error) { |
|
514 mib, err := sysctlmib(name) |
|
515 if err != nil { |
|
516 return nil, err |
|
517 } |
|
518 |
|
519 n := uintptr(SizeofClockinfo) |
|
520 var ci Clockinfo |
|
521 if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { |
|
522 return nil, err |
|
523 } |
|
524 if n != SizeofClockinfo { |
|
525 return nil, EIO |
|
526 } |
|
527 return &ci, nil |
519 } |
528 } |
520 |
529 |
521 //sys utimes(path string, timeval *[2]Timeval) (err error) |
530 //sys utimes(path string, timeval *[2]Timeval) (err error) |
522 |
531 |
523 func Utimes(path string, tv []Timeval) error { |
532 func Utimes(path string, tv []Timeval) error { |
582 if len(tv) != 2 { |
591 if len(tv) != 2 { |
583 return EINVAL |
592 return EINVAL |
584 } |
593 } |
585 return futimes(fd, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) |
594 return futimes(fd, (*[2]Timeval)(unsafe.Pointer(&tv[0]))) |
586 } |
595 } |
587 |
|
588 //sys fcntl(fd int, cmd int, arg int) (val int, err error) |
|
589 |
596 |
590 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) |
597 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) |
591 |
598 |
592 func Poll(fds []PollFd, timeout int) (n int, err error) { |
599 func Poll(fds []PollFd, timeout int) (n int, err error) { |
593 if len(fds) == 0 { |
600 if len(fds) == 0 { |