0f31d51743
A blob is a piece of data of variable length that belongs in a blob list while a data stream is a buffer used to move data between blobs among other things. Signed-off-by: Chloe M. <chloe@mirocom.org>
49 lines
808 B
C
49 lines
808 B
C
/*
|
|
* Copyright (c) 2026, Chloe M.
|
|
* Provided under the BSD-3 clause
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include "blobchain/blob.h"
|
|
#include "blobchain/memlib.h"
|
|
|
|
int
|
|
blob_list_init(struct blob_list *lp)
|
|
{
|
|
if (lp == NULL) {
|
|
errno = -EINVAL;
|
|
return -1;
|
|
}
|
|
|
|
lp->count = 0;
|
|
lp->head = NULL;
|
|
lp->tail = NULL;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
blob_list_append(struct blob_list *lp, struct blob *blob)
|
|
{
|
|
if (lp == NULL || blob == NULL) {
|
|
errno = -EINVAL;
|
|
return -1;
|
|
}
|
|
|
|
/* Create a head if needed */
|
|
if (lp->head == NULL) {
|
|
lp->head = blob;
|
|
}
|
|
|
|
/* Append the blob to the list */
|
|
if (lp->tail == NULL) {
|
|
lp->tail = blob;
|
|
} else {
|
|
lp->tail->next = blob;
|
|
lp->tail = blob;
|
|
}
|
|
|
|
++lp->count;
|
|
return 0;
|
|
return 0;
|
|
}
|