aboutsummaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-27 15:28:17 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-27 16:29:06 +0100
commit6353beb60ceafbc743bde96684d666582195192f (patch)
tree687bac388242712508944574531af67b14658b9c /http.c
parentd783e794c2fa6a9e6bffff9f41cdb7e8033bf3c3 (diff)
Add http_strcasecmp(3)HEADmaster
POSIX.1-2008 does not any locale-specific version of strcasecmp(3), so conversions to lowercase depend on the system locale. Since HTTP header fields must be checked without case sensitivity and not depend on the system locale, a specialised function that forces the "POSIX" locale is required.
Diffstat (limited to 'http.c')
-rw-r--r--http.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/http.c b/http.c
index c3c36b2..451ec88 100644
--- a/http.c
+++ b/http.c
@@ -2975,6 +2975,32 @@ end:
return ret;
}
+int http_strcasecmp(const char *s1, const char *s2)
+{
+ int ret = -1;
+ const locale_t l = newlocale(LC_CTYPE_MASK, "POSIX", (locale_t)0);
+
+ if (l == (locale_t)0)
+ {
+ fprintf(stderr, "%s: newlocale(3): %s\n", __func__, strerror(errno));
+ goto end;
+ }
+
+ while (*s1 && *s2)
+ if (tolower_l(*s1++, l) != tolower_l(*s2++, l))
+ {
+ ret = 1;
+ goto end;
+ }
+
+ ret = !!*s1 || !!*s2;
+end:
+ if (l != (locale_t)0)
+ freelocale(l);
+
+ return ret;
+}
+
int http_strncasecmp(const char *s1, const char *s2, const size_t n)
{
int ret = -1;