1
私はGoからいくつかのioctlを呼び出そうとしており、そのうちのいくつかはパラメータとしてC文字列を取ります。たとえば、Cに:CGoを使わずに文字列を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;
}
私はこのような囲碁STRUCに構造体を変換:今すぐ
type kbus_bind_request struct {
is_replier uint32 /* are we a replier? */
name_len uint32
name unsafe.Pointer // char*
}
、どのように私はunsafe.Pointer
に保存されたC文字列に移動string
を変換するのですか?私はクロスコンパイルをしているので、CGoを使いたくないので、状況が苦しくなります。
一つは、通常、 'NAME'フィールド' * byte'ではなく 'unsafe.Pointer'になるだろう。 https://golang.org/pkg/syscall/#Iovec – JimB
のようなsyscallパッケージの例を探してください。 – Timmmm