2002-05-25 07:44:39 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<strnlen>>---character string length
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
strnlen
|
|
|
|
|
2017-11-30 16:20:06 +08:00
|
|
|
SYNOPSIS
|
2002-05-25 07:44:39 +08:00
|
|
|
#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
|
2005-10-29 05:21:08 +08:00
|
|
|
<<strnlen>> is a GNU extension.
|
2002-05-25 07:44:39 +08:00
|
|
|
|
|
|
|
<<strnlen>> requires no supporting OS subroutines.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef __STRICT_ANSI__
|
|
|
|
#include <_ansi.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
size_t
|
|
|
|
_DEFUN (strnlen, (str, n),
|
|
|
|
_CONST char *str _AND
|
|
|
|
size_t n)
|
|
|
|
{
|
|
|
|
_CONST char *start = str;
|
|
|
|
|
2006-02-14 01:27:50 +08:00
|
|
|
while (n-- > 0 && *str)
|
2002-05-25 07:44:39 +08:00
|
|
|
str++;
|
|
|
|
|
|
|
|
return str - start;
|
|
|
|
}
|