syscall_darwin_amd64.go 2.0 KB

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