Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * cifs_unicode: Unicode kernel case support |
| 3 | * |
| 4 | * Function: |
| 5 | * Convert a unicode character to upper or lower case using |
| 6 | * compressed tables. |
| 7 | * |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 8 | * Copyright (c) International Business Machines Corp., 2000,2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
Steve French | d38d8c7 | 2007-06-28 19:44:13 +0000 | [diff] [blame] | 12 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * (at your option) any later version. |
Steve French | d38d8c7 | 2007-06-28 19:44:13 +0000 | [diff] [blame] | 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 18 | * the GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
Steve French | d38d8c7 | 2007-06-28 19:44:13 +0000 | [diff] [blame] | 21 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * |
| 25 | * Notes: |
| 26 | * These APIs are based on the C library functions. The semantics |
| 27 | * should match the C functions but with expanded size operands. |
| 28 | * |
| 29 | * The upper/lower functions are based on a table created by mkupr. |
| 30 | * This is a compressed table of upper and lower case conversion. |
| 31 | * |
| 32 | */ |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 33 | #ifndef _CIFS_UNICODE_H |
| 34 | #define _CIFS_UNICODE_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/byteorder.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <linux/nls.h> |
| 39 | |
| 40 | #define UNIUPR_NOLOWER /* Example to not expand lower case tables */ |
| 41 | |
Jeff Layton | 66345f5 | 2009-04-30 06:45:08 -0400 | [diff] [blame] | 42 | /* |
| 43 | * Windows maps these to the user defined 16 bit Unicode range since they are |
| 44 | * reserved symbols (along with \ and /), otherwise illegal to store |
| 45 | * in filenames in NTFS |
| 46 | */ |
Jeff Layton | 581ade4 | 2011-04-05 15:02:37 -0400 | [diff] [blame] | 47 | #define UNI_ASTERISK (__u16) ('*' + 0xF000) |
Jeff Layton | 66345f5 | 2009-04-30 06:45:08 -0400 | [diff] [blame] | 48 | #define UNI_QUESTION (__u16) ('?' + 0xF000) |
| 49 | #define UNI_COLON (__u16) (':' + 0xF000) |
| 50 | #define UNI_GRTRTHAN (__u16) ('>' + 0xF000) |
| 51 | #define UNI_LESSTHAN (__u16) ('<' + 0xF000) |
| 52 | #define UNI_PIPE (__u16) ('|' + 0xF000) |
| 53 | #define UNI_SLASH (__u16) ('\\' + 0xF000) |
| 54 | |
Steve French | b693855 | 2014-09-25 13:20:05 -0500 | [diff] [blame] | 55 | /* |
| 56 | * Macs use an older "SFM" mapping of the symbols above. Fortunately it does |
| 57 | * not conflict (although almost does) with the mapping above. |
| 58 | */ |
| 59 | |
Björn Jacke | 85435d7 | 2017-05-05 04:36:16 +0200 | [diff] [blame] | 60 | #define SFM_DOUBLEQUOTE ((__u16) 0xF020) |
Steve French | b693855 | 2014-09-25 13:20:05 -0500 | [diff] [blame] | 61 | #define SFM_ASTERISK ((__u16) 0xF021) |
| 62 | #define SFM_QUESTION ((__u16) 0xF025) |
| 63 | #define SFM_COLON ((__u16) 0xF022) |
| 64 | #define SFM_GRTRTHAN ((__u16) 0xF024) |
| 65 | #define SFM_LESSTHAN ((__u16) 0xF023) |
| 66 | #define SFM_PIPE ((__u16) 0xF027) |
| 67 | #define SFM_SLASH ((__u16) 0xF026) |
Björn Jacke | b704e70 | 2017-05-03 23:47:44 +0200 | [diff] [blame] | 68 | #define SFM_SPACE ((__u16) 0xF028) |
| 69 | #define SFM_PERIOD ((__u16) 0xF029) |
Steve French | b693855 | 2014-09-25 13:20:05 -0500 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Mapping mechanism to use when one of the seven reserved characters is |
| 73 | * encountered. We can only map using one of the mechanisms at a time |
| 74 | * since otherwise readdir could return directory entries which we would |
| 75 | * not be able to open |
| 76 | * |
| 77 | * NO_MAP_UNI_RSVD = do not perform any remapping of the character |
| 78 | * SFM_MAP_UNI_RSVD = map reserved characters using SFM scheme (MAC compatible) |
| 79 | * SFU_MAP_UNI_RSVD = map reserved characters ala SFU ("mapchars" option) |
| 80 | * |
| 81 | */ |
| 82 | #define NO_MAP_UNI_RSVD 0 |
| 83 | #define SFM_MAP_UNI_RSVD 1 |
| 84 | #define SFU_MAP_UNI_RSVD 2 |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* Just define what we want from uniupr.h. We don't want to define the tables |
| 87 | * in each source file. |
| 88 | */ |
| 89 | #ifndef UNICASERANGE_DEFINED |
| 90 | struct UniCaseRange { |
| 91 | wchar_t start; |
| 92 | wchar_t end; |
| 93 | signed char *table; |
| 94 | }; |
| 95 | #endif /* UNICASERANGE_DEFINED */ |
| 96 | |
| 97 | #ifndef UNIUPR_NOUPPER |
| 98 | extern signed char CifsUniUpperTable[512]; |
| 99 | extern const struct UniCaseRange CifsUniUpperRange[]; |
| 100 | #endif /* UNIUPR_NOUPPER */ |
| 101 | |
| 102 | #ifndef UNIUPR_NOLOWER |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 103 | extern signed char CifsUniLowerTable[512]; |
| 104 | extern const struct UniCaseRange CifsUniLowerRange[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #endif /* UNIUPR_NOLOWER */ |
| 106 | |
| 107 | #ifdef __KERNEL__ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 108 | int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen, |
Steve French | b693855 | 2014-09-25 13:20:05 -0500 | [diff] [blame] | 109 | const struct nls_table *cp, int map_type); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 110 | int cifs_utf16_bytes(const __le16 *from, int maxbytes, |
| 111 | const struct nls_table *codepage); |
| 112 | int cifs_strtoUTF16(__le16 *, const char *, int, const struct nls_table *); |
| 113 | char *cifs_strndup_from_utf16(const char *src, const int maxlen, |
| 114 | const bool is_unicode, |
| 115 | const struct nls_table *codepage); |
| 116 | extern int cifsConvertToUTF16(__le16 *target, const char *source, int maxlen, |
| 117 | const struct nls_table *cp, int mapChars); |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 118 | extern int cifs_remap(struct cifs_sb_info *cifs_sb); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 119 | extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen, |
| 120 | int *utf16_len, const struct nls_table *cp, |
| 121 | int remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #endif |
| 123 | |
Jeff Layton | c2ccf53 | 2013-09-05 08:38:11 -0400 | [diff] [blame] | 124 | wchar_t cifs_toupper(wchar_t in); |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | /* |
| 127 | * UniStrcat: Concatenate the second string to the first |
| 128 | * |
| 129 | * Returns: |
| 130 | * Address of the first string |
| 131 | */ |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 132 | static inline __le16 * |
| 133 | UniStrcat(__le16 *ucs1, const __le16 *ucs2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 135 | __le16 *anchor = ucs1; /* save a pointer to start of ucs1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | while (*ucs1++) ; /* To end of first string */ |
| 138 | ucs1--; /* Return to the null */ |
| 139 | while ((*ucs1++ = *ucs2++)) ; /* copy string 2 over */ |
| 140 | return anchor; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * UniStrchr: Find a character in a string |
| 145 | * |
| 146 | * Returns: |
| 147 | * Address of first occurrence of character in string |
| 148 | * or NULL if the character is not in the string |
| 149 | */ |
| 150 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 151 | UniStrchr(const wchar_t *ucs, wchar_t uc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | while ((*ucs != uc) && *ucs) |
| 154 | ucs++; |
| 155 | |
| 156 | if (*ucs == uc) |
| 157 | return (wchar_t *) ucs; |
| 158 | return NULL; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * UniStrcmp: Compare two strings |
| 163 | * |
| 164 | * Returns: |
| 165 | * < 0: First string is less than second |
| 166 | * = 0: Strings are equal |
| 167 | * > 0: First string is greater than second |
| 168 | */ |
| 169 | static inline int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 170 | UniStrcmp(const wchar_t *ucs1, const wchar_t *ucs2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | while ((*ucs1 == *ucs2) && *ucs1) { |
| 173 | ucs1++; |
| 174 | ucs2++; |
| 175 | } |
| 176 | return (int) *ucs1 - (int) *ucs2; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * UniStrcpy: Copy a string |
| 181 | */ |
| 182 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 183 | UniStrcpy(wchar_t *ucs1, const wchar_t *ucs2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | wchar_t *anchor = ucs1; /* save the start of result string */ |
| 186 | |
| 187 | while ((*ucs1++ = *ucs2++)) ; |
| 188 | return anchor; |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * UniStrlen: Return the length of a string (in 16 bit Unicode chars not bytes) |
| 193 | */ |
| 194 | static inline size_t |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 195 | UniStrlen(const wchar_t *ucs1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int i = 0; |
| 198 | |
| 199 | while (*ucs1++) |
| 200 | i++; |
| 201 | return i; |
| 202 | } |
| 203 | |
| 204 | /* |
Steve French | d38d8c7 | 2007-06-28 19:44:13 +0000 | [diff] [blame] | 205 | * UniStrnlen: Return the length (in 16 bit Unicode chars not bytes) of a |
| 206 | * string (length limited) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | */ |
| 208 | static inline size_t |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 209 | UniStrnlen(const wchar_t *ucs1, int maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | int i = 0; |
| 212 | |
| 213 | while (*ucs1++) { |
| 214 | i++; |
| 215 | if (i >= maxlen) |
| 216 | break; |
| 217 | } |
| 218 | return i; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * UniStrncat: Concatenate length limited string |
| 223 | */ |
| 224 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 225 | UniStrncat(wchar_t *ucs1, const wchar_t *ucs2, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | wchar_t *anchor = ucs1; /* save pointer to string 1 */ |
| 228 | |
| 229 | while (*ucs1++) ; |
| 230 | ucs1--; /* point to null terminator of s1 */ |
| 231 | while (n-- && (*ucs1 = *ucs2)) { /* copy s2 after s1 */ |
| 232 | ucs1++; |
| 233 | ucs2++; |
| 234 | } |
| 235 | *ucs1 = 0; /* Null terminate the result */ |
| 236 | return (anchor); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * UniStrncmp: Compare length limited string |
| 241 | */ |
| 242 | static inline int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 243 | UniStrncmp(const wchar_t *ucs1, const wchar_t *ucs2, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | if (!n) |
| 246 | return 0; /* Null strings are equal */ |
| 247 | while ((*ucs1 == *ucs2) && *ucs1 && --n) { |
| 248 | ucs1++; |
| 249 | ucs2++; |
| 250 | } |
| 251 | return (int) *ucs1 - (int) *ucs2; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * UniStrncmp_le: Compare length limited string - native to little-endian |
| 256 | */ |
| 257 | static inline int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 258 | UniStrncmp_le(const wchar_t *ucs1, const wchar_t *ucs2, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | if (!n) |
| 261 | return 0; /* Null strings are equal */ |
| 262 | while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) { |
| 263 | ucs1++; |
| 264 | ucs2++; |
| 265 | } |
| 266 | return (int) *ucs1 - (int) __le16_to_cpu(*ucs2); |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * UniStrncpy: Copy length limited string with pad |
| 271 | */ |
| 272 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 273 | UniStrncpy(wchar_t *ucs1, const wchar_t *ucs2, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
| 275 | wchar_t *anchor = ucs1; |
| 276 | |
| 277 | while (n-- && *ucs2) /* Copy the strings */ |
| 278 | *ucs1++ = *ucs2++; |
| 279 | |
| 280 | n++; |
| 281 | while (n--) /* Pad with nulls */ |
| 282 | *ucs1++ = 0; |
| 283 | return anchor; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * UniStrncpy_le: Copy length limited string with pad to little-endian |
| 288 | */ |
| 289 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 290 | UniStrncpy_le(wchar_t *ucs1, const wchar_t *ucs2, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | wchar_t *anchor = ucs1; |
| 293 | |
| 294 | while (n-- && *ucs2) /* Copy the strings */ |
| 295 | *ucs1++ = __le16_to_cpu(*ucs2++); |
| 296 | |
| 297 | n++; |
| 298 | while (n--) /* Pad with nulls */ |
| 299 | *ucs1++ = 0; |
| 300 | return anchor; |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * UniStrstr: Find a string in a string |
| 305 | * |
| 306 | * Returns: |
| 307 | * Address of first match found |
| 308 | * NULL if no matching string is found |
| 309 | */ |
| 310 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 311 | UniStrstr(const wchar_t *ucs1, const wchar_t *ucs2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
| 313 | const wchar_t *anchor1 = ucs1; |
| 314 | const wchar_t *anchor2 = ucs2; |
| 315 | |
| 316 | while (*ucs1) { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 317 | if (*ucs1 == *ucs2) { |
| 318 | /* Partial match found */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | ucs1++; |
| 320 | ucs2++; |
| 321 | } else { |
| 322 | if (!*ucs2) /* Match found */ |
| 323 | return (wchar_t *) anchor1; |
| 324 | ucs1 = ++anchor1; /* No match */ |
| 325 | ucs2 = anchor2; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if (!*ucs2) /* Both end together */ |
| 330 | return (wchar_t *) anchor1; /* Match found */ |
| 331 | return NULL; /* No match */ |
| 332 | } |
| 333 | |
| 334 | #ifndef UNIUPR_NOUPPER |
| 335 | /* |
| 336 | * UniToupper: Convert a unicode character to upper case |
| 337 | */ |
| 338 | static inline wchar_t |
| 339 | UniToupper(register wchar_t uc) |
| 340 | { |
| 341 | register const struct UniCaseRange *rp; |
| 342 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 343 | if (uc < sizeof(CifsUniUpperTable)) { |
| 344 | /* Latin characters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return uc + CifsUniUpperTable[uc]; /* Use base tables */ |
| 346 | } else { |
| 347 | rp = CifsUniUpperRange; /* Use range tables */ |
| 348 | while (rp->start) { |
| 349 | if (uc < rp->start) /* Before start of range */ |
| 350 | return uc; /* Uppercase = input */ |
| 351 | if (uc <= rp->end) /* In range */ |
| 352 | return uc + rp->table[uc - rp->start]; |
| 353 | rp++; /* Try next range */ |
| 354 | } |
| 355 | } |
| 356 | return uc; /* Past last range */ |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * UniStrupr: Upper case a unicode string |
| 361 | */ |
Steve French | fdf96a9 | 2013-06-25 14:03:16 -0500 | [diff] [blame] | 362 | static inline __le16 * |
| 363 | UniStrupr(register __le16 *upin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
Steve French | fdf96a9 | 2013-06-25 14:03:16 -0500 | [diff] [blame] | 365 | register __le16 *up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | up = upin; |
| 368 | while (*up) { /* For all characters */ |
Steve French | fdf96a9 | 2013-06-25 14:03:16 -0500 | [diff] [blame] | 369 | *up = cpu_to_le16(UniToupper(le16_to_cpu(*up))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | up++; |
| 371 | } |
| 372 | return upin; /* Return input pointer */ |
| 373 | } |
| 374 | #endif /* UNIUPR_NOUPPER */ |
| 375 | |
| 376 | #ifndef UNIUPR_NOLOWER |
| 377 | /* |
| 378 | * UniTolower: Convert a unicode character to lower case |
| 379 | */ |
| 380 | static inline wchar_t |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 381 | UniTolower(register wchar_t uc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 383 | register const struct UniCaseRange *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 385 | if (uc < sizeof(CifsUniLowerTable)) { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 386 | /* Latin characters */ |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 387 | return uc + CifsUniLowerTable[uc]; /* Use base tables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } else { |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 389 | rp = CifsUniLowerRange; /* Use range tables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | while (rp->start) { |
| 391 | if (uc < rp->start) /* Before start of range */ |
| 392 | return uc; /* Uppercase = input */ |
| 393 | if (uc <= rp->end) /* In range */ |
| 394 | return uc + rp->table[uc - rp->start]; |
| 395 | rp++; /* Try next range */ |
| 396 | } |
| 397 | } |
| 398 | return uc; /* Past last range */ |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * UniStrlwr: Lower case a unicode string |
| 403 | */ |
| 404 | static inline wchar_t * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 405 | UniStrlwr(register wchar_t *upin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
| 407 | register wchar_t *up; |
| 408 | |
| 409 | up = upin; |
| 410 | while (*up) { /* For all characters */ |
| 411 | *up = UniTolower(*up); |
| 412 | up++; |
| 413 | } |
| 414 | return upin; /* Return input pointer */ |
| 415 | } |
| 416 | |
| 417 | #endif |
Igor Druzhinin | bf4f121 | 2010-08-20 00:27:12 +0400 | [diff] [blame] | 418 | |
| 419 | #endif /* _CIFS_UNICODE_H */ |