syscall_freebsd_386.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 386,freebsd
  5. package unix
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  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. func SetKevent(k *Kevent_t, fd, mode, flags int) {
  22. k.Ident = uint32(fd)
  23. k.Filter = int16(mode)
  24. k.Flags = uint16(flags)
  25. }
  26. func (iov *Iovec) SetLen(length int) {
  27. iov.Len = uint32(length)
  28. }
  29. func (msghdr *Msghdr) SetControllen(length int) {
  30. msghdr.Controllen = uint32(length)
  31. }
  32. func (cmsg *Cmsghdr) SetLen(length int) {
  33. cmsg.Len = uint32(length)
  34. }
  35. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  36. var writtenOut uint64 = 0
  37. _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0)
  38. written = int(writtenOut)
  39. if e1 != 0 {
  40. err = e1
  41. }
  42. return
  43. }
  44. func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)