From be458596bd13f0a708d52efaa5c70bac2f8fe97d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 25 Sep 2013 08:44:39 +0200 Subject: [PATCH] blob: add blob_put_raw() for copying one or more blob attributes into the buffer directly Signed-off-by: Felix Fietkau --- blob.c | 14 ++++++++++++++ blob.h | 1 + 2 files changed, 15 insertions(+) diff --git a/blob.c b/blob.c index c18f5a9..6d66fcd 100644 --- a/blob.c +++ b/blob.c @@ -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) { diff --git a/blob.h b/blob.h index 88ee01c..846de6e 100644 --- a/blob.h +++ b/blob.h @@ -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) -- 2.25.1