bfs icon indicating copy to clipboard operation
bfs copied to clipboard

It reports "C.__off_t" error when build bfs/store

Open hyqhyq3 opened this issue 9 years ago • 4 comments

I got error when building bfs/store

github.com/Terry-Mao/bfs/store/os

./fadvise_linux.go:26: cannot use C.__off_t(off) (type C.__off_t) as type C.off_t in argument to _Cfunc_posix_fadvise ./fadvise_linux.go:26: cannot use C.__off_t(size) (type C.__off_t) as type C.off_t in argument to _Cfunc_posix_fadvise

// if change C.__off_t to C.off_t, it works
 if errno = int(C.posix_fadvise(C.int(fd), C.__off_t(off), C.__off_t(size), C.int(advise))); errno != 0 {
                err = syscall.Errno(errno)
        }

hyqhyq3 avatar Mar 04 '16 08:03 hyqhyq3

这个好蛋疼,我在debian 下面,必须要 C.__off_t ,理论上C的__off_t 是内部类型,但是死活找不到C.off_t ,这个求PR。

Terry-Mao avatar Mar 17 '16 03:03 Terry-Mao

是不是和Go的版本有关系?试过 1.6 吗?

shanggl avatar Jun 27 '16 06:06 shanggl

试了go 1.6,同样的问题 现在有两个解决思路,第一个是定义一个wrapper函数,通过cgo调用这个wrapper函数,由wrapper函数调用posix_fadvise。这样可以解决编译的问题,但是多了一层函数调用。 /* #define _XOPEN_SOURCE 600 #include <unistd.h> #include <fcntl.h> int fadvise(int fd, off_t offset, off_t len, int advice) { return posix_fadvise(fd, offset, len, advice); } */

func Fadvise(fd uintptr, off int64, size int64, advise int) (err error) { var errno int if errno = int(C.fadvise(C.int(fd), C.off_t(off), C.off_t(size), C.int(advise))); errno != 0 { err = syscall.Errno(errno) } return }

另外一个思路是定义_FILE_OFFSET_BITS=64,在我尝试的几个环境里,off_t都被转换成__off64_t,不确定是否在其它环境下可以工作,并且此时不管是32位还是64位环境,off_t参数全都是64位的了,和定义off_t类型的目的是矛盾的。 /* #define _FILE_OFFSET_BITS 64 #define _XOPEN_SOURCE 600 #include <unistd.h> #include <fcntl.h> */

func Fadvise(fd uintptr, off int64, size int64, advise int) (err error) { var errno int if errno = int(C.fadvise(C.int(fd), C.__off64_t(off), C.__off64_t(size), C.int(advise))); errno != 0 { err = syscall.Errno(errno) } return }

libingbuaa avatar Jan 12 '17 09:01 libingbuaa

@libingbuaa 看起来一个更好,我试试

Terry-Mao avatar Jan 15 '17 14:01 Terry-Mao