Fix distributed fallback strcasestr. - sacc - sacc(omys), simple console gopher client
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/
Log
Files
Refs
Tags
LICENSE
---
commit eb8d00efa77bcacfdf1a456a09eaa53267142994
parent 3f367506841bfd8944cc57e3ccf231c41130af5e
Author: Hiltjo Posthuma 
Date:   Mon, 21 May 2018 12:05:59 +0200

Fix distributed fallback strcasestr.

The function was slightly changed to use an inline loop without using
strncasecmp.

Diffstat:
  M sacc.c                              |      17 +++++++++++++----

1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/sacc.c b/sacc.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -66,11 +67,19 @@ asprintf(char **s, const char *fmt, ...)
 char *
 strcasestr(const char *h, const char *n)
 {
-        size_t l = strlen(n);
-        for (; *h; h++)
-                if (!strncasecmp(h, n, l))
+        size_t i;
+
+        if (!n[0])
+                return h;
+
+        for (; *h; ++h{
+                for (i = 0; n[i] && tolower(n[i]) == tolower(h[i]); ++i)
+                        ;
+                if (n[i] == '\0')
                         return (char *)h;
-        return 0;
+        }
+
+        return NULL;
 }
 #endif /* NEED_STRCASESTR */