blob: add blob_put_raw() for copying one or more blob attributes into the buffer...
authorFelix Fietkau <nbd@openwrt.org>
Wed, 25 Sep 2013 06:44:39 +0000 (08:44 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 4 Oct 2013 14:55:45 +0000 (16:55 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
blob.c
blob.h

diff --git a/blob.c b/blob.c
index c18f5a9..6d66fcd 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -135,6 +135,20 @@ blob_new(struct blob_buf *buf, int id, int payload)
 }
 
 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)
 {
        struct blob_attr *attr;
diff --git a/blob.h b/blob.h
index 88ee01c..846de6e 100644 (file)
--- 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)