diff options
author | Thierry Reding <treding@nvidia.com> | 2015-09-29 11:09:08 +0200 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2015-09-30 13:26:31 +1000 |
commit | 604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e (patch) | |
tree | 9316f9c3d5fc3918b48926a2e99335b3ce02b934 /libfdt/fdt_ro.c | |
parent | 8702bd1d3b430c16aaa37056cb24b6d984da48f7 (diff) | |
download | device-tree-compiler-604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e.tar.gz |
fdt: Add functions to retrieve strings
Given a device tree node, a property name and an index, the new function
fdt_stringlist_get() will return a pointer to the index'th string in the
property's value and return its length (or an error code on failure) in
an output argument.
Signed-off-by: Thierry Reding <treding@nvidia.com>
[Fix some -Wshadow warnings --dwg]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt/fdt_ro.c')
-rw-r--r-- | libfdt/fdt_ro.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 2d74c37..e5b3136 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -593,6 +593,51 @@ int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, return -FDT_ERR_NOTFOUND; } +const char *fdt_stringlist_get(const void *fdt, int nodeoffset, + const char *property, int idx, + int *lenp) +{ + const char *list, *end; + int length; + + list = fdt_getprop(fdt, nodeoffset, property, &length); + if (!list) { + if (lenp) + *lenp = length; + + return NULL; + } + + end = list + length; + + while (list < end) { + length = strnlen(list, end - list) + 1; + + /* Abort if the last string isn't properly NUL-terminated. */ + if (list + length > end) { + if (lenp) + *lenp = -FDT_ERR_BADVALUE; + + return NULL; + } + + if (idx == 0) { + if (lenp) + *lenp = length - 1; + + return list; + } + + list += length; + idx--; + } + + if (lenp) + *lenp = -FDT_ERR_NOTFOUND; + + return NULL; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) { |