annotate libiberty/strnlen.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Portable version of strnlen.
kono
parents:
diff changeset
2 This function is in the public domain. */
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 /*
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 @deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 Returns the length of @var{s}, as with @code{strlen}, but never looks
kono
parents:
diff changeset
9 past the first @var{maxlen} characters in the string. If there is no
kono
parents:
diff changeset
10 '\0' character in the first @var{maxlen} characters, returns
kono
parents:
diff changeset
11 @var{maxlen}.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 @end deftypefn
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 */
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 #include "config.h"
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 #include <stddef.h>
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 size_t
kono
parents:
diff changeset
22 strnlen (const char *s, size_t maxlen)
kono
parents:
diff changeset
23 {
kono
parents:
diff changeset
24 size_t i;
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 for (i = 0; i < maxlen; ++i)
kono
parents:
diff changeset
27 if (s[i] == '\0')
kono
parents:
diff changeset
28 break;
kono
parents:
diff changeset
29 return i;
kono
parents:
diff changeset
30 }