0
package main
/*
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <utmpx.h>
#include <fcntl.h>
#include <unistd.h>
char *path_utmpx = _PATH_UTMPX;
typedef struct utmpx utmpx;
*/
import "C"
import (
"fmt"
"io/ioutil"
)
type Record C.utmpx
func main() {
path := C.GoString(C.path_utmpx)
content, err := ioutil.ReadFile(path)
handleError(err)
var records []Record
// now we have the bytes(content), the struct(Record/C.utmpx)
// how can I cast bytes to struct ?
}
func handleError(err error) {
if err != nil {
panic("bad")
}
}
content
をRecord
に入力してください。 私はいくつかの関連する質問をしました。goでstruct(c struct)にバイトをキャストする方法は?
Cannot access c variables in cgo
私はいくつかの記事や記事を読みましたが、まだこれを行う方法を把握することはできません。
私はこのレポを知っており、それを読んでいます。私はただ試してみたい。ご回答有難うございます。私は 'undefined:utmp.ReadUtmp'、' undefined:utmp.UtmpxFile'を得ました。 –
私は他の答えがあるのを見て待っています。 –
GZ Xue、utmpライブラリをインストールするために 'go get github.com/ericlagergren/go-gnulib/utmp'を実行しましたか? – Mark