stddef.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_STDDEF_H
  3. #define _UAPI_LINUX_STDDEF_H
  4. #include <linux/compiler_types.h>
  5. #ifndef __always_inline
  6. #define __always_inline inline
  7. #endif
  8. /**
  9. * __struct_group() - Create a mirrored named and anonyomous struct
  10. *
  11. * @TAG: The tag name for the named sub-struct (usually empty)
  12. * @NAME: The identifier name of the mirrored sub-struct
  13. * @ATTRS: Any struct attributes (usually empty)
  14. * @MEMBERS: The member declarations for the mirrored structs
  15. *
  16. * Used to create an anonymous union of two structs with identical layout
  17. * and size: one anonymous and one named. The former's members can be used
  18. * normally without sub-struct naming, and the latter can be used to
  19. * reason about the start, end, and size of the group of struct members.
  20. * The named struct can also be explicitly tagged for layer reuse, as well
  21. * as both having struct attributes appended.
  22. */
  23. #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
  24. union { \
  25. struct { MEMBERS } ATTRS; \
  26. struct TAG { MEMBERS } ATTRS NAME; \
  27. } ATTRS
  28. /**
  29. * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
  30. *
  31. * @TYPE: The type of each flexible array element
  32. * @NAME: The name of the flexible array member
  33. *
  34. * In order to have a flexible array member in a union or alone in a
  35. * struct, it needs to be wrapped in an anonymous struct with at least 1
  36. * named member, but that member can be empty.
  37. */
  38. #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
  39. struct { \
  40. struct { } __empty_ ## NAME; \
  41. TYPE NAME[]; \
  42. }
  43. #endif