Add strcasestr()
authorJens Axboe <axboe@kernel.dk>
Fri, 5 Apr 2013 12:44:03 +0000 (14:44 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 5 Apr 2013 12:44:03 +0000 (14:44 +0200)
We'll need it for the next commit, if the platform does not
provide it.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
configure
lib/strcasestr.c [new file with mode: 0644]
lib/strcasestr.h [new file with mode: 0644]

index 27e82c660a665b4d18ca2949e8c639ab5f5c9001..15455052a7011857f619c0938875d761a96da103 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,9 @@ endif
 ifndef CONFIG_STRSEP
   SOURCE += lib/strsep.c
 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
 ifndef CONFIG_GETOPT_LONG_ONLY
   SOURCE += lib/getopt_long.c
 endif
index a3c51fbdb82f06ebd8f9e5d274bab36cb37d33cd..09ea2761df9aba981ab286a77e71caf07cbfdd77 100755 (executable)
--- a/configure
+++ b/configure
@@ -843,6 +843,22 @@ if compile_prog "" "" "strsep"; then
 fi
 echo "strsep                        $strsep"
 
 fi
 echo "strsep                        $strsep"
 
+##########################################
+# strcasestr() probe
+strcasestr="no"
+cat > $TMPC << EOF
+#include <string.h>
+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"
 ##########################################
 # 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 "$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
 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 (file)
index 0000000..92cf24c
--- /dev/null
@@ -0,0 +1,25 @@
+#include <ctype.h>
+#include <stddef.h>
+
+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 (file)
index 0000000..43d61df
--- /dev/null
@@ -0,0 +1,13 @@
+#ifdef CONFIG_STRCASESTR
+
+#include <string.h>
+
+#else
+
+#ifndef FIO_STRCASESTR_H
+#define FIO_STRCASESTR_H
+
+char *strcasestr(const char *haystack, const char *needle);
+
+#endif
+#endif