mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +03:00
Fix the implementation. We cannot use memchr.
This commit is contained in:
@@ -1,5 +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) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
Copyright (C) 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@@ -19,13 +19,26 @@
|
|||||||
|
|
||||||
#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 characters. If no
|
||||||
If no '\0' terminator is found in that many characters, return MAXLEN. */
|
'\0' terminator is found in that many characters, 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);
|
size_t len = 0;
|
||||||
return end ? (size_t) (end - string) : maxlen;
|
|
||||||
|
while (s[len] != '\0' && maxlen > 0)
|
||||||
|
{
|
||||||
|
if (s[++len] == '\0' || --maxlen == 0)
|
||||||
|
return len;
|
||||||
|
if (s[++len] == '\0' || --maxlen == 0)
|
||||||
|
return len;
|
||||||
|
if (s[++len] == '\0' || --maxlen == 0)
|
||||||
|
return len;
|
||||||
|
++len;
|
||||||
|
--maxlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
weak_alias (__strnlen, strnlen)
|
weak_alias (__strnlen, strnlen)
|
||||||
|
Reference in New Issue
Block a user