Retro68/gcc/newlib/libc/string/strnlen.c
Wolfgang Thaller ec13cc9ce7 fix newlib
2018-12-29 09:59:36 +01:00

43 lines
744 B
C

/*
FUNCTION
<<strnlen>>---character string length
INDEX
strnlen
SYNOPSIS
#include <string.h>
size_t strnlen(const char *<[str]>, size_t <[n]>);
DESCRIPTION
The <<strnlen>> function works out the length of the string
starting at <<*<[str]>>> by counting chararacters until it
reaches a NUL character or the maximum: <[n]> number of
characters have been inspected.
RETURNS
<<strnlen>> returns the character count or <[n]>.
PORTABILITY
<<strnlen>> is a GNU extension.
<<strnlen>> requires no supporting OS subroutines.
*/
#undef __STRICT_ANSI__
#include <_ansi.h>
#include <string.h>
size_t
strnlen (const char *str,
size_t n)
{
const char *start = str;
while (n-- > 0 && *str)
str++;
return str - start;
}