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

查看:77
本文介绍了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的文件,你可以通过<一看更多的想法href=\"https://github.com/search?q=extension%3Am4+extension%3Aac+%22struct+flock%22&ref=searchresults&type=$c$c\"相对=nofollow>搜索在* .AC文件结构羊群。

更新: struct flock的秩序的问题的在一个旧后在debian-错误列表上讨论。

我们可以从错误中汲取灵感,并在配置做到这一点:

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天全站免登陆