summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-20 07:21:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:51 -0500
commit9c69372fb2e7ab9b4100e0e3ea10142a38a4df97 (patch)
treee4b2c8d7f01e7b27f9ee288ba9239a1a262186fc
parent67cb7c9451f310ee6ae66c916b6b25a5914e46f1 (diff)
downloadsamba-9c69372fb2e7ab9b4100e0e3ea10142a38a4df97.tar.gz
samba-9c69372fb2e7ab9b4100e0e3ea10142a38a4df97.tar.bz2
samba-9c69372fb2e7ab9b4100e0e3ea10142a38a4df97.zip
r2430: got rid of StrnCaseCmp and added an accelerated version of StrCaseCmp()
for places where known ascii strings are being compared we should just use strncasecmp() and other standard library functions (with replacements via lib/replace.c if needed) (This used to be commit 869b757bba729c9ecd720e3956958efc7541f353)
-rw-r--r--source4/lib/util_str.c107
1 files changed, 78 insertions, 29 deletions
diff --git a/source4/lib/util_str.c b/source4/lib/util_str.c
index fc76aed44a..961bdb8084 100644
--- a/source4/lib/util_str.c
+++ b/source4/lib/util_str.c
@@ -118,25 +118,44 @@ char **toktocliplist(const char *ptr, int *ctok, const char *sep)
/**
Case insensitive string compararison.
**/
-
-int StrCaseCmp(const char *s, const char *t)
+static int StrCaseCmp_slow(const char *s1, const char *s2)
{
- pstring buf1, buf2;
- unix_strupper(s, strlen(s)+1, buf1, sizeof(buf1));
- unix_strupper(t, strlen(t)+1, buf2, sizeof(buf2));
- return strcmp(buf1,buf2);
+ smb_ucs2_t *u1, *u2;
+ int ret;
+
+ convert_string_allocate(CH_UNIX, CH_UTF16, s1, strlen(s1)+1, &u1);
+ convert_string_allocate(CH_UNIX, CH_UTF16, s2, strlen(s2)+1, &u2);
+
+ ret = strcasecmp_w(u1, u2);
+
+ free(u1);
+ free(u2);
+
+ return ret;
}
/**
- Case insensitive string compararison, length limited.
+ Case insensitive string compararison, accelerated version
**/
-
-int StrnCaseCmp(const char *s, const char *t, size_t n)
+int StrCaseCmp(const char *s1, const char *s2)
{
- pstring buf1, buf2;
- unix_strupper(s, strlen(s)+1, buf1, sizeof(buf1));
- unix_strupper(t, strlen(t)+1, buf2, sizeof(buf2));
- return strncmp(buf1,buf2,n);
+ while (*s1 && *s2 &&
+ (*s1 & 0x80) == 0 &&
+ (*s2 & 0x80) == 0) {
+ char u1 = toupper(*s1);
+ char u2 = toupper(*s2);
+ if (u1 != u2) {
+ return u2 - u1;
+ }
+ s1++;
+ s2++;
+ }
+
+ if (*s1 == 0 || *s2 == 0) {
+ return *s2 - *s1;
+ }
+
+ return StrCaseCmp_slow(s1, s2);
}
/**
@@ -155,21 +174,6 @@ BOOL strequal(const char *s1, const char *s2)
}
/**
- * Compare 2 strings up to and including the nth char.
- *
- * @note The comparison is case-insensitive.
- **/
-BOOL strnequal(const char *s1,const char *s2,size_t n)
-{
- if (s1 == s2)
- return(True);
- if (!s1 || !s2 || !n)
- return(False);
-
- return(StrnCaseCmp(s1,s2,n)==0);
-}
-
-/**
Compare 2 strings (case sensitive).
**/
@@ -1196,7 +1200,7 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex)
char *p1 = NULL, *p2 = NULL;
for (i = 0; i < len && strhex[i] != 0; i++) {
- if (strnequal(hexchars, "0x", 2)) {
+ if (strncasecmp(hexchars, "0x", 2) == 0) {
i++; /* skip two chars */
continue;
}
@@ -1460,3 +1464,48 @@ int strcmp_safe(const char *s1, const char *s2)
}
return strcmp(s1, s2);
}
+
+
+/*******************************************************************
+ Return a string representing a CIFS attribute for a file.
+********************************************************************/
+char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib)
+{
+ int i, len;
+ const struct {
+ char c;
+ uint16_t attr;
+ } attr_strs[] = {
+ {'V', FILE_ATTRIBUTE_VOLUME},
+ {'D', FILE_ATTRIBUTE_DIRECTORY},
+ {'A', FILE_ATTRIBUTE_ARCHIVE},
+ {'H', FILE_ATTRIBUTE_HIDDEN},
+ {'S', FILE_ATTRIBUTE_SYSTEM},
+ {'R', FILE_ATTRIBUTE_READONLY},
+ {'d', FILE_ATTRIBUTE_DEVICE},
+ {'t', FILE_ATTRIBUTE_TEMPORARY},
+ {'s', FILE_ATTRIBUTE_SPARSE},
+ {'r', FILE_ATTRIBUTE_REPARSE_POINT},
+ {'c', FILE_ATTRIBUTE_COMPRESSED},
+ {'o', FILE_ATTRIBUTE_OFFLINE},
+ {'n', FILE_ATTRIBUTE_NONINDEXED},
+ {'e', FILE_ATTRIBUTE_ENCRYPTED}
+ };
+ char *ret;
+
+ ret = talloc(mem_ctx, ARRAY_SIZE(attr_strs)+1);
+ if (!ret) {
+ return NULL;
+ }
+
+ for (len=i=0; i<ARRAY_SIZE(attr_strs); i++) {
+ if (attrib & attr_strs[i].attr) {
+ ret[len++] = attr_strs[i].c;
+ }
+ }
+
+ ret[len] = 0;
+
+ return ret;
+}
+