jcs
/subtext
/amendments
/68
util: Add member_size and EXPAND_TO_FIT macros
jcs made amendment 68 over 2 years ago
--- util.h Wed Jan 26 10:59:17 2022
+++ util.h Sat Jan 29 16:52:36 2022
@@ -26,10 +26,20 @@
#endif
#define nitems(what) (sizeof((what)) / sizeof((what)[0]))
+#define member_size(type, member) sizeof(((type *)0)->member)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define BOUND(a, min, max) ((a) > (max) ? (max) : ((a) < (min) ? (min) : (a)))
+
+#define EXPAND_TO_FIT(var, var_size, used_size, add, grow_amount) { \
+ if ((used_size) + (add) >= (var_size)) { \
+ while ((used_size) + (add) >= (var_size)) { \
+ (var_size) += (grow_amount); \
+ } \
+ (var) = xrealloc((var), (var_size)); \
+ } \
+}
#define SCROLLBAR_WIDTH 16