Commit d6a2eedf authored by André Goddard Rosa's avatar André Goddard Rosa Committed by Linus Torvalds

lib/string.c: simplify strnstr()

Signed-off-by: default avatarAndré Goddard Rosa <andre.goddard@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Joe Perches <joe@perches.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a11d2b64
...@@ -689,13 +689,13 @@ EXPORT_SYMBOL(strstr); ...@@ -689,13 +689,13 @@ EXPORT_SYMBOL(strstr);
*/ */
char *strnstr(const char *s1, const char *s2, size_t len) char *strnstr(const char *s1, const char *s2, size_t len)
{ {
size_t l1 = len, l2; size_t l2;
l2 = strlen(s2); l2 = strlen(s2);
if (!l2) if (!l2)
return (char *)s1; return (char *)s1;
while (l1 >= l2) { while (len >= l2) {
l1--; len--;
if (!memcmp(s1, s2, l2)) if (!memcmp(s1, s2, l2))
return (char *)s1; return (char *)s1;
s1++; s1++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment