diff options
Diffstat (limited to 'lib/string/strnlen.c')
| -rw-r--r-- | lib/string/strnlen.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/string/strnlen.c b/lib/string/strnlen.c new file mode 100644 index 0000000..8931c52 --- /dev/null +++ b/lib/string/strnlen.c @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: MIT */ +/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ + +#include <string.h> + +size_t strnlen(const char *s, size_t n) +{ + const char *p = memchr(s, 0, n); + return p ? p-s : n; +} |
