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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/*
* NTDLL wide-char functions
*
* Copyright 2000 Alexandre Julliard
* Copyright 2000 Jon Griffiths
* Copyright 2003 Thomas Mertes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winternl.h"
#include "wine/unicode.h"
/*********************************************************************
* _wcsicmp (NTDLL.@)
*/
INT __cdecl NTDLL__wcsicmp( LPCWSTR str1, LPCWSTR str2 )
{
return strcmpiW( str1, str2 );
}
/*********************************************************************
* _wcslwr (NTDLL.@)
*/
LPWSTR __cdecl NTDLL__wcslwr( LPWSTR str )
{
return strlwrW( str );
}
/*********************************************************************
* _wcsnicmp (NTDLL.@)
*/
INT __cdecl NTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n )
{
return strncmpiW( str1, str2, n );
}
/*********************************************************************
* _wcsupr (NTDLL.@)
*/
LPWSTR __cdecl NTDLL__wcsupr( LPWSTR str )
{
return struprW( str );
}
/*********************************************************************
* towlower (NTDLL.@)
*/
WCHAR __cdecl NTDLL_towlower( WCHAR ch )
{
return tolowerW(ch);
}
/*********************************************************************
* towupper (NTDLL.@)
*/
WCHAR __cdecl NTDLL_towupper( WCHAR ch )
{
return toupperW(ch);
}
/***********************************************************************
* wcscat (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcscat( LPWSTR dst, LPCWSTR src )
{
return strcatW( dst, src );
}
/*********************************************************************
* wcschr (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcschr( LPCWSTR str, WCHAR ch )
{
return strchrW( str, ch );
}
/*********************************************************************
* wcscmp (NTDLL.@)
*/
INT __cdecl NTDLL_wcscmp( LPCWSTR str1, LPCWSTR str2 )
{
return strcmpW( str1, str2 );
}
/***********************************************************************
* wcscpy (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcscpy( LPWSTR dst, LPCWSTR src )
{
return strcpyW( dst, src );
}
/*********************************************************************
* wcscspn (NTDLL.@)
*/
INT __cdecl NTDLL_wcscspn( LPCWSTR str, LPCWSTR reject )
{
return strcspnW( str, reject );
}
/***********************************************************************
* wcslen (NTDLL.@)
*/
INT __cdecl NTDLL_wcslen( LPCWSTR str )
{
return strlenW( str );
}
/*********************************************************************
* wcsncat (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT n )
{
LPWSTR ret = s1;
while (*s1) s1++;
while (n-- > 0) if (!(*s1++ = *s2++)) return ret;
*s1 = 0;
return ret;
}
/*********************************************************************
* wcsncmp (NTDLL.@)
*/
INT __cdecl NTDLL_wcsncmp( LPCWSTR str1, LPCWSTR str2, INT n )
{
return strncmpW( str1, str2, n );
}
/*********************************************************************
* wcsncpy (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT n )
{
WCHAR *ret = s1;
while (n-- > 0) if (!(*s1++ = *s2++)) break;
while (n-- > 0) *s1++ = 0;
return ret;
}
/*********************************************************************
* wcspbrk (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept )
{
return strpbrkW( str, accept );
}
/*********************************************************************
* wcsrchr (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcsrchr( LPWSTR str, WCHAR ch )
{
return strrchrW( str, ch );
}
/*********************************************************************
* wcsspn (NTDLL.@)
*/
INT __cdecl NTDLL_wcsspn( LPCWSTR str, LPCWSTR accept )
{
return strspnW( str, accept );
}
/*********************************************************************
* wcsstr (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcsstr( LPCWSTR str, LPCWSTR sub )
{
return strstrW( str, sub );
}
/*********************************************************************
* wcstok (NTDLL.@)
*/
LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim )
{
static LPWSTR next = NULL;
LPWSTR ret;
if (!str)
if (!(str = next)) return NULL;
while (*str && NTDLL_wcschr( delim, *str )) str++;
if (!*str) return NULL;
ret = str++;
while (*str && !NTDLL_wcschr( delim, *str )) str++;
if (*str) *str++ = 0;
next = str;
return ret;
}
/*********************************************************************
* wcstombs (NTDLL.@)
*/
INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
{
DWORD len;
if (!dst)
{
RtlUnicodeToMultiByteSize( &len, src, strlenW(src)*sizeof(WCHAR) );
return len;
}
else
{
if (n <= 0) return 0;
RtlUnicodeToMultiByteN( dst, n, &len, src, strlenW(src)*sizeof(WCHAR) );
if (len < n) dst[len] = 0;
}
return len;
}
/*********************************************************************
* mbstowcs (NTDLL.@)
*/
INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
{
DWORD len;
if (!dst)
{
RtlMultiByteToUnicodeSize( &len, src, strlen(src) );
}
else
{
if (n <= 0) return 0;
RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) );
if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0;
}
return len / sizeof(WCHAR);
}
/*********************************************************************
* wcstol (NTDLL.@)
*/
LONG __cdecl NTDLL_wcstol(LPCWSTR s, LPWSTR *end, INT base)
{
return strtolW( s, end, base );
}
/*********************************************************************
* wcstoul (NTDLL.@)
*/
ULONG __cdecl NTDLL_wcstoul(LPCWSTR s, LPWSTR *end, INT base)
{
return strtoulW( s, end, base );
}
/*********************************************************************
* iswctype (NTDLL.@)
*/
INT __cdecl NTDLL_iswctype( WCHAR wc, WCHAR wct )
{
return (get_char_typeW(wc) & 0xfff) & wct;
}
/*********************************************************************
* iswalpha (NTDLL.@)
*
* Checks if a unicode char wc is a letter
*
* RETURNS
* TRUE: The unicode char wc is a letter.
* FALSE: Otherwise
*/
INT __cdecl NTDLL_iswalpha( WCHAR wc )
{
return isalphaW(wc);
}
/*********************************************************************
* iswdigit (NTDLL.@)
*
* Checks if a unicode char wc is a digit
*
* RETURNS
* TRUE: The unicode char wc is a digit.
* FALSE: Otherwise
*/
INT __cdecl NTDLL_iswdigit( WCHAR wc )
{
return isdigitW(wc);
}
/*********************************************************************
* iswlower (NTDLL.@)
*
* Checks if a unicode char wc is a lower case letter
*
* RETURNS
* TRUE: The unicode char wc is a lower case letter.
* FALSE: Otherwise
*/
INT __cdecl NTDLL_iswlower( WCHAR wc )
{
return islowerW(wc);
}
/*********************************************************************
* iswspace (NTDLL.@)
*
* Checks if a unicode char wc is a white space character
*
* RETURNS
* TRUE: The unicode char wc is a white space character.
* FALSE: Otherwise
*/
INT __cdecl NTDLL_iswspace( WCHAR wc )
{
return isspaceW(wc);
}
/*********************************************************************
* iswxdigit (NTDLL.@)
*
* Checks if a unicode char wc is an extended digit
*
* RETURNS
* TRUE: The unicode char wc is an extended digit.
* FALSE: Otherwise
*/
INT __cdecl NTDLL_iswxdigit( WCHAR wc )
{
return isxdigitW(wc);
}
/*********************************************************************
* _ultow (NTDLL.@)
*
* Converts an unsigned long integer to a unicode string.
*
* RETURNS
* Always returns str.
*
* NOTES
* Converts value to a '\0' terminated wstring which is copied to str.
* The maximum length of the copied str is 33 bytes.
* Does not check if radix is in the range of 2 to 36.
* If str is NULL it just returns NULL.
*/
LPWSTR __cdecl _ultow(
ULONG value, /* [I] Value to be converted */
LPWSTR str, /* [O] Destination for the converted value */
INT radix) /* [I] Number base for conversion */
{
WCHAR buffer[33];
PWCHAR pos;
WCHAR digit;
pos = &buffer[32];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
if (str != NULL) {
memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
} /* if */
return str;
}
/*********************************************************************
* _ltow (NTDLL.@)
*
* Converts a long integer to a unicode string.
*
* RETURNS
* Always returns str.
*
* NOTES
* Converts value to a '\0' terminated wstring which is copied to str.
* The maximum length of the copied str is 33 bytes. If radix
* is 10 and value is negative, the value is converted with sign.
* Does not check if radix is in the range of 2 to 36.
* If str is NULL it just returns NULL.
*/
LPWSTR __cdecl _ltow(
LONG value, /* [I] Value to be converted */
LPWSTR str, /* [O] Destination for the converted value */
INT radix) /* [I] Number base for conversion */
{
ULONG val;
int negative;
WCHAR buffer[33];
PWCHAR pos;
WCHAR digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[32];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
if (str != NULL) {
memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
} /* if */
return str;
}
/*********************************************************************
* _itow (NTDLL.@)
*
* Converts an integer to a unicode string.
*
* RETURNS
* Always returns str.
*
* NOTES
* Converts value to a '\0' terminated wstring which is copied to str.
* The maximum length of the copied str is 33 bytes. If radix
* is 10 and value is negative, the value is converted with sign.
* Does not check if radix is in the range of 2 to 36.
* If str is NULL it just returns NULL.
*
* DIFFERENCES
* - The native function crashes when the string is longer than 19 chars.
* This function does not have this bug.
*/
LPWSTR __cdecl _itow(
int value, /* [I] Value to be converted */
LPWSTR str, /* [O] Destination for the converted value */
INT radix) /* [I] Number base for conversion */
{
return _ltow(value, str, radix);
}
/*********************************************************************
* _ui64tow (NTDLL.@)
*
* Converts a large unsigned integer to a unicode string.
*
* RETURNS
* Always returns str.
*
* NOTES
* Converts value to a '\0' terminated wstring which is copied to str.
* The maximum length of the copied str is 33 bytes.
* Does not check if radix is in the range of 2 to 36.
* If str is NULL it just returns NULL.
*
* DIFFERENCES
* - This function does not exist in the native DLL (but in msvcrt).
* But since the maintenance of all these functions is better done
* in one place we implement it here.
*/
LPWSTR __cdecl _ui64tow(
ULONGLONG value, /* [I] Value to be converted */
LPWSTR str, /* [O] Destination for the converted value */
INT radix) /* [I] Number base for conversion */
{
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
pos = &buffer[64];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
if (str != NULL) {
memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return str;
}
/*********************************************************************
* _i64tow (NTDLL.@)
*
* Converts a large integer to a unicode string.
*
* RETURNS
* Always returns str.
*
* NOTES
* Converts value to a '\0' terminated wstring which is copied to str.
* The maximum length of the copied str is 33 bytes. If radix
* is 10 and value is negative, the value is converted with sign.
* Does not check if radix is in the range of 2 to 36.
* If str is NULL it just returns NULL.
*
* DIFFERENCES
* - The native DLL converts negative values (for base 10) wrong:
* -1 is converted to -18446744073709551615
* -2 is converted to -18446744073709551614
* -9223372036854775807 is converted to -9223372036854775809
* -9223372036854775808 is converted to -9223372036854775808
* The native msvcrt _i64tow function and our ntdll function do
* not have this bug.
*/
LPWSTR __cdecl _i64tow(
LONGLONG value, /* [I] Value to be converted */
LPWSTR str, /* [O] Destination for the converted value */
INT radix) /* [I] Number base for conversion */
{
ULONGLONG val;
int negative;
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[64];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
if (str != NULL) {
memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return str;
}
/*********************************************************************
* _wtol (NTDLL.@)
*
* Converts a unicode string to a long integer.
*
* PARAMS
* str [I] Wstring to be converted
*
* RETURNS
* On success it returns the integer value otherwise it returns 0.
*
* NOTES
* Accepts: {whitespace} [+|-] {digits}
* No check is made for value overflow, only the lower 32 bits are assigned.
* If str is NULL it crashes, as the native function does.
*/
LONG __cdecl _wtol( LPCWSTR str )
{
ULONG RunningTotal = 0;
char bMinus = 0;
while (isspaceW(*str)) {
str++;
} /* while */
if (*str == '+') {
str++;
} else if (*str == '-') {
bMinus = 1;
str++;
} /* if */
while (*str >= '0' && *str <= '9') {
RunningTotal = RunningTotal * 10 + *str - '0';
str++;
} /* while */
return bMinus ? -RunningTotal : RunningTotal;
}
/*********************************************************************
* _wtoi (NTDLL.@)
*
* Converts a unicode string to an integer.
*
* PARAMS
* str [I] Wstring to be converted
*
* RETURNS
* On success it returns the integer value otherwise it returns 0.
*
* NOTES
* Accepts: {whitespace} [+|-] {digits}
* No check is made for value overflow, only the lower 32 bits are assigned.
* If str is NULL it crashes, as the native function does.
*/
int __cdecl _wtoi( LPCWSTR str )
{
return _wtol(str);
}
/*********************************************************************
* _wtoi64 (NTDLL.@)
*
* Converts a unicode string to a large integer.
*
* PARAMS
* str [I] Wstring to be converted
*
* RETURNS
* On success it returns the integer value otherwise it returns 0.
*
* NOTES
* Accepts: {whitespace} [+|-] {digits}
* No check is made for value overflow, only the lower 64 bits are assigned.
* If str is NULL it crashes, as the native function does.
*/
LONGLONG __cdecl _wtoi64( LPCWSTR str )
{
ULONGLONG RunningTotal = 0;
char bMinus = 0;
while (isspaceW(*str)) {
str++;
} /* while */
if (*str == '+') {
str++;
} else if (*str == '-') {
bMinus = 1;
str++;
} /* if */
while (*str >= '0' && *str <= '9') {
RunningTotal = RunningTotal * 10 + *str - '0';
str++;
} /* while */
return bMinus ? -RunningTotal : RunningTotal;
}