Module Name:    src
Committed By:   jmcneill
Date:           Sat Jul  8 12:36:51 UTC 2017

Modified Files:
        src/sys/dev/fdt: fdt_subr.c fdtvar.h

Log Message:
Add fdtbus_get_string_index helper.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/fdt/fdt_subr.c
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/fdt/fdtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.15 src/sys/dev/fdt/fdt_subr.c:1.16
--- src/sys/dev/fdt/fdt_subr.c:1.15	Sun Jul  2 15:27:58 2017
+++ src/sys/dev/fdt/fdt_subr.c	Sat Jul  8 12:36:51 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.15 2017/07/02 15:27:58 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.15 2017/07/02 15:27:58 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -422,3 +422,23 @@ fdtbus_get_string(int phandle, const cha
 
 	return fdt_getprop(fdtbus_get_data(), off, prop, NULL);
 }
+
+const char *
+fdtbus_get_string_index(int phandle, const char *prop, u_int index)
+{
+	const char *names, *name;
+	int len, cur;
+
+	if ((len = OF_getproplen(phandle, prop)) < 0)
+		return NULL;
+
+	names = fdtbus_get_string(phandle, prop);
+
+	for (name = names, cur = 0; len > 0;
+	     name += strlen(name) + 1, cur++) {
+		if (index == cur)
+			return name;
+	}
+
+	return NULL;
+}

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.23 src/sys/dev/fdt/fdtvar.h:1.24
--- src/sys/dev/fdt/fdtvar.h:1.23	Sun Jul  2 15:27:58 2017
+++ src/sys/dev/fdt/fdtvar.h	Sat Jul  8 12:36:51 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.23 2017/07/02 15:27:58 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.24 2017/07/08 12:36:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -297,6 +297,7 @@ bool		fdtbus_status_okay(int);
 
 const void *	fdtbus_get_prop(int, const char *, int *);
 const char *	fdtbus_get_string(int, const char *);
+const char *	fdtbus_get_string_index(int, const char *, u_int);
 
 int		fdtbus_print(void *, const char *);
 

Reply via email to