Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move strcasestr() implementation to compat.c
Note: this change is untested.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Oct 13, 2012
1 parent 47fe613 commit a0dcd34
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
22 changes: 22 additions & 0 deletions compat.c
Expand Up @@ -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
22 changes: 0 additions & 22 deletions http.c
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions openconnect-internal.h
Expand Up @@ -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

/****************************************************************************/

Expand Down

0 comments on commit a0dcd34

Please sign in to comment.