提交 d5f1fb53 编写于 作者: L Li Zefan 提交者: Steven Rostedt

lib: Introduce strnstr()

It differs strstr() in that it limits the length to be searched
in the first string.
Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4B4E8743.6030805@cn.fujitsu.com>
Acked-by: NFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: NSteven Rostedt <rostedt@goodmis.org>
上级 a3291c14
...@@ -72,7 +72,10 @@ static inline __must_check char *strstrip(char *str) ...@@ -72,7 +72,10 @@ static inline __must_check char *strstrip(char *str)
} }
#ifndef __HAVE_ARCH_STRSTR #ifndef __HAVE_ARCH_STRSTR
extern char * strstr(const char *,const char *); extern char * strstr(const char *, const char *);
#endif
#ifndef __HAVE_ARCH_STRNSTR
extern char * strnstr(const char *, const char *, size_t);
#endif #endif
#ifndef __HAVE_ARCH_STRLEN #ifndef __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *); extern __kernel_size_t strlen(const char *);
......
...@@ -667,7 +667,7 @@ EXPORT_SYMBOL(memscan); ...@@ -667,7 +667,7 @@ EXPORT_SYMBOL(memscan);
*/ */
char *strstr(const char *s1, const char *s2) char *strstr(const char *s1, const char *s2)
{ {
int l1, l2; size_t l1, l2;
l2 = strlen(s2); l2 = strlen(s2);
if (!l2) if (!l2)
...@@ -684,6 +684,31 @@ char *strstr(const char *s1, const char *s2) ...@@ -684,6 +684,31 @@ char *strstr(const char *s1, const char *s2)
EXPORT_SYMBOL(strstr); EXPORT_SYMBOL(strstr);
#endif #endif
#ifndef __HAVE_ARCH_STRNSTR
/**
* strnstr - Find the first substring in a length-limited string
* @s1: The string to be searched
* @s2: The string to search for
* @len: the maximum number of characters to search
*/
char *strnstr(const char *s1, const char *s2, size_t len)
{
size_t l1 = len, l2;
l2 = strlen(s2);
if (!l2)
return (char *)s1;
while (l1 >= l2) {
l1--;
if (!memcmp(s1, s2, l2))
return (char *)s1;
s1++;
}
return NULL;
}
EXPORT_SYMBOL(strnstr);
#endif
#ifndef __HAVE_ARCH_MEMCHR #ifndef __HAVE_ARCH_MEMCHR
/** /**
* memchr - Find a character in an area of memory. * memchr - Find a character in an area of memory.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册