github.com/dolotech/hongbao@v0.0.0-20191130105438-fd59d7a5dda5/src/golang.org/x/sys/unix/syscall_freebsd_386.go (about) 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 5 // +build 386,freebsd 6 7 package unix 8 9 import ( 10 "syscall" 11 "unsafe" 12 ) 13 14 func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 16 func NsecToTimespec(nsec int64) (ts Timespec) { 17 ts.Sec = int32(nsec / 1e9) 18 ts.Nsec = int32(nsec % 1e9) 19 return 20 } 21 22 func NsecToTimeval(nsec int64) (tv Timeval) { 23 nsec += 999 // round up to microsecond 24 tv.Usec = int32(nsec % 1e9 / 1e3) 25 tv.Sec = int32(nsec / 1e9) 26 return 27 } 28 29 func SetKevent(k *Kevent_t, fd, mode, flags int) { 30 k.Ident = uint32(fd) 31 k.Filter = int16(mode) 32 k.Flags = uint16(flags) 33 } 34 35 func (iov *Iovec) SetLen(length int) { 36 iov.Len = uint32(length) 37 } 38 39 func (msghdr *Msghdr) SetControllen(length int) { 40 msghdr.Controllen = uint32(length) 41 } 42 43 func (cmsg *Cmsghdr) SetLen(length int) { 44 cmsg.Len = uint32(length) 45 } 46 47 func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 48 var writtenOut uint64 = 0 49 _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 50 51 written = int(writtenOut) 52 53 if e1 != 0 { 54 err = e1 55 } 56 return 57 } 58 59 func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)