[PATCH 04/10] Move strcasestr() implementation to compat.c

Kevin Cernekee cernekee at gmail.com
Sun Oct 7 21:03:38 EDT 2012


Note: this change is untested.

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 compat.c               |   22 ++++++++++++++++++++++
 http.c                 |   22 ----------------------
 openconnect-internal.h |    4 ++++
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/compat.c b/compat.c
index 537f68d..da59d35 100644
--- 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
--- 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)
 {
diff --git a/openconnect-internal.h b/openconnect-internal.h
index eaf05a7..5b0b44a 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -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
 
 /****************************************************************************/
 
-- 
1.7.5.4




More information about the openconnect-devel mailing list