Mercurial > hg > CbC > CbC_gcc
comparison libiberty/strnlen.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Portable version of strnlen. | |
2 This function is in the public domain. */ | |
3 | |
4 /* | |
5 | |
6 @deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen}) | |
7 | |
8 Returns the length of @var{s}, as with @code{strlen}, but never looks | |
9 past the first @var{maxlen} characters in the string. If there is no | |
10 '\0' character in the first @var{maxlen} characters, returns | |
11 @var{maxlen}. | |
12 | |
13 @end deftypefn | |
14 | |
15 */ | |
16 | |
17 #include "config.h" | |
18 | |
19 #include <stddef.h> | |
20 | |
21 size_t | |
22 strnlen (const char *s, size_t maxlen) | |
23 { | |
24 size_t i; | |
25 | |
26 for (i = 0; i < maxlen; ++i) | |
27 if (s[i] == '\0') | |
28 break; | |
29 return i; | |
30 } |