00001 /* Find the length of STRING, but scan at most MAXLEN characters. 00002 Copyright (C) 1996, 1997, 1998, 2000-2003 Free Software Foundation, Inc. 00003 This file is part of the GNU C Library. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU Lesser General Public License as published by 00007 the Free Software Foundation; either version 2.1, or (at your option) 00008 any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public License along 00016 with this program; if not, write to the Free Software Foundation, 00017 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 00018 00019 #ifdef HAVE_CONFIG_H 00020 # include <config.h> 00021 #endif 00022 #undef strnlen 00023 00024 #include <string.h> 00025 00026 #undef __strnlen 00027 #undef strnlen 00028 00029 #ifndef _LIBC 00030 # define strnlen rpl_strnlen 00031 #endif 00032 00033 #ifndef weak_alias 00034 # define __strnlen strnlen 00035 #endif 00036 00037 /* Find the length of STRING, but scan at most MAXLEN characters. 00038 If no '\0' terminator is found in that many characters, return MAXLEN. */ 00039 00040 size_t 00041 __strnlen (const char *string, size_t maxlen) 00042 { 00043 const char *end = memchr (string, '\0', maxlen); 00044 return end ? (size_t) (end - string) : maxlen; 00045 } 00046 #ifdef weak_alias 00047 weak_alias (__strnlen, strnlen) 00048 #endif