summaryrefslogtreecommitdiff
path: root/source4/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/util')
-rw-r--r--source4/lib/util/util_str.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c
index 4bb3ea1b54..8f408c00dc 100644
--- a/source4/lib/util/util_str.c
+++ b/source4/lib/util/util_str.c
@@ -101,14 +101,53 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
if (c1 == INVALID_CODEPOINT ||
c2 == INVALID_CODEPOINT) {
/* what else can we do?? */
+ return strcasecmp(s1, s2);
+ }
+
+ if (toupper_w(c1) != toupper_w(c2)) {
return c1 - c2;
}
+ }
+
+ return *s1 - *s2;
+}
+
+/**
+ Case insensitive string compararison, length limited
+**/
+_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
+{
+ codepoint_t c1=0, c2=0;
+ size_t size1, size2;
+
+ while (*s1 && *s2 && n) {
+ n--;
+
+ c1 = next_codepoint(s1, &size1);
+ c2 = next_codepoint(s2, &size2);
+
+ s1 += size1;
+ s2 += size2;
+
+ if (c1 == c2) {
+ continue;
+ }
+
+ if (c1 == INVALID_CODEPOINT ||
+ c2 == INVALID_CODEPOINT) {
+ /* what else can we do?? */
+ return strcasecmp(s1, s2);
+ }
if (toupper_w(c1) != toupper_w(c2)) {
return c1 - c2;
}
}
+ if (n == 0) {
+ return 0;
+ }
+
return *s1 - *s2;
}