This source file includes following definitions.
- UniStrcat
- UniStrchr
- UniStrcmp
- UniStrcpy
- UniStrlen
- UniStrnlen
- UniStrncat
- UniStrncmp
- UniStrncmp_le
- UniStrncpy
- UniStrncpy_le
- UniStrstr
- UniToupper
- UniStrupr
- UniTolower
- UniStrlwr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _CIFS_UNICODE_H
19 #define _CIFS_UNICODE_H
20
21 #include <asm/byteorder.h>
22 #include <linux/types.h>
23 #include <linux/nls.h>
24
25 #define UNIUPR_NOLOWER
26
27
28
29
30
31
32 #define UNI_ASTERISK (__u16) ('*' + 0xF000)
33 #define UNI_QUESTION (__u16) ('?' + 0xF000)
34 #define UNI_COLON (__u16) (':' + 0xF000)
35 #define UNI_GRTRTHAN (__u16) ('>' + 0xF000)
36 #define UNI_LESSTHAN (__u16) ('<' + 0xF000)
37 #define UNI_PIPE (__u16) ('|' + 0xF000)
38 #define UNI_SLASH (__u16) ('\\' + 0xF000)
39
40
41
42
43
44
45 #define SFM_DOUBLEQUOTE ((__u16) 0xF020)
46 #define SFM_ASTERISK ((__u16) 0xF021)
47 #define SFM_QUESTION ((__u16) 0xF025)
48 #define SFM_COLON ((__u16) 0xF022)
49 #define SFM_GRTRTHAN ((__u16) 0xF024)
50 #define SFM_LESSTHAN ((__u16) 0xF023)
51 #define SFM_PIPE ((__u16) 0xF027)
52 #define SFM_SLASH ((__u16) 0xF026)
53 #define SFM_SPACE ((__u16) 0xF028)
54 #define SFM_PERIOD ((__u16) 0xF029)
55
56
57
58
59
60
61
62
63
64
65
66
67 #define NO_MAP_UNI_RSVD 0
68 #define SFM_MAP_UNI_RSVD 1
69 #define SFU_MAP_UNI_RSVD 2
70
71
72
73
74 #ifndef UNICASERANGE_DEFINED
75 struct UniCaseRange {
76 wchar_t start;
77 wchar_t end;
78 signed char *table;
79 };
80 #endif
81
82 #ifndef UNIUPR_NOUPPER
83 extern signed char CifsUniUpperTable[512];
84 extern const struct UniCaseRange CifsUniUpperRange[];
85 #endif
86
87 #ifndef UNIUPR_NOLOWER
88 extern signed char CifsUniLowerTable[512];
89 extern const struct UniCaseRange CifsUniLowerRange[];
90 #endif
91
92 #ifdef __KERNEL__
93 int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
94 const struct nls_table *cp, int map_type);
95 int cifs_utf16_bytes(const __le16 *from, int maxbytes,
96 const struct nls_table *codepage);
97 int cifs_strtoUTF16(__le16 *, const char *, int, const struct nls_table *);
98 char *cifs_strndup_from_utf16(const char *src, const int maxlen,
99 const bool is_unicode,
100 const struct nls_table *codepage);
101 extern int cifsConvertToUTF16(__le16 *target, const char *source, int maxlen,
102 const struct nls_table *cp, int mapChars);
103 extern int cifs_remap(struct cifs_sb_info *cifs_sb);
104 extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen,
105 int *utf16_len, const struct nls_table *cp,
106 int remap);
107 #endif
108
109 wchar_t cifs_toupper(wchar_t in);
110
111
112
113
114
115
116
117 static inline __le16 *
118 UniStrcat(__le16 *ucs1, const __le16 *ucs2)
119 {
120 __le16 *anchor = ucs1;
121
122 while (*ucs1++) ;
123 ucs1--;
124 while ((*ucs1++ = *ucs2++)) ;
125 return anchor;
126 }
127
128
129
130
131
132
133
134
135 static inline wchar_t *
136 UniStrchr(const wchar_t *ucs, wchar_t uc)
137 {
138 while ((*ucs != uc) && *ucs)
139 ucs++;
140
141 if (*ucs == uc)
142 return (wchar_t *) ucs;
143 return NULL;
144 }
145
146
147
148
149
150
151
152
153
154 static inline int
155 UniStrcmp(const wchar_t *ucs1, const wchar_t *ucs2)
156 {
157 while ((*ucs1 == *ucs2) && *ucs1) {
158 ucs1++;
159 ucs2++;
160 }
161 return (int) *ucs1 - (int) *ucs2;
162 }
163
164
165
166
167 static inline wchar_t *
168 UniStrcpy(wchar_t *ucs1, const wchar_t *ucs2)
169 {
170 wchar_t *anchor = ucs1;
171
172 while ((*ucs1++ = *ucs2++)) ;
173 return anchor;
174 }
175
176
177
178
179 static inline size_t
180 UniStrlen(const wchar_t *ucs1)
181 {
182 int i = 0;
183
184 while (*ucs1++)
185 i++;
186 return i;
187 }
188
189
190
191
192
193 static inline size_t
194 UniStrnlen(const wchar_t *ucs1, int maxlen)
195 {
196 int i = 0;
197
198 while (*ucs1++) {
199 i++;
200 if (i >= maxlen)
201 break;
202 }
203 return i;
204 }
205
206
207
208
209 static inline wchar_t *
210 UniStrncat(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
211 {
212 wchar_t *anchor = ucs1;
213
214 while (*ucs1++) ;
215 ucs1--;
216 while (n-- && (*ucs1 = *ucs2)) {
217 ucs1++;
218 ucs2++;
219 }
220 *ucs1 = 0;
221 return (anchor);
222 }
223
224
225
226
227 static inline int
228 UniStrncmp(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
229 {
230 if (!n)
231 return 0;
232 while ((*ucs1 == *ucs2) && *ucs1 && --n) {
233 ucs1++;
234 ucs2++;
235 }
236 return (int) *ucs1 - (int) *ucs2;
237 }
238
239
240
241
242 static inline int
243 UniStrncmp_le(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
244 {
245 if (!n)
246 return 0;
247 while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
248 ucs1++;
249 ucs2++;
250 }
251 return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
252 }
253
254
255
256
257 static inline wchar_t *
258 UniStrncpy(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
259 {
260 wchar_t *anchor = ucs1;
261
262 while (n-- && *ucs2)
263 *ucs1++ = *ucs2++;
264
265 n++;
266 while (n--)
267 *ucs1++ = 0;
268 return anchor;
269 }
270
271
272
273
274 static inline wchar_t *
275 UniStrncpy_le(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
276 {
277 wchar_t *anchor = ucs1;
278
279 while (n-- && *ucs2)
280 *ucs1++ = __le16_to_cpu(*ucs2++);
281
282 n++;
283 while (n--)
284 *ucs1++ = 0;
285 return anchor;
286 }
287
288
289
290
291
292
293
294
295 static inline wchar_t *
296 UniStrstr(const wchar_t *ucs1, const wchar_t *ucs2)
297 {
298 const wchar_t *anchor1 = ucs1;
299 const wchar_t *anchor2 = ucs2;
300
301 while (*ucs1) {
302 if (*ucs1 == *ucs2) {
303
304 ucs1++;
305 ucs2++;
306 } else {
307 if (!*ucs2)
308 return (wchar_t *) anchor1;
309 ucs1 = ++anchor1;
310 ucs2 = anchor2;
311 }
312 }
313
314 if (!*ucs2)
315 return (wchar_t *) anchor1;
316 return NULL;
317 }
318
319 #ifndef UNIUPR_NOUPPER
320
321
322
323 static inline wchar_t
324 UniToupper(register wchar_t uc)
325 {
326 register const struct UniCaseRange *rp;
327
328 if (uc < sizeof(CifsUniUpperTable)) {
329
330 return uc + CifsUniUpperTable[uc];
331 } else {
332 rp = CifsUniUpperRange;
333 while (rp->start) {
334 if (uc < rp->start)
335 return uc;
336 if (uc <= rp->end)
337 return uc + rp->table[uc - rp->start];
338 rp++;
339 }
340 }
341 return uc;
342 }
343
344
345
346
347 static inline __le16 *
348 UniStrupr(register __le16 *upin)
349 {
350 register __le16 *up;
351
352 up = upin;
353 while (*up) {
354 *up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
355 up++;
356 }
357 return upin;
358 }
359 #endif
360
361 #ifndef UNIUPR_NOLOWER
362
363
364
365 static inline wchar_t
366 UniTolower(register wchar_t uc)
367 {
368 register const struct UniCaseRange *rp;
369
370 if (uc < sizeof(CifsUniLowerTable)) {
371
372 return uc + CifsUniLowerTable[uc];
373 } else {
374 rp = CifsUniLowerRange;
375 while (rp->start) {
376 if (uc < rp->start)
377 return uc;
378 if (uc <= rp->end)
379 return uc + rp->table[uc - rp->start];
380 rp++;
381 }
382 }
383 return uc;
384 }
385
386
387
388
389 static inline wchar_t *
390 UniStrlwr(register wchar_t *upin)
391 {
392 register wchar_t *up;
393
394 up = upin;
395 while (*up) {
396 *up = UniTolower(*up);
397 up++;
398 }
399 return upin;
400 }
401
402 #endif
403
404 #endif