diff options
author | Thierry Reding <treding@nvidia.com> | 2014-08-26 17:33:50 +0200 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2014-10-11 01:05:59 +0200 |
commit | dbb170e5d4f45d29a419c80e7a746cfbbf78d231 (patch) | |
tree | cbdd2280789eb80b2a4caca35dedc8845dfcbb52 /lib/libfdt | |
parent | bf0c463942fbba4bf726865e65c9cc72551559e1 (diff) |
fdt: Add a function to count strings
Given a device tree node and a property name, the fdt_count_strings()
function counts the number of strings found in the property value.
Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/libfdt')
-rw-r--r-- | lib/libfdt/fdt_ro.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index 36af043525..cb06a9b50d 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -491,6 +491,26 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) return 0; } +int fdt_count_strings(const void *fdt, int node, const char *property) +{ + int length, i, count = 0; + const char *list; + + list = fdt_getprop(fdt, node, property, &length); + if (!list) + return -length; + + for (i = 0; i < length; i++) { + int len = strlen(list); + + list += len + 1; + i += len; + count++; + } + + return count; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) { |