aboutsummaryrefslogtreecommitdiffstats
path: root/util/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/compat.c')
-rw-r--r--util/compat.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/util/compat.c b/util/compat.c
index aca558aee..cd487e5e2 100644
--- a/util/compat.c
+++ b/util/compat.c
@@ -1,3 +1,5 @@
+#include <sys/types.h>
+
int
hextobyte (const char *s)
{
@@ -22,3 +24,71 @@ hextobyte (const char *s)
return -1;
return c;
}
+
+int
+ascii_toupper (int c)
+{
+ if (c >= 'a' && c <= 'z')
+ c &= ~0x20;
+ return c;
+}
+
+int
+ascii_tolower (int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ c |= 0x20;
+ return c;
+}
+
+int
+ascii_strcasecmp (const char *a, const char *b)
+{
+ const unsigned char *p1 = (const unsigned char *)a;
+ const unsigned char *p2 = (const unsigned char *)b;
+ unsigned char c1, c2;
+
+ if (p1 == p2)
+ return 0;
+
+ do
+ {
+ c1 = ascii_tolower (*p1);
+ c2 = ascii_tolower (*p2);
+
+ if (c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ return c1 - c2;
+}
+
+int
+ascii_strncasecmp (const char *a, const char *b, size_t n)
+{
+ const unsigned char *p1 = (const unsigned char *)a;
+ const unsigned char *p2 = (const unsigned char *)b;
+ unsigned char c1, c2;
+
+ if (p1 == p2 || !n )
+ return 0;
+
+ do
+ {
+ c1 = ascii_tolower (*p1);
+ c2 = ascii_tolower (*p2);
+
+ if ( !--n || c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ return c1 - c2;
+}