@@ -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);
@@ -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;
+}
Sometimes handy. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> --- libc/include/string.h | 1 + libc/string/strlen.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)