From: Jens Axboe Date: Fri, 5 Apr 2013 12:44:03 +0000 (+0200) Subject: Add strcasestr() X-Git-Tag: fio-2.1~89^2~3 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=9ad8da8217db155d2b48fe7bed91da794a71d071 Add strcasestr() We'll need it for the next commit, if the platform does not provide it. Signed-off-by: Jens Axboe --- diff --git a/Makefile b/Makefile index 27e82c66..15455052 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,9 @@ endif ifndef CONFIG_STRSEP SOURCE += lib/strsep.c endif +ifndef CONFIG_STRCASESTR + SOURCE += lib/strcasestr.c +endif ifndef CONFIG_GETOPT_LONG_ONLY SOURCE += lib/getopt_long.c endif diff --git a/configure b/configure index a3c51fbd..09ea2761 100755 --- a/configure +++ b/configure @@ -843,6 +843,22 @@ if compile_prog "" "" "strsep"; then fi echo "strsep $strsep" +########################################## +# strcasestr() probe +strcasestr="no" +cat > $TMPC << EOF +#include +int main(int argc, char **argv) +{ + strcasestr(NULL, NULL); + return 0; +} +EOF +if compile_prog "" "" "strcasestr"; then + strcasestr="yes" +fi +echo "strcasestr $strcasestr" + ########################################## # getopt_long_only() probe getopt_long_only="no" @@ -1043,6 +1059,9 @@ fi if test "$strsep" = "yes" ; then output_sym "CONFIG_STRSEP" fi +if test "$strcasestr" = "yes" ; then + output_sym "CONFIG_STRCASESTR" +fi if test "$getopt_long_only" = "yes" ; then output_sym "CONFIG_GETOPT_LONG_ONLY" fi diff --git a/lib/strcasestr.c b/lib/strcasestr.c new file mode 100644 index 00000000..92cf24c6 --- /dev/null +++ b/lib/strcasestr.c @@ -0,0 +1,25 @@ +#include +#include + +char *strcasestr(const char *s1, const char *s2) +{ + const char *s = s1; + const char *p = s2; + + do { + if (!*p) + return (char *) s1; + if ((*p == *s) || + (tolower(*p) == tolower(*s))) { + ++p; + ++s; + } else { + p = s2; + if (!*s) + return NULL; + s = ++s1; + } + } while (1); + + return *p ? NULL : (char *) s1; +} diff --git a/lib/strcasestr.h b/lib/strcasestr.h new file mode 100644 index 00000000..43d61df4 --- /dev/null +++ b/lib/strcasestr.h @@ -0,0 +1,13 @@ +#ifdef CONFIG_STRCASESTR + +#include + +#else + +#ifndef FIO_STRCASESTR_H +#define FIO_STRCASESTR_H + +char *strcasestr(const char *haystack, const char *needle); + +#endif +#endif