From 9ad8da8217db155d2b48fe7bed91da794a71d071 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 5 Apr 2013 14:44:03 +0200 Subject: [PATCH 1/1] Add strcasestr() We'll need it for the next commit, if the platform does not provide it. Signed-off-by: Jens Axboe --- Makefile | 3 +++ configure | 19 +++++++++++++++++++ lib/strcasestr.c | 25 +++++++++++++++++++++++++ lib/strcasestr.h | 13 +++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 lib/strcasestr.c create mode 100644 lib/strcasestr.h 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 -- 2.25.1