michael@428: /* Find the length of STRING, but scan at most MAXLEN characters. michael@428: Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. michael@428: Written by Simon Josefsson. michael@428: michael@428: This program is free software; you can redistribute it and/or modify michael@428: it under the terms of the GNU General Public License as published by michael@428: the Free Software Foundation; either version 2, or (at your option) michael@428: any later version. michael@428: michael@428: This program is distributed in the hope that it will be useful, michael@428: but WITHOUT ANY WARRANTY; without even the implied warranty of michael@428: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@428: GNU General Public License for more details. michael@428: michael@428: You should have received a copy of the GNU General Public License michael@428: along with this program; if not, write to the Free Software Foundation, michael@428: Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ michael@428: michael@428: #include michael@428: michael@428: #include michael@428: michael@428: /* Find the length of STRING, but scan at most MAXLEN characters. michael@428: If no '\0' terminator is found in that many characters, return MAXLEN. */ michael@428: michael@428: size_t michael@428: strnlen (const char *string, size_t maxlen) michael@428: { michael@428: const char *end = memchr (string, '\0', maxlen); michael@428: return end ? (size_t) (end - string) : maxlen; michael@428: }