strnlen1.c

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

Generated on Fri Oct 5 18:20:26 2007 for WvStreams by  doxygen 1.5.3