github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/misc/cgo/test/issue3729.go (about) 1 // Copyright 2012 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 // Issue 3729: cmd/cgo: access errno from void C function 6 // void f(void) returns [0]byte, error in Go world. 7 8 // +build !windows 9 10 package cgotest 11 12 /* 13 #include <errno.h> 14 15 void g(void) { 16 errno = E2BIG; 17 } 18 19 // try to pass some non-trivial arguments to function g2 20 const char _expA = 0x42; 21 const float _expB = 3.14159; 22 const short _expC = 0x55aa; 23 const int _expD = 0xdeadbeef; 24 void g2(int x, char a, float b, short c, int d) { 25 if (a == _expA && b == _expB && c == _expC && d == _expD) 26 errno = x; 27 else 28 errno = -1; 29 } 30 */ 31 import "C" 32 33 import ( 34 "syscall" 35 "testing" 36 ) 37 38 func test3729(t *testing.T) { 39 _, e := C.g() 40 if e != syscall.E2BIG { 41 t.Errorf("got %q, expect %q", e, syscall.E2BIG) 42 } 43 _, e = C.g2(C.EINVAL, C._expA, C._expB, C._expC, C._expD) 44 if e != syscall.EINVAL { 45 t.Errorf("got %q, expect %q", e, syscall.EINVAL) 46 } 47 }