aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2022-11-27 19:02:46 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2022-12-03 17:03:36 +0100
commitda60273fc6af89c37a14f80aa7b76bb570e82968 (patch)
tree51a4491268f8441d1c802931ed95e978f5fa316a
parente2d7896795bed7483fb08ff47801afdbd7cd9849 (diff)
downloadbackports-da60273fc6af89c37a14f80aa7b76bb570e82968.tar.gz
headers: Add DECLARE_FLEX_ARRAY()
Copy this from kernel 5.15.80. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--backport/backport-include/linux/stddef.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/backport/backport-include/linux/stddef.h b/backport/backport-include/linux/stddef.h
index a6cdc67d..a0765ef3 100644
--- a/backport/backport-include/linux/stddef.h
+++ b/backport/backport-include/linux/stddef.h
@@ -23,4 +23,37 @@
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
#endif
+#ifndef __DECLARE_FLEX_ARRAY
+/**
+ * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
+ *
+ * @TYPE: The type of each flexible array element
+ * @NAME: The name of the flexible array member
+ *
+ * In order to have a flexible array member in a union or alone in a
+ * struct, it needs to be wrapped in an anonymous struct with at least 1
+ * named member, but that member can be empty.
+ */
+#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
+ struct { \
+ struct { } __empty_ ## NAME; \
+ TYPE NAME[]; \
+ }
+#endif
+
+#ifndef DECLARE_FLEX_ARRAY
+/**
+ * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
+ *
+ * @TYPE: The type of each flexible array element
+ * @NAME: The name of the flexible array member
+ *
+ * In order to have a flexible array member in a union or alone in a
+ * struct, it needs to be wrapped in an anonymous struct with at least 1
+ * named member, but that member can be empty.
+ */
+#define DECLARE_FLEX_ARRAY(TYPE, NAME) \
+ __DECLARE_FLEX_ARRAY(TYPE, NAME)
+#endif
+
#endif /* __BACKPORT_LINUX_STDDEF_H */