syscall_darwin_386.go 1.8 KB

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