提交 d6a2eedf 编写于 作者: A André Goddard Rosa 提交者: Linus Torvalds

lib/string.c: simplify strnstr()

Signed-off-by: NAndré 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: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 a11d2b64
......@@ -689,13 +689,13 @@ EXPORT_SYMBOL(strstr);
*/
char *strnstr(const char *s1, const char *s2, size_t len)
{
size_t l1 = len, l2;
size_t l2;
l2 = strlen(s2);
if (!l2)
return (char *)s1;
while (l1 >= l2) {
l1--;
while (len >= l2) {
len--;
if (!memcmp(s1, s2, l2))
return (char *)s1;
s1++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册