1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:54:40 -07:00

syscall: fix FreeBSD 386 sendfile

The previous version was not handling an off_t (64 bit)
parameter on 32 bit i386 systems.  This patch splits sendfile
into two implementations in their respective arch-specific files.
Tested on FreeBSD amd64 and i386.

R=bradfitz
CC=golang-dev
https://golang.org/cl/6356048
This commit is contained in:
David G. Andersen 2012-07-03 08:16:43 -07:00 committed by Brad Fitzpatrick
parent a0c688331f
commit 7b6541a593
3 changed files with 28 additions and 12 deletions

View File

@ -89,18 +89,6 @@ func Pipe(p []int) (err error) {
return return
} }
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
var writtenOut uint64 = 0
_, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0, 0)
written = int(writtenOut)
if e1 != 0 {
err = e1
}
return
}
func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) { func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) {
var value IPMreqn var value IPMreqn
vallen := _Socklen(SizeofIPMreqn) vallen := _Socklen(SizeofIPMreqn)

View File

@ -4,6 +4,8 @@
package syscall package syscall
import "unsafe"
func Getpagesize() int { return 4096 } func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
@ -41,4 +43,16 @@ func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length) cmsg.Len = uint32(length)
} }
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
var writtenOut uint64 = 0
_, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0)
written = int(writtenOut)
if e1 != 0 {
err = e1
}
return
}
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic

View File

@ -4,6 +4,8 @@
package syscall package syscall
import "unsafe"
func Getpagesize() int { return 4096 } func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
@ -41,4 +43,16 @@ func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length) cmsg.Len = uint32(length)
} }
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
var writtenOut uint64 = 0
_, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0, 0)
written = int(writtenOut)
if e1 != 0 {
err = e1
}
return
}
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)