syscall_darwin_arm.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2015 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.
  4. package unix
  5. import (
  6. "syscall"
  7. "unsafe"
  8. )
  9. func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
  10. func NsecToTimespec(nsec int64) (ts Timespec) {
  11. ts.Sec = int32(nsec / 1e9)
  12. ts.Nsec = int32(nsec % 1e9)
  13. return
  14. }
  15. func NsecToTimeval(nsec int64) (tv Timeval) {
  16. nsec += 999 // round up to microsecond
  17. tv.Usec = int32(nsec % 1e9 / 1e3)
  18. tv.Sec = int32(nsec / 1e9)
  19. return
  20. }
  21. //sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error)
  22. func Gettimeofday(tv *Timeval) (err error) {
  23. // The tv passed to gettimeofday must be non-nil
  24. // but is otherwise unused. The answers come back
  25. // in the two registers.
  26. sec, usec, err := gettimeofday(tv)
  27. tv.Sec = int32(sec)
  28. tv.Usec = int32(usec)
  29. return err
  30. }
  31. func SetKevent(k *Kevent_t, fd, mode, flags int) {
  32. k.Ident = uint32(fd)
  33. k.Filter = int16(mode)
  34. k.Flags = uint16(flags)
  35. }
  36. func (iov *Iovec) SetLen(length int) {
  37. iov.Len = uint32(length)
  38. }
  39. func (msghdr *Msghdr) SetControllen(length int) {
  40. msghdr.Controllen = uint32(length)
  41. }
  42. func (cmsg *Cmsghdr) SetLen(length int) {
  43. cmsg.Len = uint32(length)
  44. }
  45. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  46. var length = uint64(count)
  47. _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(*offset>>32), uintptr(unsafe.Pointer(&length)), 0, 0, 0, 0)
  48. written = int(length)
  49. if e1 != 0 {
  50. err = e1
  51. }
  52. return
  53. }
  54. func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) // sic