Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / strnlen.c
blob3ee18d1c00ed97f57e12d5c298cf6ffd7b30abd6
1 /*
2 FUNCTION
3 <<strnlen>>---character string length
5 INDEX
6 strnlen
8 SYNOPSIS
9 #include <string.h>
10 size_t strnlen(const char *<[str]>, size_t <[n]>);
12 DESCRIPTION
13 The <<strnlen>> function works out the length of the string
14 starting at <<*<[str]>>> by counting chararacters until it
15 reaches a NUL character or the maximum: <[n]> number of
16 characters have been inspected.
18 RETURNS
19 <<strnlen>> returns the character count or <[n]>.
21 PORTABILITY
22 <<strnlen>> is a GNU extension.
24 <<strnlen>> requires no supporting OS subroutines.
28 #undef __STRICT_ANSI__
29 #include <_ansi.h>
30 #include <string.h>
32 size_t
33 strnlen (const char *str,
34 size_t n)
36 const char *start = str;
38 while (n-- > 0 && *str)
39 str++;
41 return str - start;