diff mbox series

[1/5] Factorize function to count elements in array of strings

Message ID 20181101170635.13493-1-sbabic@denx.de
State Changes Requested
Headers show
Series [1/5] Factorize function to count elements in array of strings | expand

Commit Message

Stefano Babic Nov. 1, 2018, 5:06 p.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/util.c    | 16 ++++++++++++++++
 include/util.h |  1 +
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index 15d38b7..a357ea3 100644
--- a/core/util.c
+++ b/core/util.c
@@ -481,6 +481,22 @@  char** string_split(const char* in, const char d)
 	return result;
 }
 
+/*
+ * Count number of elements in an array of strings
+ * Last item must have a NULL terminator
+ */
+unsigned int count_string_array(const char **nodes)
+{
+	const char **iter = nodes;
+	int count = 0;
+
+	while (*iter != NULL) {
+		iter++;
+		count++;
+	}
+	return count;
+}
+
 unsigned long long ustrtoull(const char *cp, unsigned int base)
 {
 	errno = 0;
diff --git a/include/util.h b/include/util.h
index 06f4a83..0a95967 100644
--- a/include/util.h
+++ b/include/util.h
@@ -179,6 +179,7 @@  void get_sw_versions(char *cfgfname, struct swupdate_cfg *sw);
 __u64 version_to_number(const char *version_string);
 int check_hw_compatibility(struct swupdate_cfg *cfg);
 int count_elem_list(struct imglist *list);
+unsigned int count_string_array(const char **nodes);
 
 /* Decryption key functions */
 int load_decryption_key(char *fname);