mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
common/utils.h: add tal_arr_expand helper.
We do this a lot, and had boutique helpers in various places. So add a more generic one; for convenience it returns a pointer to the new end element. I prefer the name tal_arr_expand to tal_arr_append, since it's up to the caller to populate the new array entry. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
d590302523
commit
96f05549b2
@@ -19,6 +19,16 @@ char *tal_hex(const tal_t *ctx, const tal_t *data);
|
||||
/* Allocate and fill a buffer with the data of this hex string. */
|
||||
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
|
||||
|
||||
/* Helper macro to extend tal_arr and return pointer new last element. */
|
||||
#if HAVE_STATEMENT_EXPR
|
||||
/* More efficient version calls tal_count() once */
|
||||
#define tal_arr_expand(p) \
|
||||
({ size_t n = tal_count(*p); tal_resize((p), n+1); *(p) + n; })
|
||||
#else
|
||||
#define tal_arr_expand(p) \
|
||||
(tal_resize((p), tal_count(*(p))+1), (*p) + tal_count(*(p))-1)
|
||||
#endif
|
||||
|
||||
/* Use the POSIX C locale. */
|
||||
void setup_locale(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user