qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen
@ 2017-10-18 22:31 John Arbuckle
  2017-10-19  1:31 ` David Gibson
  0 siblings, 1 reply; 6+ messages in thread
From: John Arbuckle @ 2017-10-18 22:31 UTC (permalink / raw)
  To: qemu-devel, david, qemu-ppc; +Cc: John Arbuckle

Implement the strnlen() function if it isn't implemented.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
 libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 3d00d2e..a7986fb 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -55,6 +55,30 @@
 
 #include "libfdt_internal.h"
 
+/* if the current environment does not define strnlen */
+#ifndef strnlen
+
+/* This eliminates the missing prototype warning */
+int strnlen(const char *string, int max_count);
+
+/*
+ * strnlen: return the length of a string or max_count
+ * which ever is shortest
+ */
+
+int strnlen(const char *string, int max_count)
+{
+    int count;
+    for(count = 0; count < max_count; count++) {
+        if (string[count] == '\0') {
+            break;
+        }
+    }
+    return count;
+}
+
+#endif /* strnlen */
+
 static int _fdt_nodename_eq(const void *fdt, int offset,
 			    const char *s, int len)
 {
-- 
2.13.5 (Apple Git-94)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-19 14:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-18 22:31 [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen John Arbuckle
2017-10-19  1:31 ` David Gibson
2017-10-19  2:39   ` Programmingkid
2017-10-19  4:11     ` David Gibson
2017-10-19  9:37       ` Peter Maydell
2017-10-19 14:54       ` Programmingkid

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).