diff options
author | Ayke van Laethem <[email protected]> | 2024-11-06 14:57:56 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2024-11-20 07:53:59 +0100 |
commit | 6593cf22fad6fab2a201ed00c2cc20c76e29161a (patch) | |
tree | 929fba3e751e9665844c2e7c8b2783a872ccb1dd /testdata/cgo/main.go | |
parent | 548fba82e691b125bdac71f6c393f67fcf4d769f (diff) | |
download | tinygo-6593cf22fad6fab2a201ed00c2cc20c76e29161a.tar.gz tinygo-6593cf22fad6fab2a201ed00c2cc20c76e29161a.zip |
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).
Diffstat (limited to 'testdata/cgo/main.go')
-rw-r--r-- | testdata/cgo/main.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go index 00e0ba01d..38d11386a 100644 --- a/testdata/cgo/main.go +++ b/testdata/cgo/main.go @@ -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)) |