From 58aec3c59a53147c7d924c823f7405218fb5f555 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 12 Mar 2014 20:08:27 +0100 Subject: blobmsg: allow data/length iterator/accessor functions to work on non-blobmsg elements This primarily helps with simplifying the ubus APIs. blobmsg header presence is indicated by the BLOB_ATTR_EXTENDED bit in the id_len field. This changes the format ABI, but not the API. Signed-off-by: Felix Fietkau --- blobmsg.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'blobmsg.h') diff --git a/blobmsg.h b/blobmsg.h index 4619643..e9e0e6e 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -65,7 +65,12 @@ static inline int blobmsg_type(const struct blob_attr *attr) static inline void *blobmsg_data(const struct blob_attr *attr) { struct blobmsg_hdr *hdr = (struct blobmsg_hdr *) blob_data(attr); - return (char *) hdr + blobmsg_hdrlen(be16_to_cpu(hdr->namelen)); + char *data = blob_data(attr); + + if (blob_is_extended(attr)) + data += blobmsg_hdrlen(be16_to_cpu(hdr->namelen)); + + return data; } static inline int blobmsg_data_len(const struct blob_attr *attr) -- cgit v1.2.3