mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-02 09:46:37 +03:00
abuf: Add a function to copy a buffer
It is useful to be able to copy an abuf, to allow changes while preserving the original. Add a function for this. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
14
lib/abuf.c
14
lib/abuf.c
@@ -128,6 +128,20 @@ bool abuf_init_size(struct abuf *buf, size_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool abuf_copy(const struct abuf *old, struct abuf *copy)
|
||||
{
|
||||
char *data;
|
||||
|
||||
data = malloc(old->size);
|
||||
if (!data)
|
||||
return false;
|
||||
memcpy(data, old->data, old->size);
|
||||
abuf_init_set(copy, data, old->size);
|
||||
copy->alloced = true;
|
||||
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user