blob: add blob_put_raw() for copying one or more blob attributes into the buffer directly

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2013-09-25 08:44:39 +02:00
parent 460d94d6e8
commit be458596bd
2 changed files with 15 additions and 0 deletions

14
blob.c
View file

@ -134,6 +134,20 @@ blob_new(struct blob_buf *buf, int id, int payload)
return attr;
}
struct blob_attr *
blob_put_raw(struct blob_buf *buf, const void *ptr, int len)
{
struct blob_attr *attr;
if (len < sizeof(struct blob_attr) || !ptr)
return NULL;
attr = blob_add(buf, blob_next(buf->head), 0, len - sizeof(struct blob_attr));
blob_set_raw_len(buf->head, blob_pad_len(buf->head) + len);
memcpy(attr, ptr, len);
return attr;
}
struct blob_attr *
blob_put(struct blob_buf *buf, int id, const void *ptr, int len)
{

1
blob.h
View file

@ -190,6 +190,7 @@ extern struct blob_attr *blob_put(struct blob_buf *buf, int id, const void *ptr,
extern bool blob_check_type(const void *ptr, int len, int type);
extern int blob_parse(struct blob_attr *attr, struct blob_attr **data, const struct blob_attr_info *info, int max);
extern struct blob_attr *blob_memdup(struct blob_attr *attr);
extern struct blob_attr *blob_put_raw(struct blob_buf *buf, const void *ptr, int len);
static inline struct blob_attr *
blob_put_string(struct blob_buf *buf, int id, const char *str)