mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] imd: use struct imd_header * as argument
@ 2016-03-29  8:50 Sascha Hauer
  2016-03-29  8:50 ` [PATCH 2/7] imd: string returned from imd_string_data should be const Sascha Hauer
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Sascha Hauer @ 2016-03-29  8:50 UTC (permalink / raw)
  To: Barebox List

imd_concat_strings() and imd_string_data() are easier to handle when
they take a struct imd_header * instead of a struct imd_entry_string *.
Change this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/imd.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/common/imd.c b/common/imd.c
index f84e344..acaa23f 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -193,11 +193,14 @@ static uint32_t imd_name_to_type(const char *name)
 	return IMD_TYPE_INVALID;
 }
 
-static char *imd_string_data(struct imd_entry_string *imd_string, int index)
+static char *imd_string_data(struct imd_header *imd, int index)
 {
 	int i, total = 0, l = 0;
-	int len = imd_read_length(&imd_string->header);
-	char *p = imd_string->data;
+	int len = imd_read_length(imd);
+	char *p = (char *)(imd + 1);
+
+	if (!imd_is_string(imd->type))
+		return NULL;
 
 	for (i = 0; total < len; total += l, p += l) {
 		l = strlen(p) + 1;
@@ -208,16 +211,20 @@ static char *imd_string_data(struct imd_entry_string *imd_string, int index)
 	return NULL;
 }
 
-static char *imd_concat_strings(struct imd_entry_string *imd_string)
+static char *imd_concat_strings(struct imd_header *imd)
 {
-	int i, len = imd_read_length(&imd_string->header);
+	int i, len = imd_read_length(imd);
 	char *str;
+	char *data = (char *)(imd + 1);
+
+	if (!imd_is_string(imd->type))
+		return NULL;
 
 	str = malloc(len);
 	if (!str)
 		return NULL;
 
-	memcpy(str, imd_string->data, len);
+	memcpy(str, data, len);
 
 	for (i = 0; i < len - 1; i++)
 		if (str[i] == 0)
@@ -284,10 +291,7 @@ int imd_command(int argc, char *argv[])
 			uint32_t type = imd_read_type(imd);
 
 			if (imd_is_string(type)) {
-				struct imd_entry_string *imd_string =
-					(struct imd_entry_string *)imd;
-
-				str = imd_concat_strings(imd_string);
+				str = imd_concat_strings(imd);
 
 				printf("%s: %s\n", imd_type_to_name(type), str);
 			} else {
@@ -302,13 +306,10 @@ int imd_command(int argc, char *argv[])
 		}
 
 		if (imd_is_string(type)) {
-			struct imd_entry_string *imd_string =
-				(struct imd_entry_string *)imd;
-
 			if (strno >= 0)
-				str = imd_string_data(imd_string, strno);
+				str = imd_string_data(imd, strno);
 			else
-				str = imd_concat_strings(imd_string);
+				str = imd_concat_strings(imd);
 
 			if (!str)
 				return -ENODATA;
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-04-01  8:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-29  8:50 [PATCH 1/7] imd: use struct imd_header * as argument Sascha Hauer
2016-03-29  8:50 ` [PATCH 2/7] imd: string returned from imd_string_data should be const Sascha Hauer
2016-03-29  9:34   ` Stefan Christ
2016-04-01  8:43     ` Sascha Hauer
2016-03-29  8:50 ` [PATCH 3/7] scripts: Add scripts/include/ to include path for target programs Sascha Hauer
2016-03-29  8:50 ` [PATCH 4/7] imd: rename imd_search_validate to imd_get Sascha Hauer
2016-03-29  8:50 ` [PATCH 5/7] imd: export functions Sascha Hauer
2016-03-29  8:50 ` [PATCH 6/7] imd: Add function to read parameters Sascha Hauer
2016-03-29  8:50 ` [PATCH 7/7] bbu: print and evaluate image Metadata Sascha Hauer
2016-03-29  9:29   ` Stefan Christ
2016-04-01  8:41     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox