mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 18:40:39 -08:00
Update from gnulib
This commit is contained in:
parent
c6a052f2fe
commit
7f89fe8a34
1 changed files with 10 additions and 6 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
/* Find the length of STRING, but scan at most MAXLEN characters.
|
/* Find the length of STRING, but scan at most MAXLEN characters.
|
||||||
Copyright (C) 2005-2007, 2009-2024 Free Software Foundation, Inc.
|
Copyright (C) 2005-2007, 2009-2024 Free Software Foundation, Inc.
|
||||||
Written by Simon Josefsson.
|
|
||||||
|
|
||||||
This file is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
|
@ -19,12 +18,17 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Find the length of STRING, but scan at most MAXLEN characters.
|
/* Find the length of S, but scan at most MAXLEN bytes.
|
||||||
If no '\0' terminator is found in that many characters, return MAXLEN. */
|
S must be a string if it starts with fewer than MAXLEN initialized bytes.
|
||||||
|
If no '\0' terminator is found in that many bytes, return MAXLEN. */
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
strnlen (const char *string, size_t maxlen)
|
strnlen (const char *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
const char *end = memchr (string, '\0', maxlen);
|
/* Do not use memchr, because on some platforms memchr has
|
||||||
return end ? (size_t) (end - string) : maxlen;
|
undefined behavior if MAXLEN exceeds the number of bytes in S. */
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < maxlen && s[i]; i++)
|
||||||
|
continue;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue