I'm trying to call some ioctls from Go, and some of them take C strings as parameters. For example, in C:
/* When the user asks to bind a message name to an interface, they use: */
struct kbus_bind_request {
__u32 is_replier; /* are we a replier? */
__u32 name_len;
char *name;
};
extern int kbus_ksock_bind(kbus_ksock_t ksock,
const char *name,
uint32_t is_replier)
{
int rv;
kbus_bind_request_t bind_request;
bind_request.name = (char *) name;
bind_request.name_len = strlen(name);
bind_request.is_replier = is_replier;
rv = ioctl(ksock, KBUS_IOC_BIND, &bind_request);
if (rv < 0)
return -errno;
else
return rv;
}
I converted the struct to a Go struc like this:
type kbus_bind_request struct {
is_replier uint32 /* are we a replier? */
name_len uint32
name unsafe.Pointer // char*
}
Now, how do I convert a Go string
to a C string stored in an unsafe.Pointer
? I don't want to use CGo as I am cross-compiling and it makes things a pain.