linux 内核中strstr 功能
在内核代码中看到strstr函数:
mode = strstr(boot_command_line, "D:");
应该是一个字符串处理函数,使用man命令查看下给出如下解释:
SYNOPSIS #include <string.h> char *strstr(const char *haystack, const char *needle); #define _GNU_SOURCE #include <string.h> char *strcasestr(const char *haystack, const char *needle); DESCRIPTION The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating '\0' characters are not compared. The strcasestr() function is like strstr(), but ignores the case of both arguments. RETURN VALUE These functions return a pointer to the beginning of the substring, or NULL if the substring is not found.
简单的例子:
#include <string.h> #include <stdio.h> int main() { char *haystack = "Hello, this is csdn blog, I am here"; char *needle = "he"; char *temp; temp = strstr(haystack, needle); if(temp != NULL) { printf("%s\n", temp); } else { printf("can not find [%s] from [%s]\n", needle, haystack); } return 0; }
$ gcc strstr.c -o strstr $ ./strstr
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。