blob: add blob_put_raw() for copying one or more blob attributes into the buffer...
[project/libubox.git] / blob.c
diff --git a/blob.c b/blob.c
index c18f5a955450633e70a562f015ea65c7e15e6e6b..6d66fcdb85ce04b61363afb0742a6127faf16247 100644 (file)
--- 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)
 {