[Skiboot] [PATCH 09/14] libc: add strnlen()
Oliver O'Halloran
oohall at gmail.com
Fri Sep 15 15:40:54 AEST 2017
Sometimes handy.
Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
libc/include/string.h | 1 +
libc/string/strlen.c | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/libc/include/string.h b/libc/include/string.h
index e4b4fac95ef9..2172bdcbf9f5 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -25,6 +25,7 @@ int strncasecmp(const char *s1, const char *s2, size_t n);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
size_t strlen(const char *s);
+size_t strnlen(const char *s, size_t n);
char *strstr(const char *hay, const char *needle);
char *strtok(char *src, const char *pattern);
char *strdup(const char *src);
diff --git a/libc/string/strlen.c b/libc/string/strlen.c
index 95b99d25455f..5b408e7ef899 100644
--- a/libc/string/strlen.c
+++ b/libc/string/strlen.c
@@ -25,3 +25,16 @@ strlen(const char *s)
return len;
}
+size_t
+strnlen(const char *s, size_t n)
+{
+ size_t len = 0;
+
+ while (*s != 0 && n) {
+ len += 1;
+ s += 1;
+ n--;
+ }
+
+ return len;
+}
--
2.9.5
More information about the Skiboot
mailing list