diff options
author | Andrew Tridgell <tridge@samba.org> | 2006-03-21 11:37:11 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:59:01 -0500 |
commit | 2216af23c70ec8dee7162aaf35be5aed60a1a8ca (patch) | |
tree | 8f38c00a664762eb1afb4d57df11f62ad60dedf3 /source4 | |
parent | 9c97e1ec64a0da0248ec24568e223a7aecc9c536 (diff) | |
download | samba-2216af23c70ec8dee7162aaf35be5aed60a1a8ca.tar.gz samba-2216af23c70ec8dee7162aaf35be5aed60a1a8ca.tar.bz2 samba-2216af23c70ec8dee7162aaf35be5aed60a1a8ca.zip |
r14612: added strncasecmp_m() and fixed strcasecmp_m() for invalid codepoints
(This used to be commit 12b533450bdb31b57154940898f2f02c49e96ed1)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/util/util_str.c | 39 |
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; } |