Autoconf 检查结构群 [英] Autoconf check for struct flock

查看:26
本文介绍了Autoconf 检查结构群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

fcntl() uses struct flock structure to define and check file locks. Unfortunately, on different Unix systems the fields in this structure are in different order. Does anybody know how one could check for it with autoconf or at least check if the structure is in specific format (e.g. the question would be - does the struct format matches the Linux format)?

推荐答案

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

You can use this autoconf macro to find if a certain member of struct flock exists:

AC_CHECK_MEMBERS([struct flock.l_type],[],[],[[#include <fcntl.h>]])

Github 有各种 autoconf 文件,您可以通过 在 *.ac 文件中搜索struct flock".

Github has a variety of autoconf files you can look at for additional ideas by searching for "struct flock" in *.ac files.

更新:struct flock 顺序的问题是在 debian-bugs 列表的旧帖子中讨论过.

我们可以从那个 bug 中汲取灵感并在 configure 中做到这一点:

We could take inspiration from that bug and do this in configure:

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") )

您也可以在运行时在您的程序中执行此检查,它不必是配置步骤.

You can also do this check in your program at runtime, it doesn't have to be a configure step.

这篇关于Autoconf 检查结构群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆