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>
diff --git a/lib/abuf.c b/lib/abuf.c
index 61adf7f..3cbe320 100644
--- a/lib/abuf.c
+++ b/lib/abuf.c
@@ -119,6 +119,15 @@
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 */