]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Implement strnlen()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sun, 12 Apr 2015 00:28:38 +0000 (01:28 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 28 Sep 2015 13:53:02 +0000 (14:53 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/libc/string.c
include/xtf/libc.h

index c35a84cfdead0c557b7a0223141bc91a2a135452..8bf2a3bbc767c64a9a392bcc06a68fcf8041a018 100644 (file)
@@ -10,6 +10,16 @@ size_t strlen(const char *str)
     return s - str;
 }
 
+size_t strnlen(const char *str, size_t max)
+{
+    const char *s = str;
+
+    while ( max-- && *s != '\0' )
+        ++s;
+
+    return s - str;
+}
+
 /*
  * Local variables:
  * mode: C
index ae5ede9b9f33af790a35bbfd76ff95cafaf38c04..a794d0a4c96eebfbdfd23a4c6759157adde67e6e 100644 (file)
@@ -16,6 +16,7 @@
 #define strlen(s)                   __builtin_strlen(s)
 
 size_t strlen(const char *str);
+size_t strnlen(const char *str, size_t max);
 
 #endif /* XTF_LIBC_H */