(root)/
glibc-2.38/
string/
strnlen.c
       1  /* Find the length of STRING, but scan at most MAXLEN characters.
       2     Copyright (C) 1991-2023 Free Software Foundation, Inc.
       3  
       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.
       8  
       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.
      13  
      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/>.  */
      17  
      18  #include <string.h>
      19  
      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.  */
      22  
      23  #ifdef STRNLEN
      24  # define __strnlen STRNLEN
      25  #endif
      26  
      27  size_t
      28  __strnlen (const char *str, size_t maxlen)
      29  {
      30    const char *found = memchr (str, '\0', maxlen);
      31    return found ? found - str : maxlen;
      32  }
      33  
      34  #ifndef STRNLEN
      35  weak_alias (__strnlen, strnlen)
      36  libc_hidden_def (__strnlen)
      37  libc_hidden_def (strnlen)
      38  #endif