mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
6593cf22fa
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).
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import "syscall"
|
|
import "unsafe"
|
|
|
|
var _ unsafe.Pointer
|
|
|
|
//go:linkname C.CString runtime.cgo_CString
|
|
func C.CString(string) *C.char
|
|
|
|
//go:linkname C.GoString runtime.cgo_GoString
|
|
func C.GoString(*C.char) string
|
|
|
|
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
|
func C.__GoStringN(*C.char, uintptr) string
|
|
|
|
func C.GoStringN(cstr *C.char, length C.int) string {
|
|
return C.__GoStringN(cstr, uintptr(length))
|
|
}
|
|
|
|
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
|
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
|
|
|
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
|
return C.__GoBytes(ptr, uintptr(length))
|
|
}
|
|
|
|
//go:linkname C.__CBytes runtime.cgo_CBytes
|
|
func C.__CBytes([]byte) unsafe.Pointer
|
|
|
|
func C.CBytes(b []byte) unsafe.Pointer {
|
|
return C.__CBytes(b)
|
|
}
|
|
|
|
//go:linkname C.__get_errno_num runtime.cgo_errno
|
|
func C.__get_errno_num() uintptr
|
|
|
|
func C.__get_errno() error {
|
|
return syscall.Errno(C.__get_errno_num())
|
|
}
|
|
|
|
type (
|
|
C.char uint8
|
|
C.schar int8
|
|
C.uchar uint8
|
|
C.short int16
|
|
C.ushort uint16
|
|
C.int int32
|
|
C.uint uint32
|
|
C.long int32
|
|
C.ulong uint32
|
|
C.longlong int64
|
|
C.ulonglong uint64
|
|
)
|