fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / strnlen.c
blobb9a3b5e7715736f1153a1608bca082ddd9b887c9
1 /*
2 FUNCTION
3 <<strnlen>>---character string length
5 INDEX
6 strnlen
8 ANSI_SYNOPSIS
9 #include <string.h>
10 size_t strnlen(const char *<[str]>, size_t <[n]>);
12 TRAD_SYNOPSIS
13 #include <string.h>
14 size_t strnlen(<[str]>, <[n]>)
15 char *<[src]>;
16 size_t <[n]>;
18 DESCRIPTION
19 The <<strnlen>> function works out the length of the string
20 starting at <<*<[str]>>> by counting chararacters until it
21 reaches a NUL character or the maximum: <[n]> number of
22 characters have been inspected.
24 RETURNS
25 <<strnlen>> returns the character count or <[n]>.
27 PORTABILITY
28 <<strnlen>> is a Gnu extension.
30 <<strnlen>> requires no supporting OS subroutines.
34 #undef __STRICT_ANSI__
35 #include <_ansi.h>
36 #include <string.h>
38 size_t
39 _DEFUN (strnlen, (str, n),
40 _CONST char *str _AND
41 size_t n)
43 _CONST char *start = str;
45 while (*str && n-- > 0)
46 str++;
48 return str - start;