[PATCH v3 2/4] dtc: Add data_insert_data function

Ayush Singh <[email protected]>
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <[email protected]>
Add helper function to insert a data struct into another.

Signed-off-by: Ayush Singh <[email protected]>
---
 data.c | 27 +++++++++++++++++++++++++++
 dtc.h  |  1 +
 2 files changed, 28 insertions(+)

diff --git a/data.c b/data.c
index 913796f2e664d07cdc48e0cbf2ab5d6fe9978072..5b25aa060416134be430aebe33c9cce49515297f 100644
--- a/data.c
+++ b/data.c
@@ -251,6 +251,33 @@ bool data_is_one_string(struct data d)
 	return true;
 }
 
+struct data data_insert_data(struct data d, struct marker *m, struct data old)
+{
+	unsigned int offset = m->offset;
+	struct marker *next = m->next;
+	struct marker *marker;
+	struct data new_data;
+	char *ref;
+
+	new_data = data_insert_at_marker(d, m, old.val, old.len);
+
+	/* Copy all markers from old value */
+	marker = old.markers;
+	for_each_marker(marker) {
+		ref = NULL;
+
+		if (marker->ref)
+			ref = xstrdup(marker->ref);
+
+		m->next = alloc_marker(marker->offset + offset, marker->type,
+				       ref);
+		m = m->next;
+	}
+	m->next = next;
+
+	return new_data;
+}
+
 struct marker *alloc_marker(unsigned int offset, enum markertype type,
 			    char *ref)
 {
diff --git a/dtc.h b/dtc.h
index bd803397449a4b71ff89944ea125cefb96c4dd21..3a220b9afc99f92ea57d50d348eb0872bc779818 100644
--- a/dtc.h
+++ b/dtc.h
@@ -182,6 +182,7 @@ struct data data_append_addr(struct data d, uint64_t addr);
 struct data data_append_byte(struct data d, uint8_t byte);
 struct data data_append_zeroes(struct data d, int len);
 struct data data_append_align(struct data d, int align);
+struct data data_insert_data(struct data d, struct marker *m, struct data old);
 
 struct marker *alloc_marker(unsigned int offset, enum markertype type,
 			    char *ref);

-- 
2.49.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.