Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strnlen.c « string « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9a3b5e7715736f1153a1608bca082ddd9b887c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 
FUNCTION
	<<strnlen>>---character string length
	
INDEX
	strnlen

ANSI_SYNOPSIS
	#include <string.h>
	size_t strnlen(const char *<[str]>, size_t <[n]>);

TRAD_SYNOPSIS
	#include <string.h>
	size_t strnlen(<[str]>, <[n]>)
	char *<[src]>;
	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
_DEFUN (strnlen, (str, n),
	_CONST char *str _AND
	size_t n)
{
  _CONST char *start = str;

  while (*str && n-- > 0)
    str++;

  return str - start;
}