This is conceptually similar to strchr(3), but there are
slight changes to account for the buffer having an explicit
buffer length.
Now that we have an optimised memchr(3), we can use it
to implement strnlen(3) with better performance. This
could perhaps be backported to the generic implementation
as strnlen(3) isn't optimised there but memchr(3) is.
The performance is competitive with glibc, although glibc
once again wins for very long strings, like due to the use
of AVX and/or AVX-512. It may be worth adding an AVX or
AVX-512 implementation of this function to trigger for
longer buffers only.
Sponsored by: The FreeBSD Foundation