Autoconf 检查结构群

编程入门 行业动态 更新时间:2024-10-26 20:21:46
本文介绍了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 检查结构群

本文发布于:2023-11-02 15:13:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:结构   Autoconf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!