coreutils/lib/strnlen.c

49 lines
1.4 KiB
C
Raw Normal View History

2000-05-04 14:34:23 +08:00
/* Find the length of STRING, but scan at most MAXLEN characters.
2003-08-18 17:44:49 +08:00
Copyright (C) 1996, 1997, 1998, 2000-2003 Free Software Foundation, Inc.
2000-05-04 14:34:23 +08:00
This file is part of the GNU C Library.
2003-07-10 15:06:25 +08: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 14:34:23 +08:00
2003-07-10 15:06:25 +08:00
This program is distributed in the hope that it will be useful,
2000-05-04 14:34:23 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
2003-07-10 15:06:25 +08:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2000-05-04 14:34:23 +08:00
2003-07-10 15:06:25 +08: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 15:58:06 +08:00
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2000-05-04 14:34:23 +08:00
2000-06-04 21:20:20 +08:00
#if HAVE_CONFIG_H
# include <config.h>
#endif
2003-08-18 17:44:49 +08:00
#undef strnlen
2000-06-04 21:20:20 +08:00
2003-09-14 06:01:20 +08:00
#include <string.h>
2000-06-04 05:47:37 +08:00
#undef __strnlen
#undef strnlen
2003-08-18 17:44:49 +08:00
#ifndef _LIBC
# define strnlen rpl_strnlen
#endif
#ifndef weak_alias
# define __strnlen strnlen
#endif
2000-05-04 14:34:23 +08: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
__strnlen (const char *string, size_t maxlen)
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
2000-05-04 14:34:23 +08:00
}
#ifdef weak_alias
weak_alias (__strnlen, strnlen)
#endif