Commit a0dcd34e authored by Kevin Cernekee's avatar Kevin Cernekee

Move strcasestr() implementation to compat.c

Note: this change is untested.
Signed-off-by: default avatarKevin Cernekee <cernekee@gmail.com>
parent 47fe613c
......@@ -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
......@@ -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)
{
......
......@@ -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
/****************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment