aw_common.h 656 B

1234567891011121314151617181920212223
  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  4. #ifndef offsetof
  5. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  6. #endif
  7. /**
  8. * container_of - cast a member of a structure out to the containing structure
  9. * @ptr: the pointer to the member.
  10. * @type: the type of the container struct this is embedded in.
  11. * @member: the name of the member within the struct.
  12. *
  13. */
  14. #define container_of(ptr, type, member) ({ \
  15. const typeof(((type *)0)->member) * __mptr = (ptr); \
  16. (type *)((char *)__mptr - offsetof(type, member)); })
  17. #define UNUSED(var) {(void)var;}
  18. #endif /*COMMON_H*/