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