diff options
author | Oliver O'Halloran <oohall@gmail.com> | 2017-09-15 15:40:54 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-09-15 02:49:27 -0500 |
commit | c77b9747531b79badb69bcd2e8c25fb250fa48d2 (patch) | |
tree | 5f1f656344c198ecf91407c0380990f23f94979a /libc/string | |
parent | d60fdbce2b4b4cebe325b7f7a0f63beb2bf187be (diff) | |
download | skiboot-c77b9747531b79badb69bcd2e8c25fb250fa48d2.zip skiboot-c77b9747531b79badb69bcd2e8c25fb250fa48d2.tar.gz skiboot-c77b9747531b79badb69bcd2e8c25fb250fa48d2.tar.bz2 |
libc: add strnlen()
Sometimes handy.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc/string')
-rw-r--r-- | libc/string/strlen.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libc/string/strlen.c b/libc/string/strlen.c index 95b99d2..5b408e7 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; +} |