summaryrefslogtreecommitdiffstats
path: root/m4/fr_check_struct_has_member.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/fr_check_struct_has_member.m4')
-rw-r--r--m4/fr_check_struct_has_member.m436
1 files changed, 36 insertions, 0 deletions
diff --git a/m4/fr_check_struct_has_member.m4 b/m4/fr_check_struct_has_member.m4
new file mode 100644
index 0000000..57d8b02
--- /dev/null
+++ b/m4/fr_check_struct_has_member.m4
@@ -0,0 +1,36 @@
+dnl #
+dnl # Look for a header file in a number of places.
+dnl #
+dnl # Usage: FR_CHECK_STRUCT_HAS_MEMBER([#include <foo.h>], [struct foo], member)
+dnl # If the member is defined, then the variable
+dnl # ac_cv_type_struct_foo_has_member is set to 'yes'
+dnl #
+AC_DEFUN([FR_CHECK_STRUCT_HAS_MEMBER], [
+ AC_MSG_CHECKING([for $3 in $2])
+
+dnl BASED on 'offsetof':
+dnl #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+dnl
+
+ AC_TRY_COMPILE([
+$1
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
+#endif
+],
+ [ int foo = offsetof($2, $3) ],
+ has_element=" ",
+ has_element=)
+
+ ac_safe_type=`echo "$2" | sed 'y% %_%'`
+ if test "x$has_element" != "x"; then
+ AC_MSG_RESULT(yes)
+ eval "ac_cv_type_${ac_safe_type}_has_$3=yes"
+ else
+ AC_MSG_RESULT(no)
+ eval "ac_cv_type_${ac_safe_type}_has_$3="
+ fi
+])