On 18/11/14 17:12, Tim Ruehsen wrote:
I amended three tests to fail when run with turkish locale.
I fixed these issues (using c_strcasecmp/c_strncasecmp) and also replaced
strcasecmp/strncasecmp by c_strcasecmp/c_strncasecmp at places where we
definitely want a ASCII comparison instead of a locale dependent one.
There are still some places left where we use strcasecmp/strncasecmp, e.g.
domain/host and filename comparisons.
Please have a look...
Tim
I had pretty much coded the same thing when I realized that your patch
was still unapplied.
I am attaching it here fwiw. I generally changed them on a few more
places, although I think
some of your edits to init.c are incorrect, as well as those on
progress.c: as they are
user-parameters, they _might_ be introduced in the user locale (they
would misteriously fail
when run under C locale in cron, though. I'm not so sure it should be
supported).
Notwithstanding with keeping parameters in user-locale case, I made the
accepts list C-case.
That's the most arguable one, but doesn't seem sensible to change the
code to support that.
Regards
>From 16688a829f5b5a30b5287bf8cc2dfc1e8ac1e6d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81ngel=20Gonz=C3=A1lez?= <[email protected]>
Date: Wed, 19 Nov 2014 23:50:20 +0100
Subject: [PATCH] Replace strcasecmp and strncasecmp with c_strcasecmp and
c_strncasecmp
---
bootstrap.conf | 1 +
src/cmpt.c | 63 --------------------------------------------------------
src/cookies.c | 5 +++--
src/css-url.c | 2 +-
src/ftp-basic.c | 21 ++++++++++---------
src/ftp-ls.c | 9 ++++----
src/ftp.c | 7 ++++---
src/hash.c | 2 +-
src/html-parse.c | 2 +-
src/html-url.c | 23 +++++++++++----------
src/http.c | 34 +++++++++++++++---------------
src/iri.c | 9 ++++----
src/main.c | 3 ++-
src/mswindows.h | 8 -------
src/netrc.c | 2 +-
src/openssl.c | 2 +-
src/progress.c | 1 +
src/recur.c | 4 ++--
src/res.c | 1 +
src/url.c | 5 +++--
src/utils.c | 11 +++++-----
src/wget.h | 2 +-
22 files changed, 79 insertions(+), 138 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 71aa913..045dbba 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -70,6 +70,7 @@ sigpipe
snprintf
socket
stdbool
+strcase
strcasestr
strerror_r-posix
strtok_r
diff --git a/src/cmpt.c b/src/cmpt.c
index a49103e..e6510f2 100644
--- a/src/cmpt.c
+++ b/src/cmpt.c
@@ -47,69 +47,6 @@ as that of the covered work. */
new Wget-specific interfaces -- those should be placed in utils.c
or elsewhere. */
-/* strcasecmp and strncasecmp apparently originated with BSD 4.4.
- SUSv3 seems to be the only standard out there (that I can find)
- that requires their existence, so in theory there might be systems
- still in use that lack them. Note that these don't get defined
- under Windows because mswindows.h defines them to the equivalent
- Windows functions stricmp and strnicmp. */
-
-#ifndef HAVE_STRCASECMP
-/* From GNU libc. */
-/* Compare S1 and S2, ignoring case, returning less than, equal to or
- greater than zero if S1 is lexiographically less than,
- equal to or greater than S2. */
-int
-strcasecmp (const char *s1, const char *s2)
-{
- register const unsigned char *p1 = (const unsigned char *) s1;
- register const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
-
- if (p1 == p2)
- return 0;
-
- do
- {
- c1 = c_tolower (*p1++);
- c2 = c_tolower (*p2++);
- if (c1 == '\0')
- break;
- }
- while (c1 == c2);
-
- return c1 - c2;
-}
-#endif /* not HAVE_STRCASECMP */
-
-#ifndef HAVE_STRNCASECMP
-/* From GNU libc. */
-/* Compare no more than N characters of S1 and S2,
- ignoring case, returning less than, equal to or
- greater than zero if S1 is lexicographically less
- than, equal to or greater than S2. */
-int
-strncasecmp (const char *s1, const char *s2, size_t n)
-{
- register const unsigned char *p1 = (const unsigned char *) s1;
- register const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
-
- if (p1 == p2 || n == 0)
- return 0;
-
- do
- {
- c1 = c_tolower (*p1++);
- c2 = c_tolower (*p2++);
- if (c1 == '\0' || c1 != c2)
- return c1 - c2;
- } while (--n > 0);
-
- return c1 - c2;
-}
-#endif /* not HAVE_STRNCASECMP */
-
#ifndef HAVE_MEMRCHR
/* memrchr is a GNU extension. It is like the memchr function, except
that it searches backwards from the end of the n bytes pointed to
diff --git a/src/cookies.c b/src/cookies.c
index bf872a8..a170699 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -58,6 +58,7 @@ as that of the covered work. */
#include "hash.h"
#include "cookies.h"
#include "http.h" /* for http_atotm */
+#include "c-strcase.h"
/* Declarations of `struct cookie' and the most basic functions. */
@@ -558,7 +559,7 @@ no_psl:
DEBUGP (("cdm: 2"));
/* For the sake of efficiency, check for exact match first. */
- if (0 == strcasecmp (cookie_domain, host))
+ if (0 == c_strcasecmp (cookie_domain, host))
return true;
DEBUGP ((" 3"));
@@ -893,7 +894,7 @@ cookie_matches_url (const struct cookie *cookie,
equal to HOST. If not, assume success on the grounds of the
cookie's chain having been found by find_chains_of_host. */
if (cookie->domain_exact
- && 0 != strcasecmp (host, cookie->domain))
+ && 0 != c_strcasecmp (host, cookie->domain))
return false;
pg = path_matches (path, cookie->path);
diff --git a/src/css-url.c b/src/css-url.c
index 8ee4e8c..cac9dbc 100644
--- a/src/css-url.c
+++ b/src/css-url.c
@@ -73,7 +73,7 @@ extern int yylex (void);
static char *
get_uri_string (const char *at, int *pos, int *length)
{
- if (0 != strncasecmp (at + *pos, "url(", 4))
+ if (0 != c_strncasecmp (at + *pos, "url(", 4))
return NULL;
*pos += 4;
diff --git a/src/ftp-basic.c b/src/ftp-basic.c
index 83cc447..d740721 100644
--- a/src/ftp-basic.c
+++ b/src/ftp-basic.c
@@ -43,6 +43,7 @@ as that of the covered work. */
#include "host.h"
#include "ftp.h"
#include "retr.h"
+#include "c-strcase.h"
/* Get the response of FTP server and allocate enough room to handle
@@ -190,7 +191,7 @@ ftp_login (int csock, const char *acc, const char *pass)
for (i = 0; i < countof (skey_head); i++)
{
int l = strlen (skey_head[i]);
- if (0 == strncasecmp (skey_head[i], respline, l))
+ if (0 == c_strncasecmp (skey_head[i], respline, l))
{
seed = respline + l;
break;
@@ -1066,25 +1067,25 @@ ftp_syst (int csock, enum stype *server_type, enum ustype *unix_type)
if (request == NULL)
*server_type = ST_OTHER;
- else if (!strcasecmp (request, "VMS"))
+ else if (!c_strcasecmp (request, "VMS"))
*server_type = ST_VMS;
- else if (!strcasecmp (request, "UNIX"))
+ else if (!c_strcasecmp (request, "UNIX"))
{
*server_type = ST_UNIX;
/* 2013-10-17 Andrea Urbani (matfanjol)
I check more in depth the system type */
- if (!strncasecmp (ftp_last_respline, "215 UNIX Type: L8", 17))
+ if (!c_strncasecmp (ftp_last_respline, "215 UNIX Type: L8", 17))
*unix_type = UST_TYPE_L8;
- else if (!strncasecmp (ftp_last_respline,
+ else if (!c_strncasecmp (ftp_last_respline,
"215 UNIX MultiNet Unix Emulation V5.3(93)", 41))
*unix_type = UST_MULTINET;
}
- else if (!strcasecmp (request, "WINDOWS_NT")
- || !strcasecmp (request, "WINDOWS2000"))
+ else if (!c_strcasecmp (request, "WINDOWS_NT")
+ || !c_strcasecmp (request, "WINDOWS2000"))
*server_type = ST_WINNT;
- else if (!strcasecmp (request, "MACOS"))
+ else if (!c_strcasecmp (request, "MACOS"))
*server_type = ST_MACOS;
- else if (!strcasecmp (request, "OS/400"))
+ else if (!c_strcasecmp (request, "OS/400"))
*server_type = ST_OS400;
else
*server_type = ST_OTHER;
@@ -1205,7 +1206,7 @@ char
ftp_process_type (const char *params)
{
if (params
- && 0 == strncasecmp (params, "type=", 5)
+ && 0 == c_strncasecmp (params, "type=", 5)
&& params[5] != '\0')
return c_toupper (params[5]);
else
diff --git a/src/ftp-ls.c b/src/ftp-ls.c
index 8ab8a37..d68380b 100644
--- a/src/ftp-ls.c
+++ b/src/ftp-ls.c
@@ -42,6 +42,7 @@ as that of the covered work. */
#include "url.h"
#include "convert.h" /* for html_quote_string prototype */
#include "retr.h" /* for output_stream */
+#include "c-strcase.h"
/* Converts symbolic permissions to number-style ones, e.g. string
rwxr-xr-x to 755. For now, it knows nothing of
@@ -121,7 +122,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
{
len = clean_line (line, len);
/* Skip if total... */
- if (!strncasecmp (line, "total", 5))
+ if (!c_strncasecmp (line, "total", 5))
continue;
/* Get the first token (permissions). */
tok = strtok (line, " ");
@@ -199,7 +200,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
if (next < 0) /* a month name was not encountered */
{
for (i = 0; i < 12; i++)
- if (!strcasecmp (tok, months[i]))
+ if (!c_strcasecmp (tok, months[i]))
break;
/* If we got a month, it means the token before it is the
size, and the filename is three tokens away. */
@@ -775,14 +776,14 @@ ftp_parse_vms_ls (const char *file)
what will work in a CWD command.
*/
len = strlen (tok);
- if (!strncasecmp((tok + (len - 4)), ".DIR", 4))
+ if (!c_strncasecmp((tok + (len - 4)), ".DIR", 4))
{
*(tok+ (len - 4)) = '\0'; /* Discard ".DIR". */
cur.type = FT_DIRECTORY;
cur.perms = VMS_DEFAULT_PROT_DIR;
DEBUGP (("Directory (nv)\n"));
}
- else if (!strncasecmp ((tok + (len - 6)), ".DIR;1", 6))
+ else if (!c_strncasecmp ((tok + (len - 6)), ".DIR;1", 6))
{
*(tok+ (len - 6)) = '\0'; /* Discard ".DIR;1". */
cur.type = FT_DIRECTORY;
diff --git a/src/ftp.c b/src/ftp.c
index d614a27..2bab1a1 100644
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -50,6 +50,7 @@ as that of the covered work. */
#include "convert.h" /* for downloaded_file */
#include "recur.h" /* for INFINITE_RECURSION */
#include "warc.h"
+#include "c-strcase.h"
#ifdef __VMS
# include "vms.h"
@@ -102,7 +103,7 @@ ftp_expected_bytes (const char *s)
return 0;
if (c_tolower (*s) != 'b')
continue;
- if (strncasecmp (s, "byte", 4))
+ if (c_strncasecmp (s, "byte", 4))
continue;
else
break;
@@ -2330,10 +2331,10 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action)
* harmless.
*/
int (*cmp) (const char *, const char *)
- = opt.ignore_case ? strcasecmp : (int (*)())strcmp;
+ = opt.ignore_case ? c_strcasecmp : (int (*)())strcmp;
#else /* def __VMS */
int (*cmp) (const char *, const char *)
- = opt.ignore_case ? strcasecmp : strcmp;
+ = opt.ignore_case ? c_strcasecmp : strcmp;
#endif /* def __VMS [else] */
f = start;
while (f)
diff --git a/src/hash.c b/src/hash.c
index 393c775..929019e 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -690,7 +690,7 @@ hash_string_nocase (const void *key)
static int
string_cmp_nocase (const void *s1, const void *s2)
{
- return !strcasecmp ((const char *)s1, (const char *)s2);
+ return !c_strcasecmp ((const char *)s1, (const char *)s2);
}
/* Like make_string_hash_table, but uses string_hash_nocase and
diff --git a/src/html-parse.c b/src/html-parse.c
index b7a90da..bfc70be 100644
--- a/src/html-parse.c
+++ b/src/html-parse.c
@@ -352,7 +352,7 @@ tagstack_find (struct tagstack_item *tail, const char *tagname_begin,
{
if (len == (tail->tagname_end - tail->tagname_begin))
{
- if (0 == strncasecmp (tail->tagname_begin, tagname_begin, len))
+ if (0 == c_strncasecmp (tail->tagname_begin, tagname_begin, len))
return tail;
}
tail = tail->prev;
diff --git a/src/html-url.c b/src/html-url.c
index 903864e..a5c55e5 100644
--- a/src/html-url.c
+++ b/src/html-url.c
@@ -45,6 +45,7 @@ as that of the covered work. */
#include "recur.h"
#include "html-url.h"
#include "css-url.h"
+#include "c-strcase.h"
typedef void (*tag_handler_t) (int, struct taginfo *, struct map_context *);
@@ -255,7 +256,7 @@ find_attr (struct taginfo *tag, const char *name, int *attrind)
{
int i;
for (i = 0; i < tag->nattrs; i++)
- if (!strcasecmp (tag->attrs[i].name, name))
+ if (!c_strcasecmp (tag->attrs[i].name, name))
{
if (attrind)
*attrind = i;
@@ -451,7 +452,7 @@ tag_find_urls (int tagid, struct taginfo *tag, struct map_context *ctx)
has three attributes. */
for (i = first; i < size && tag_url_attributes[i].tagid == tagid; i++)
{
- if (0 == strcasecmp (tag->attrs[attrind].name,
+ if (0 == c_strcasecmp (tag->attrs[attrind].name,
tag_url_attributes[i].attr_name))
{
struct urlpos *up = append_url (link, ATTR_POS(tag,attrind,ctx),
@@ -536,12 +537,12 @@ tag_handle_link (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
char *rel = find_attr (tag, "rel", NULL);
if (rel)
{
- if (0 == strcasecmp (rel, "stylesheet"))
+ if (0 == c_strcasecmp (rel, "stylesheet"))
{
up->link_inline_p = 1;
up->link_expect_css = 1;
}
- else if (0 == strcasecmp (rel, "shortcut icon"))
+ else if (0 == c_strcasecmp (rel, "shortcut icon"))
{
up->link_inline_p = 1;
}
@@ -553,7 +554,7 @@ tag_handle_link (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
<link rel="alternate" type="application/rss+xml" href=".../?feed=rss2" />
*/
char *type = find_attr (tag, "type", NULL);
- if (!type || strcasecmp (type, "text/html") == 0)
+ if (!type || c_strcasecmp (type, "text/html") == 0)
up->link_expect_html = 1;
}
}
@@ -570,7 +571,7 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
char *name = find_attr (tag, "name", NULL);
char *http_equiv = find_attr (tag, "http-equiv", NULL);
- if (http_equiv && 0 == strcasecmp (http_equiv, "refresh"))
+ if (http_equiv && 0 == c_strcasecmp (http_equiv, "refresh"))
{
/* Some pages use a META tag to specify that the page be
refreshed by a new page after a given number of seconds. The
@@ -615,7 +616,7 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
entry->link_expect_html = 1;
}
}
- else if (http_equiv && 0 == strcasecmp (http_equiv, "content-type"))
+ else if (http_equiv && 0 == c_strcasecmp (http_equiv, "content-type"))
{
/* Handle stuff like:
<meta http-equiv="Content-Type" content="text/html; charset=CHARSET"> */
@@ -632,14 +633,14 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
xfree_null (meta_charset);
meta_charset = mcharset;
}
- else if (name && 0 == strcasecmp (name, "robots"))
+ else if (name && 0 == c_strcasecmp (name, "robots"))
{
/* Handle stuff like:
<meta name="robots" content="index,nofollow"> */
char *content = find_attr (tag, "content", NULL);
if (!content)
return;
- if (!strcasecmp (content, "none"))
+ if (!c_strcasecmp (content, "none"))
ctx->nofollow = true;
else
{
@@ -651,7 +652,7 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
/* Find the next occurrence of ',' or whitespace,
* or the end of the string. */
end = content + strcspn (content, ", \f\n\r\t\v");
- if (!strncasecmp (content, "nofollow", end - content))
+ if (!c_strncasecmp (content, "nofollow", end - content))
ctx->nofollow = true;
/* Skip past the next comma, if any. */
if (*end == ',')
@@ -692,7 +693,7 @@ collect_tags_mapper (struct taginfo *tag, void *arg)
check_style_attr (tag, ctx);
- if (tag->end_tag_p && (0 == strcasecmp (tag->name, "style"))
+ if (tag->end_tag_p && (0 == c_strcasecmp (tag->name, "style"))
&& tag->contents_begin && tag->contents_end
&& tag->contents_begin <= tag->contents_end)
{
diff --git a/src/http.c b/src/http.c
index 06148eb..fce4b9f 100644
--- a/src/http.c
+++ b/src/http.c
@@ -244,7 +244,7 @@ request_set_header (struct request *req, const char *name, const char *value,
for (i = 0; i < req->hcount; i++)
{
hdr = &req->headers[i];
- if (0 == strcasecmp (name, hdr->name))
+ if (0 == c_strcasecmp (name, hdr->name))
{
/* Replace existing header. */
release_header (hdr);
@@ -297,7 +297,7 @@ request_remove_header (struct request *req, const char *name)
for (i = 0; i < req->hcount; i++)
{
struct request_header *hdr = &req->headers[i];
- if (0 == strcasecmp (name, hdr->name))
+ if (0 == c_strcasecmp (name, hdr->name))
{
release_header (hdr);
/* Move the remaining headers by one. */
@@ -682,7 +682,7 @@ resp_header_locate (const struct response *resp, const char *name, int start,
const char *e = headers[i + 1];
if (e - b > name_len
&& b[name_len] == ':'
- && 0 == strncasecmp (b, name, name_len))
+ && 0 == c_strncasecmp (b, name, name_len))
{
b += name_len + 1;
while (b < e && c_isspace (*b))
@@ -871,7 +871,7 @@ parse_content_range (const char *hdr, wgint *first_byte_ptr,
/* Ancient versions of Netscape proxy server, presumably predating
rfc2068, sent out `Content-Range' without the "bytes"
specifier. */
- if (0 == strncasecmp (hdr, "bytes", 5))
+ if (0 == c_strncasecmp (hdr, "bytes", 5))
{
hdr += 5;
/* "JavaWebServer/1.1.1" sends "bytes: x-y/z", contrary to the
@@ -1335,7 +1335,7 @@ persistent_available_p (const char *host, int port, bool ssl,
/* If the host is the same, we're in business. If not, there is
still hope -- read below. */
- if (0 != strcasecmp (host, pconn.host))
+ if (0 != c_strcasecmp (host, pconn.host))
{
/* Check if pconn.socket is talking to HOST under another name.
This happens often when both sites are virtual hosts
@@ -1877,9 +1877,9 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
xstrdup (number_to_static_string (body_data_size)),
rel_value);
}
- else if (strcasecmp (opt.method, "post") == 0
- || strcasecmp (opt.method, "put") == 0
- || strcasecmp (opt.method, "patch") == 0)
+ else if (c_strcasecmp (opt.method, "post") == 0
+ || c_strcasecmp (opt.method, "put") == 0
+ || c_strcasecmp (opt.method, "patch") == 0)
request_set_header (req, "Content-Length", "0", rel_none);
}
@@ -2298,14 +2298,14 @@ read_header:
{
if (resp_header_copy (resp, "Connection", hdrval, sizeof (hdrval)))
{
- if (0 == strcasecmp (hdrval, "Close"))
+ if (0 == c_strcasecmp (hdrval, "Close"))
keep_alive = false;
}
}
chunked_transfer_encoding = false;
if (resp_header_copy (resp, "Transfer-Encoding", hdrval, sizeof (hdrval))
- && 0 == strcasecmp (hdrval, "chunked"))
+ && 0 == c_strcasecmp (hdrval, "chunked"))
chunked_transfer_encoding = true;
/* Handle (possibly multiple instances of) the Set-Cookie header. */
@@ -2735,11 +2735,11 @@ read_header:
case HTTP_STATUS_TEMPORARY_REDIRECT:
return NEWLOCATION_KEEP_POST;
case HTTP_STATUS_MOVED_PERMANENTLY:
- if (opt.method && strcasecmp (opt.method, "post") != 0)
+ if (opt.method && c_strcasecmp (opt.method, "post") != 0)
return NEWLOCATION_KEEP_POST;
break;
case HTTP_STATUS_MOVED_TEMPORARILY:
- if (opt.method && strcasecmp (opt.method, "post") != 0)
+ if (opt.method && c_strcasecmp (opt.method, "post") != 0)
return NEWLOCATION_KEEP_POST;
break;
default:
@@ -2753,14 +2753,14 @@ read_header:
of the multitude of broken CGI's that "forget" to generate the
content-type. */
if (!type ||
- 0 == strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)) ||
- 0 == strncasecmp (type, TEXTXHTML_S, strlen (TEXTXHTML_S)))
+ 0 == c_strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)) ||
+ 0 == c_strncasecmp (type, TEXTXHTML_S, strlen (TEXTXHTML_S)))
*dt |= TEXTHTML;
else
*dt &= ~TEXTHTML;
if (type &&
- 0 == strncasecmp (type, TEXTCSS_S, strlen (TEXTCSS_S)))
+ 0 == c_strncasecmp (type, TEXTCSS_S, strlen (TEXTCSS_S)))
*dt |= TEXTCSS;
else
*dt &= ~TEXTCSS;
@@ -4078,8 +4078,8 @@ ensure_extension (struct http_stat *hs, const char *ext, int *dt)
}
if (last_period_in_local_filename == NULL
- || !(0 == strcasecmp (last_period_in_local_filename, shortext)
- || 0 == strcasecmp (last_period_in_local_filename, ext)))
+ || !(0 == c_strcasecmp (last_period_in_local_filename, shortext)
+ || 0 == c_strcasecmp (last_period_in_local_filename, ext)))
{
int local_filename_len = strlen (hs->local_file);
/* Resize the local file, allowing for ".html" preceded by
diff --git a/src/iri.c b/src/iri.c
index dd2806d..d924699 100644
--- a/src/iri.c
+++ b/src/iri.c
@@ -39,6 +39,7 @@ as that of the covered work. */
#include "utils.h"
#include "url.h"
+#include "c-strcase.h"
/* RFC3987 section 3.1 mandates STD3 ASCII RULES */
#define IDNA_FLAGS IDNA_USE_STD3_ASCII_RULES
@@ -206,7 +207,7 @@ locale_to_utf8 (const char *str)
opt.locale = find_locale ();
}
- if (!opt.locale || !strcasecmp (opt.locale, "utf-8"))
+ if (!opt.locale || !c_strcasecmp (opt.locale, "utf-8"))
return str;
if (do_conversion ("UTF-8", opt.locale, (char *) str, strlen ((char *) str), &new))
@@ -276,7 +277,7 @@ remote_to_utf8 (struct iri *iri, const char *str, const char **new)
/* When `i->uri_encoding' == "UTF-8" there is nothing to convert. But we must
test for non-ASCII symbols for correct hostname processing in `idn_encode'
function. */
- if (!strcasecmp (iri->uri_encoding, "UTF-8"))
+ if (!c_strcasecmp (iri->uri_encoding, "UTF-8"))
{
const char *p = str;
for (p = str; *p; p++)
@@ -344,7 +345,7 @@ set_uri_encoding (struct iri *i, char *charset, bool force)
return;
if (i->uri_encoding)
{
- if (charset && !strcasecmp (i->uri_encoding, charset))
+ if (charset && !c_strcasecmp (i->uri_encoding, charset))
return;
xfree (i->uri_encoding);
}
@@ -361,7 +362,7 @@ set_content_encoding (struct iri *i, char *charset)
return;
if (i->content_encoding)
{
- if (charset && !strcasecmp (i->content_encoding, charset))
+ if (charset && !c_strcasecmp (i->content_encoding, charset))
return;
xfree (i->content_encoding);
}
diff --git a/src/main.c b/src/main.c
index 530f9e8..a917e24 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,7 @@ as that of the covered work. */
#include "http.h" /* for save_cookies */
#include "ptimer.h"
#include "warc.h"
+#include "c-strcase.h"
#include <getopt.h>
#include <getpass.h>
#include <quote.h>
@@ -1465,7 +1466,7 @@ for details.\n\n"));
/* When user specifies HEAD as the method, we do not wish to download any
files. Hence, set wget to run in spider mode. */
- if (opt.method && strcasecmp (opt.method, "HEAD") == 0)
+ if (opt.method && c_strcasecmp (opt.method, "HEAD") == 0)
setoptval ("spider", "1", "spider");
/* Convert post_data to body-data and post_file_name to body-file options.
diff --git a/src/mswindows.h b/src/mswindows.h
index 3b815f0..482edb1 100644
--- a/src/mswindows.h
+++ b/src/mswindows.h
@@ -57,14 +57,6 @@ as that of the covered work. */
/* Declares getpid(). */
#include <process.h>
-/* We have strcasecmp and strncasecmp, just under different names. */
-#ifndef HAVE_STRCASECMP
-# define strcasecmp stricmp
-#endif
-#ifndef HAVE_STRNCASECMP
-# define strncasecmp strnicmp
-#endif
-
#include <stdio.h>
/* Define a wgint type under Windows. */
diff --git a/src/netrc.c b/src/netrc.c
index dec9e2a..228003d 100644
--- a/src/netrc.c
+++ b/src/netrc.c
@@ -117,7 +117,7 @@ search_netrc (const char *host, const char **acc, const char **passwd,
{
if (!l->host)
continue;
- else if (!strcasecmp (l->host, host))
+ else if (!c_strcasecmp (l->host, host))
break;
}
if (l)
diff --git a/src/openssl.c b/src/openssl.c
index 5127b87..7a8bc81 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -564,7 +564,7 @@ ssl_connect_wget (int fd, const char *hostname)
not bar.com [or foo.bar.com]."
If the pattern contain no wildcards, pattern_match(a, b) is
- equivalent to !strcasecmp(a, b). */
+ equivalent to !strcasecmp(a, b) in a C locale. */
static bool
pattern_match (const char *pattern, const char *string)
diff --git a/src/progress.c b/src/progress.c
index f813714..0a3ad8b 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -42,6 +42,7 @@ as that of the covered work. */
#include "progress.h"
#include "utils.h"
#include "retr.h"
+#include "c-strcase.h"
struct progress_implementation {
const char *name;
diff --git a/src/recur.c b/src/recur.c
index 1121e5a..ea45fa8 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -568,7 +568,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
the parent page when in -p mode. */
if (opt.no_parent
&& schemes_are_similar_p (u->scheme, start_url_parsed->scheme)
- && 0 == strcasecmp (u->host, start_url_parsed->host)
+ && 0 == c_strcasecmp (u->host, start_url_parsed->host)
&& (u->scheme != start_url_parsed->scheme
|| u->port == start_url_parsed->port)
&& !(opt.page_requisites && upos->link_inline_p))
@@ -625,7 +625,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
/* 7. */
if (schemes_are_similar_p (u->scheme, parent->scheme))
- if (!opt.spanhost && 0 != strcasecmp (parent->host, u->host))
+ if (!opt.spanhost && 0 != c_strcasecmp (parent->host, u->host))
{
DEBUGP (("This is not the same hostname as the parent's (%s and %s).\n",
u->host, parent->host));
diff --git a/src/res.c b/src/res.c
index 1c74481..4af31bf 100644
--- a/src/res.c
+++ b/src/res.c
@@ -81,6 +81,7 @@ as that of the covered work. */
#include "url.h"
#include "retr.h"
#include "res.h"
+#include "c-strcase.h"
#ifdef TESTING
#include "test.h"
diff --git a/src/url.c b/src/url.c
index 3e1f664..7643b9a 100644
--- a/src/url.c
+++ b/src/url.c
@@ -41,6 +41,7 @@ as that of the covered work. */
#include "utils.h"
#include "url.h"
#include "host.h" /* for is_valid_ipv6_address */
+#include "c-strcase.h"
#ifdef __VMS
#include "vms.h"
@@ -428,7 +429,7 @@ url_scheme (const char *url)
int i;
for (i = 0; supported_schemes[i].leading_string; i++)
- if (0 == strncasecmp (url, supported_schemes[i].leading_string,
+ if (0 == c_strncasecmp (url, supported_schemes[i].leading_string,
strlen (supported_schemes[i].leading_string)))
{
if (!(supported_schemes[i].flags & scm_disabled))
@@ -956,7 +957,7 @@ url_error (const char *url, int error_code)
if ((p = strchr (scheme, ':')))
*p = '\0';
- if (!strcasecmp (scheme, "https"))
+ if (!c_strcasecmp (scheme, "https"))
error = aprintf (_("HTTPS support not compiled in"));
else
error = aprintf (_(parse_errors[error_code]), quote (scheme));
diff --git a/src/utils.c b/src/utils.c
index d82f15c..c632938 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -99,6 +99,7 @@ as that of the covered work. */
#endif
#include "exits.h"
+#include "c-strcase.h"
static void _Noreturn
memfatal (const char *context, long attempted_size)
@@ -1038,7 +1039,7 @@ match_tail (const char *string, const char *tail, bool fold_case)
if (!fold_case)
return !strcmp (string + pos, tail);
else
- return !strcasecmp (string + pos, tail);
+ return !c_strcasecmp (string + pos, tail);
}
/* Checks whether string S matches each element of ACCEPTS. A list
@@ -1070,7 +1071,7 @@ in_acclist (const char *const *accepts, const char *s, bool backward)
else
{
int cmp = opt.ignore_case
- ? strcasecmp (s, *accepts) : strcmp (s, *accepts);
+ ? c_strcasecmp (s, *accepts) : strcmp (s, *accepts);
if (cmp == 0)
return true;
}
@@ -1121,11 +1122,11 @@ has_html_suffix_p (const char *fname)
if ((suf = suffix (fname)) == NULL)
return false;
- if (!strcasecmp (suf, "html"))
+ if (!c_strcasecmp (suf, "html"))
return true;
- if (!strcasecmp (suf, "htm"))
+ if (!c_strcasecmp (suf, "htm"))
return true;
- if (suf[0] && !strcasecmp (suf + 1, "html"))
+ if (suf[0] && !c_strcasecmp (suf + 1, "html"))
return true;
return false;
}
diff --git a/src/wget.h b/src/wget.h
index 53f9011..81ac702 100644
--- a/src/wget.h
+++ b/src/wget.h
@@ -266,7 +266,7 @@ typedef double SUM_SIZE_INT;
/* The same as above, except the comparison is case-insensitive. */
#define BOUNDED_EQUAL_NO_CASE(beg, end, string_literal) \
((end) - (beg) == sizeof (string_literal) - 1 \
- && !strncasecmp (beg, string_literal, sizeof (string_literal) - 1))
+ && !c_strncasecmp (beg, string_literal, sizeof (string_literal) - 1))
/* Like ptr=strdup(str), but allocates the space for PTR on the stack.
This cannot be an expression because this is not portable:
--
2.1.3