Move strcasestr() implementation to compat.c
authorKevin Cernekee <cernekee@gmail.com>
Mon, 8 Oct 2012 01:03:38 +0000 (18:03 -0700)
committerKevin Cernekee <cernekee@gmail.com>
Sat, 13 Oct 2012 21:23:05 +0000 (14:23 -0700)
Note: this change is untested.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
compat.c
http.c
openconnect-internal.h

index 537f68d..da59d35 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -140,3 +140,25 @@ ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream)
        return -1;
 }
 #endif
+
+#ifndef HAVE_STRCASESTR
+#include <ctype.h>
+
+char *openconnect__strcasestr(const char *haystack, const char *needle)
+{
+       int hlen = strlen(haystack);
+       int nlen = strlen(needle);
+       int i, j;
+
+       for (i = 0; i < hlen - nlen + 1; i++) {
+               for (j = 0; j < nlen; j++) {
+                       if (tolower(haystack[i + j]) !=
+                           tolower(needle[j]))
+                               break;
+               }
+               if (j == nlen)
+                       return (char *)haystack + i;
+       }
+       return NULL;
+}
+#endif
diff --git a/http.c b/http.c
index 0fb661e..8f264dc 100644 (file)
--- a/http.c
+++ b/http.c
@@ -526,28 +526,6 @@ static int run_csd_script(struct openconnect_info *vpninfo, char *buf, int bufle
        return 0;
 }
 
-#ifndef HAVE_STRCASESTR
-static char *openconnect__strcasestr(const char *haystack, const char *needle)
-{
-       int hlen = strlen(haystack);
-       int nlen = strlen(needle);
-       int i, j;
-
-       for (i = 0; i < hlen - nlen + 1; i++) {
-               for (j = 0; j < nlen; j++) {
-                       if (tolower(haystack[i + j]) != 
-                           tolower(needle[j]))
-                               break;
-               }
-               if (j == nlen)
-                       return (char *)haystack + i;
-       }
-       return NULL;
-}
-#define strcasestr openconnect__strcasestr
-#endif
-
-
 int internal_parse_url(char *url, char **res_proto, char **res_host,
                       int *res_port, char **res_path, int default_port)
 {
index eaf05a7..5b0b44a 100644 (file)
@@ -320,6 +320,10 @@ int openconnect__asprintf(char **strp, const char *fmt, ...);
 #define getline openconnect__getline
 ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream);
 #endif
+#ifndef HAVE_STRCASESTR
+#define strcasestr openconnect__strcasestr
+char *openconnect__strcasestr(const char *haystack, const char *needle);
+#endif
 
 /****************************************************************************/