]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - lib/libfdt/fdt_ro.c
fdt: Add a function to get the index of a string
[karo-tx-uboot.git] / lib / libfdt / fdt_ro.c
index cb06a9b50d8509d30bad932737687af211e59dda..fec4a0a141fdd3e556e4f7aede81417c0be81fdf 100644 (file)
@@ -511,6 +511,32 @@ int fdt_count_strings(const void *fdt, int node, const char *property)
        return count;
 }
 
+int fdt_find_string(const void *fdt, int node, const char *property,
+                   const char *string)
+{
+       const char *list, *end;
+       int len, index = 0;
+
+       list = fdt_getprop(fdt, node, property, &len);
+       if (!list)
+               return len;
+
+       end = list + len;
+       len = strlen(string);
+
+       while (list < end) {
+               int l = strlen(list);
+
+               if (l == len && memcmp(list, string, len) == 0)
+                       return index;
+
+               list += l + 1;
+               index++;
+       }
+
+       return -FDT_ERR_NOTFOUND;
+}
+
 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
                              const char *compatible)
 {