|
Packit |
1ac44c |
/* Find the length of STRING, but scan at most MAXLEN characters.
|
|
Packit |
1ac44c |
Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc.
|
|
Packit |
1ac44c |
Written by Simon Josefsson.
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
1ac44c |
it under the terms of the GNU General Public License as published by
|
|
Packit |
1ac44c |
the Free Software Foundation; either version 3, or (at your option)
|
|
Packit |
1ac44c |
any later version.
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
This program is distributed in the hope that it will be useful,
|
|
Packit |
1ac44c |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
1ac44c |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
1ac44c |
GNU General Public License for more details.
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
You should have received a copy of the GNU General Public License
|
|
Packit |
1ac44c |
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
#include <config.h>
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
#include <string.h>
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
/* Find the length of STRING, but scan at most MAXLEN characters.
|
|
Packit |
1ac44c |
If no '\0' terminator is found in that many characters, return MAXLEN. */
|
|
Packit |
1ac44c |
|
|
Packit |
1ac44c |
size_t
|
|
Packit |
1ac44c |
strnlen (const char *string, size_t maxlen)
|
|
Packit |
1ac44c |
{
|
|
Packit |
1ac44c |
const char *end = memchr (string, '\0', maxlen);
|
|
Packit |
1ac44c |
return end ? (size_t) (end - string) : maxlen;
|
|
Packit |
1ac44c |
}
|