blob: add blob_buf_grow()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
9a3519536b
commit
b786f85267
2 changed files with 13 additions and 6 deletions
18
blob.c
18
blob.c
|
@ -50,6 +50,17 @@ attr_to_offset(struct blob_buf *buf, struct blob_attr *attr)
|
||||||
return (char *)attr - (char *) buf->buf;
|
return (char *)attr - (char *) buf->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
blob_buf_grow(struct blob_buf *buf, int required)
|
||||||
|
{
|
||||||
|
int offset_head = attr_to_offset(buf, buf->head);
|
||||||
|
|
||||||
|
if (!buf->grow || !buf->grow(buf, required))
|
||||||
|
return;
|
||||||
|
|
||||||
|
buf->head = offset_to_attr(buf, offset_head);
|
||||||
|
}
|
||||||
|
|
||||||
static struct blob_attr *
|
static struct blob_attr *
|
||||||
blob_add(struct blob_buf *buf, struct blob_attr *pos, int id, int payload)
|
blob_add(struct blob_buf *buf, struct blob_attr *pos, int id, int payload)
|
||||||
{
|
{
|
||||||
|
@ -58,12 +69,7 @@ blob_add(struct blob_buf *buf, struct blob_attr *pos, int id, int payload)
|
||||||
struct blob_attr *attr;
|
struct blob_attr *attr;
|
||||||
|
|
||||||
if (required > 0) {
|
if (required > 0) {
|
||||||
int offset_head = attr_to_offset(buf, buf->head);
|
blob_buf_grow(buf, required);
|
||||||
|
|
||||||
if (!buf->grow || !buf->grow(buf, required))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
buf->head = offset_to_attr(buf, offset_head);
|
|
||||||
attr = offset_to_attr(buf, offset);
|
attr = offset_to_attr(buf, offset);
|
||||||
} else {
|
} else {
|
||||||
attr = pos;
|
attr = pos;
|
||||||
|
|
1
blob.h
1
blob.h
|
@ -238,6 +238,7 @@ extern void blob_set_raw_len(struct blob_attr *attr, unsigned int len);
|
||||||
extern bool blob_attr_equal(const struct blob_attr *a1, const struct blob_attr *a2);
|
extern bool blob_attr_equal(const struct blob_attr *a1, const struct blob_attr *a2);
|
||||||
extern int blob_buf_init(struct blob_buf *buf, int id);
|
extern int blob_buf_init(struct blob_buf *buf, int id);
|
||||||
extern void blob_buf_free(struct blob_buf *buf);
|
extern void blob_buf_free(struct blob_buf *buf);
|
||||||
|
extern void blob_buf_grow(struct blob_buf *buf, int required);
|
||||||
extern struct blob_attr *blob_new(struct blob_buf *buf, int id, int payload);
|
extern struct blob_attr *blob_new(struct blob_buf *buf, int id, int payload);
|
||||||
extern void *blob_nest_start(struct blob_buf *buf, int id);
|
extern void *blob_nest_start(struct blob_buf *buf, int id);
|
||||||
extern void blob_nest_end(struct blob_buf *buf, void *cookie);
|
extern void blob_nest_end(struct blob_buf *buf, void *cookie);
|
||||||
|
|
Loading…
Reference in a new issue