int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b) { smb_ucs2_t cpa, cpb; while ((*COPY_UCS2_CHAR(&cpb,b)) && toupper_w(*(COPY_UCS2_CHAR(&cpa,a))) == toupper_w(cpb)) { a++; b++; } return (tolower_w(*(COPY_UCS2_CHAR(&cpa,a))) - tolower_w(*(COPY_UCS2_CHAR(&cpb,b)))); }
int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len) { smb_ucs2_t cpa, cpb; size_t n = 0; while ((n < len) && *COPY_UCS2_CHAR(&cpb,b) && (toupper_w(*(COPY_UCS2_CHAR(&cpa,a))) == toupper_w(cpb))) { a++; b++; n++; } return (len - n)?(tolower_w(*(COPY_UCS2_CHAR(&cpa,a))) - tolower_w(*(COPY_UCS2_CHAR(&cpb,b)))):0; }
/******************************************************************* Convert a string to upper case. return True if any char is converted ********************************************************************/ BOOL strupper_w(smb_ucs2_t *s) { BOOL ret = False; while (*s) { smb_ucs2_t v = toupper_w(*s); if (v != *s) { *s = v; ret = True; } s++; } return ret; }
BOOL strupper_w(smb_ucs2_t *s) { smb_ucs2_t cp; BOOL ret = False; while (*(COPY_UCS2_CHAR(&cp,s))) { smb_ucs2_t v = toupper_w(cp); if (v != cp) { COPY_UCS2_CHAR(s,&v); ret = True; } s++; } return ret; }
size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; size_t src_len; size_t ret; /* treat a pstring as "unlimited" length */ if (dest_len == (size_t)-1) dest_len = sizeof(pstring); if (flags & STR_TERMINATE) src_len = (size_t)-1; else src_len = strlen(src); if (ucs2_align(base_ptr, dest, flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); if (dest_len) dest_len--; len++; } /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { return 0; } len += ret; if (flags & STR_UPPER) { smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest; size_t i; /* We check for i < (ret / 2) below as the dest string isn't null terminated if STR_TERMINATE isn't set. */ for (i = 0; i < (ret / 2) && i < (dest_len / 2) && dest_ucs2[i]; i++) { smb_ucs2_t v = toupper_w(dest_ucs2[i]); if (v != dest_ucs2[i]) { dest_ucs2[i] = v; } } } return len; }
int toupper_ascii(int c) { smb_ucs2_t uc = toupper_w(UCS2_CHAR(c)); return UCS2_TO_CHAR(uc); }
/******************************************************************* case insensitive string comparison, lenght limited ********************************************************************/ int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len) { size_t n = 0; while ((n < len) && *b && (toupper_w(*a) == toupper_w(*b))) { a++; b++; n++; } return (len - n)?(tolower_w(*a) - tolower_w(*b)):0; }
/******************************************************************* case insensitive string comparison ********************************************************************/ int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b) { while (*b && toupper_w(*a) == toupper_w(*b)) { a++; b++; } return (tolower_w(*a) - tolower_w(*b)); }
/* p and n are the pattern and string being matched. The max_n array is an optimisation only. The ldot pointer is NULL if the string does not contain a '.', otherwise it points at the last dot in 'n'. */ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n, struct max_n *max_n, const smb_ucs2_t *ldot, bool is_case_sensitive) { smb_ucs2_t c; int i; while ((c = *p++)) { switch (c) { /* a '*' matches zero or more characters of any type */ case UCS2_CHAR('*'): if (max_n->predot && max_n->predot <= n) { return null_match(p); } for (i=0; n[i]; i++) { if (ms_fnmatch_core(p, n+i, max_n+1, ldot, is_case_sensitive) == 0) { return 0; } } if (!max_n->predot || max_n->predot > n) max_n->predot = n; return null_match(p); /* a '<' matches zero or more characters of any type, but stops matching at the last '.' in the string. */ case UCS2_CHAR('<'): if (max_n->predot && max_n->predot <= n) { return null_match(p); } if (max_n->postdot && max_n->postdot <= n && n <= ldot) { return -1; } for (i=0; n[i]; i++) { if (ms_fnmatch_core(p, n+i, max_n+1, ldot, is_case_sensitive) == 0) return 0; if (n+i == ldot) { if (ms_fnmatch_core(p, n+i+1, max_n+1, ldot, is_case_sensitive) == 0) return 0; if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n; return -1; } } if (!max_n->predot || max_n->predot > n) max_n->predot = n; return null_match(p); /* a '?' matches any single character */ case UCS2_CHAR('?'): if (! *n) { return -1; } n++; break; /* a '?' matches any single character */ case UCS2_CHAR('>'): if (n[0] == UCS2_CHAR('.')) { if (! n[1] && null_match(p) == 0) { return 0; } break; } if (! *n) return null_match(p); n++; break; case UCS2_CHAR('"'): if (*n == 0 && null_match(p) == 0) { return 0; } if (*n != UCS2_CHAR('.')) return -1; n++; break; default: if (c != *n) { if (is_case_sensitive) { return -1; } if (toupper_w(c) != toupper_w(*n)) { return -1; } } n++; break; } } if (! *n) { return 0; } return -1; }