cgo: support errno value as second return parameter

Making this work on all targets was interesting but there's now a test
in place to make sure this works on all targets that have the CGo test
enabled (which is almost all targets).
This commit is contained in:
Ayke van Laethem
2024-11-06 14:57:56 +01:00
committed by Ayke
parent 548fba82e6
commit 6593cf22fa
23 changed files with 263 additions and 16 deletions
+11 -1
View File
@@ -18,7 +18,10 @@ import "C"
// static int headerfunc_static(int a) { return a - 1; }
import "C"
import "unsafe"
import (
"syscall"
"unsafe"
)
func main() {
println("fortytwo:", C.fortytwo())
@@ -168,6 +171,13 @@ func main() {
println("len(C.GoBytes(C.CBytes(nil),0)):", len(C.GoBytes(C.CBytes(nil), 0)))
println(`rountrip CBytes:`, C.GoString((*C.char)(C.CBytes([]byte("hello\000")))))
// Check that errno is returned from the second return value, and that it
// matches the errno value that was just set.
_, errno := C.set_errno(C.EINVAL)
println("EINVAL:", errno == syscall.EINVAL)
_, errno = C.set_errno(C.EAGAIN)
println("EAGAIN:", errno == syscall.EAGAIN)
// libc: test whether C functions work at all.
buf1 := []byte("foobar\x00")
buf2 := make([]byte, len(buf1))