大家一看就知道这个是什么作用,这个函数呢,大部分OS中都没有实现
strnstr函数说明,在s1的前pos1个字符串中查找s2,如果存在就返回s2在s1中的位置,如果没有找到,返回 NULL,经测试没有问题
以下是源码
/**
* strnstr - Find the first substring in a %NUL terminated string
* @s1: The string to be searched
* @s2: The string to search for
* @pos1: 在s1的前pos1字符中查找
* add by zoukaiping*/
char* strnstr(char* s1, char* s2, int pos1)
{
int l1, l2;
l2 = strlen(s2);
if (!l2)
return (char *)s1;
l1 = strlen(s1);
pos1 = (pos1 > s1)?s1:pos1;
while (pos1 >= l2) {
pos1--;
if (!memcmp(s1, s2, l2))
return (char *)s1;
s1++;
}
return NULL;
}