aboutsummaryrefslogtreecommitdiffstats
path: root/util/strgutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/strgutil.c')
-rw-r--r--util/strgutil.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/util/strgutil.c b/util/strgutil.c
index 858d603e0..e793fc1ce 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -687,18 +687,58 @@ ascii_tolower (int c)
int
-ascii_strcasecmp( const char *a, const char *b )
+ascii_strcasecmp (const char *a, const char *b)
{
- if (a == b)
- return 0;
+ const unsigned char *p1 = (const unsigned char *)a;
+ const unsigned char *p2 = (const unsigned char *)b;
+ unsigned char c1, c2;
- for (; *a && *b; a++, b++) {
- if (*a != *b && ascii_toupper(*a) != ascii_toupper(*b))
- break;
+ if (p1 == p2)
+ return 0;
+
+ do
+ {
+ c1 = ascii_tolower (*p1);
+ c2 = ascii_tolower (*p2);
+
+ if (c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
}
- return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
+ 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;
+}
+
+
int
ascii_memcasecmp( const char *a, const char *b, size_t n )
{
@@ -712,6 +752,7 @@ ascii_memcasecmp( const char *a, const char *b, size_t n )
}
+
/*********************************************
********** missing string functions *********
*********************************************/