diff options
author | Simon Glass <sjg@chromium.org> | 2025-05-01 07:37:01 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2025-05-30 09:49:31 +0100 |
commit | 97b586695cd80821455ae06ee178c6c8cf759ce6 (patch) | |
tree | 51e652168f67b87cfc9fd044079d83a2b574ba7f /lib/abuf.c | |
parent | a619c4410956f446510749b6dc3989849616b7a0 (diff) |
abuf: Add a helper for initing and allocating a buffer
This construct appears in various places. Reduce code size by adding a
function for it.
It inits the abuf, then allocates it to the requested size.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/abuf.c')
-rw-r--r-- | lib/abuf.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/abuf.c b/lib/abuf.c index 61adf7fc6b1..3cbe320fb08 100644 --- a/lib/abuf.c +++ b/lib/abuf.c @@ -119,6 +119,15 @@ void abuf_init_set(struct abuf *abuf, void *data, size_t size) abuf_set(abuf, data, size); } +bool abuf_init_size(struct abuf *buf, size_t size) +{ + abuf_init(buf); + if (!abuf_realloc(buf, size)) + return false; + + return true; +} + void abuf_init_const(struct abuf *abuf, const void *data, size_t size) { /* for now there is no flag indicating that the abuf data is constant */ |