summaryrefslogtreecommitdiff
path: root/source3/lib/util_str.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-05-13 20:23:36 +0200
committerAndrew Bartlett <abartlet@samba.org>2011-05-18 16:12:08 +0200
commitda662b82b87cdbe07762974b1f9e825ef15951bd (patch)
treef29813bc62f28b9bb73f835828c7f6d3ecbcc872 /source3/lib/util_str.c
parentc615ebed6e3d273a682806b952d543e834e5630d (diff)
downloadsamba-da662b82b87cdbe07762974b1f9e825ef15951bd.tar.gz
samba-da662b82b87cdbe07762974b1f9e825ef15951bd.tar.bz2
samba-da662b82b87cdbe07762974b1f9e825ef15951bd.zip
s3-lib Replace StrnCaseCmp() with strncasecmp_m()
strncasecmp_m() never needs to call to talloc, and via next_codepoint() still has an ASCII fast-path bypassing iconv() calls. Andrew Bartlett
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r--source3/lib/util_str.c62
1 files changed, 1 insertions, 61 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index ee36930fd1..bb8482ca0b 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -36,66 +36,6 @@ const char toupper_ascii_fast_table[128] = {
};
/**
- Case insensitive string compararison, length limited.
-**/
-int StrnCaseCmp(const char *s, const char *t, size_t len)
-{
- size_t n = 0;
- const char *ps, *pt;
- size_t size;
- smb_ucs2_t *buffer_s, *buffer_t;
- int ret;
-
- for (ps = s, pt = t; n < len ; ps++, pt++, n++) {
- char us, ut;
-
- if (!*ps && !*pt)
- return 0; /* both ended */
- else if (!*ps)
- return -1; /* s is a prefix */
- else if (!*pt)
- return +1; /* t is a prefix */
- else if ((*ps & 0x80) || (*pt & 0x80))
- /* not ascii anymore, do it the
- * hard way from here on in */
- break;
-
- us = toupper_ascii_fast(*ps);
- ut = toupper_ascii_fast(*pt);
- if (us == ut)
- continue;
- else if (us < ut)
- return -1;
- else if (us > ut)
- return +1;
- }
-
- if (n == len) {
- return 0;
- }
-
- if (!push_ucs2_talloc(talloc_tos(), &buffer_s, ps, &size)) {
- return strncmp(ps, pt, len-n);
- /* Not quite the right answer, but finding the right one
- under this failure case is expensive,
- and it's pretty close */
- }
-
- if (!push_ucs2_talloc(talloc_tos(), &buffer_t, pt, &size)) {
- TALLOC_FREE(buffer_s);
- return strncmp(ps, pt, len-n);
- /* Not quite the right answer, but finding the right one
- under this failure case is expensive,
- and it's pretty close */
- }
-
- ret = strncasecmp_w(buffer_s, buffer_t, len-n);
- TALLOC_FREE(buffer_s);
- TALLOC_FREE(buffer_t);
- return ret;
-}
-
-/**
* Compare 2 strings up to and including the nth char.
*
* @note The comparison is case-insensitive.
@@ -107,7 +47,7 @@ bool strnequal(const char *s1,const char *s2,size_t n)
if (!s1 || !s2 || !n)
return(false);
- return(StrnCaseCmp(s1,s2,n)==0);
+ return(strncasecmp_m(s1,s2,n)==0);
}
/**