1 /* Find the length of STRING, but scan at most MAXLEN characters.
2 Copyright (C) 1991-2024 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, see <https://www.gnu.org/licenses/>. */
20 /* Find the length of S, but scan at most MAXLEN characters. If no
21 '\0' terminator is found in that many characters, return MAXLEN. */
24 # define __strnlen STRNLEN
28 __strnlen (const char *str
, size_t maxlen
)
30 const char *found
= memchr (str
, '\0', maxlen
);
31 return found
? found
- str
: maxlen
;
35 weak_alias (__strnlen
, strnlen
)
36 libc_hidden_def (__strnlen
)
37 libc_hidden_def (strnlen
)