source: trunk/libs/newlib/src/newlib/libc/string/strnlen.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 744 bytes
Line 
1/*
2FUNCTION
3        <<strnlen>>---character string length
4       
5INDEX
6        strnlen
7
8SYNOPSIS
9        #include <string.h>
10        size_t strnlen(const char *<[str]>, size_t <[n]>);
11
12DESCRIPTION
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.
17
18RETURNS
19        <<strnlen>> returns the character count or <[n]>.
20
21PORTABILITY
22<<strnlen>> is a GNU extension.
23
24<<strnlen>> requires no supporting OS subroutines.
25
26*/
27
28#undef __STRICT_ANSI__
29#include <_ansi.h>
30#include <string.h>
31
32size_t
33strnlen (const char *str,
34        size_t n)
35{
36  const char *start = str;
37
38  while (n-- > 0 && *str)
39    str++;
40
41  return str - start;
42}
Note: See TracBrowser for help on using the repository browser.