linux_stddef.h 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef _LINUX_STDDEF_H
  2. #define _LINUX_STDDEF_H
  3. #undef NULL
  4. #if defined(__cplusplus)
  5. #define NULL 0
  6. #else
  7. #define NULL ((void *)0)
  8. #endif
  9. #undef offsetof
  10. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  11. /**
  12. * container_of - cast a member of a structure out to the containing structure
  13. *
  14. * @ptr: the pointer to the member.
  15. * @type: the type of the container struct this is embedded in.
  16. * @member: the name of the member within the struct.
  17. *
  18. */
  19. #define container_of(ptr, type, member) ({ \
  20. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  21. (type *)( (char *)__mptr - offsetof(type,member) );})
  22. /*
  23. * Check at compile time that something is of a particular type.
  24. * Always evaluates to 1 so you may use it easily in comparisons.
  25. */
  26. #define typecheck(type,x) \
  27. ({ type __dummy; \
  28. typeof(x) __dummy2; \
  29. (void)(&__dummy == &__dummy2); \
  30. 1; \
  31. })
  32. #endif