-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathnls.c
80 lines (72 loc) · 2.07 KB
/
nls.c
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
#include "ntrtl.h"
/**
* Compares two counted Unicode strings. The return value indicates if the
* strings are equal or String1 is less than String2 or String1 is greater
* than String2.
*
* The CaseInSensitive parameter specifies if case is to be ignored when
* doing the comparison.
*
* @param[in] String1 Pointer to the first string.
* @param[in] Length1 Length of the first string.
* @param[in] String2 Pointer to the second string.
* @param[in] Length2 Length of the second string.
* @param[in] CaseInSensitive If TRUE, case should be ignored when doing
* the comparison.
*
* @return Signed value that gives the results of the comparison:
* Zero - String1 equals String2
* < Zero - String1 less than String2
* > Zero - String1 greater than String2
*/
LONG
NTAPI
RtlCompareUnicodeStrings(
IN CONST WCHAR* String1,
IN SIZE_T Length1,
IN CONST WCHAR* String2,
IN SIZE_T Length2,
IN BOOLEAN CaseInSensitive
)
{
CONST WCHAR* s1, * s2, * Limit;
LONG n1, n2;
UINT32 c1, c2;
if (Length1 > LONG_MAX || Length2 > LONG_MAX) {
return STATUS_INVALID_BUFFER_SIZE;
}
s1 = String1;
s2 = String2;
n1 = (LONG)Length1;
n2 = (LONG)Length2;
Limit = (WCHAR*)((CHAR*)s1 + (n1 <= n2 ? n1 : n2));
if (CaseInSensitive) {
while (s1 < Limit) {
c1 = *s1;
c2 = *s2;
if (c1 != c2) {
//
// Note that this needs to reference the translation table!
//
c1 = RTL_UPCASE(c1);
c2 = RTL_UPCASE(c2);
if (c1 != c2) {
return (INT32)(c1)-(INT32)(c2);
}
}
s1 += 1;
s2 += 1;
}
} else {
while (s1 < Limit) {
c1 = *s1;
c2 = *s2;
if (c1 != c2) {
return (LONG)(c1)-(LONG)(c2);
}
s1 += 1;
s2 += 1;
}
}
return n1 - n2;
}