Autoconf检查struct flock

Sta*_*asM 13 c unix linux autoconf autotools

fcntl()使用struct flock结构来定义和检查文件锁.不幸的是,在不同的Unix系统上,这种结构中的字段顺序不同.有没有人知道如何使用autoconf检查它或至少检查结构是否采用特定格式(例如,问题是 - 结构格式是否与Linux格式匹配)?

pat*_*net 3

您可以使用此 autoconf 宏来查找某个成员是否struct flock存在:

AC_CHECK_MEMBERS([struct flock.l_type],[],[],[[#include <fcntl.h>]])
Run Code Online (Sandbox Code Playgroud)

Github 有各种 autoconf 文件,您可以通过在 *.ac 文件中搜索“struct集群”来查看更多想法。

更新:debian-bugs 列表上的一篇旧文章讨论了struct flock顺序问题。

我们可以从该错误中获得灵感并在配置中执行此操作:

AC_MSG_CHECKING("whether flock struct is linux ordered or not")
AC_TRY_RUN([
  #include <fcntl.h>
  struct flock lock = { 1, 2, 3, 4, 5 };
  int main() { return lock.l_type==1 ? 0 : 1; }
], [
    AC_DEFINE(HAVE_FLOCK_LINUX) 
    AC_MSG_RESULT("yes")
], AC_MSG_RESULT("no") )
Run Code Online (Sandbox Code Playgroud)

您还可以在运行时在程序中执行此检查,它不一定是配置步骤。