1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-06-08 10:46:56 +02:00
Files
coreutils/lib/strnlen.c
T

34 lines
1.2 KiB
C
Raw Normal View History

2000-05-04 06:34:23 +00:00
/* Find the length of STRING, but scan at most MAXLEN characters.
2006-01-24 07:52:03 +00:00
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
Written by Simon Josefsson.
2000-05-04 06:34:23 +00:00
2003-07-10 07:06:25 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
2000-05-04 06:34:23 +00:00
2003-07-10 07:06:25 +00:00
This program is distributed in the hope that it will be useful,
2000-05-04 06:34:23 +00:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
2003-07-10 07:06:25 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2000-05-04 06:34:23 +00:00
2006-01-24 07:52:03 +00:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
2005-05-14 07:58:06 +00:00
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2000-05-04 06:34:23 +00:00
2005-09-22 06:05:39 +00:00
#ifdef HAVE_CONFIG_H
2000-06-04 13:20:20 +00:00
# include <config.h>
#endif
2006-01-24 07:52:03 +00:00
#include "strnlen.h"
2000-05-06 15:45:30 +00:00
2000-05-04 06:34:23 +00:00
/* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN. */
size_t
2006-01-24 07:52:03 +00:00
strnlen (const char *string, size_t maxlen)
2000-05-04 06:34:23 +00:00
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
2000-05-04 06:34:23 +00:00
}