Loading...
include/struct.h Libc-583 Libc-1272.200.26
--- Libc/Libc-583/include/struct.h
+++ Libc/Libc-1272.200.26/include/struct.h
@@ -48,4 +48,21 @@
 #define	strbase(name, addr, field) \
 	((struct name *)((char *)(addr) - fldoff(name, field)))
 
+/* Number of elements in a statically-defined array */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && __GNUC__
+#define countof(arr) ({ \
+	_Static_assert( \
+			!__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0])), \
+			"array must be statically defined"); \
+	(sizeof(arr) / sizeof(arr[0])); \
+})
+#else
+#define countof(arr) \
+	(sizeof(arr) / sizeof(arr[0]))
+#endif
+
+/* Length of a statically-defined string (does not include null terminator) */
+#define lenof(str) \
+	(sizeof(str) - 1)
+
 #endif /* !_STRUCT_H_ */