//export udf_fileexists_go_init
func udf_fileexists_go_init(initid *C.UDF_INIT, args *C.UDF_ARGS, message *C.char) C.my_bool {
	if args.arg_count != 1 {
		msg := "udf_fileexists_go() requires one string argument\n"
		C.strcpy(message, C.CString(msg))
		return 1
	}

	return 0
}
Beispiel #2
0
func strcpy(dst *C.char, capacity int, src string) error {
	if 0 == len(src) {
		return nil
	}
	if capacity < len(src) {
		return errors.New("string too long.")
	}
	s := C.CString(src)
	//IncrementMemory()
	C.strcpy(dst, s)
	C.free(unsafe.Pointer(s))
	//DecrementMemory()
	return nil
}
Beispiel #3
0
func main() {
	p := C.malloc(C.size_t(1))
	if p == nil {
		C.perror(C.CString("malloc failure"))
	}
	defer C.free(p)
	C.strcpy((*C.char)(p), (*C.char)(C.CString("123")))
	C.strcat((*C.char)(p), C.CString("233"))
	fmt.Printf(C.GoString((*C.char)(p)))

	ts := C.malloc(C.size_t(unsafe.Sizeof(C.struct_Test{})))
	if ts == nil {
		C.perror(C.CString("malloc struct"))
	}
	defer C.free(ts)
}
//export PutMemberDescription
func PutMemberDescription(objIdx C.uint32_t, ifIdx C.uint32_t,
	memberIdx C.uint32_t, argIdx C.uint32_t,
	language *C.char, dest *C.char, maxlen C.uint32_t) {

	desc := memberDescriptionProvider(int(objIdx), int(ifIdx), int(memberIdx), int(argIdx), C.GoString(language))

	if len(desc) >= int(maxlen) {
		desc = desc[0:int(maxlen)]
	}

	buff := C.CString(desc)
	defer C.free(unsafe.Pointer(buff))
	C.strcpy(dest, buff)
	//	for i := 0; i < len(desc) && i < int(maxlen); i++ {
	//		dest  = C.char(desc[i])
	//	}
}
Beispiel #5
0
func copyStringToCPointer(text string, target *C.char) {
	cMsg := C.CString(text)
	defer C.free(unsafe.Pointer(cMsg))
	C.strcpy(target, cMsg)
}