xref: /reactos/drivers/network/ndis/ndis/string.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS NDIS library
4  * FILE:        ndis/string.c
5  * PURPOSE:     String management routines
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  *              Vizzini (vizzini@plasmic.com)
8  * REVISIONS:
9  *   CSH 01/08-2000 Created
10  *   Vizzini 08-Oct-2003  Error checking, documentation, and formatting
11  */
12 
13 #include "ndissys.h"
14 
15 /*
16  * @implemented
17  */
18 #undef NdisAnsiStringToUnicodeString
19 NDIS_STATUS
20 EXPORT
NdisAnsiStringToUnicodeString(IN OUT PNDIS_STRING DestinationString,IN PANSI_STRING SourceString)21 NdisAnsiStringToUnicodeString(
22     IN OUT  PNDIS_STRING   DestinationString,
23     IN      PANSI_STRING   SourceString)
24 /*
25  * FUNCTION: Converts an ANSI string to an NDIS (unicode) string
26  * ARGUMENTS:
27  *     DestinationString = Address of buffer to place converted string in
28  *     SourceString      = Pointer to ANSI string to be converted
29  * NOTES:
30  *     - caller must be running at IRQL = PASSIVE_LEVEL
31  */
32 {
33   PAGED_CODE();
34   ASSERT(DestinationString);
35   ASSERT(SourceString);
36 
37   return (NDIS_STATUS)RtlAnsiStringToUnicodeString(
38       (PUNICODE_STRING)DestinationString,
39       (PANSI_STRING)SourceString, FALSE);
40 }
41 
42 
43 /*
44  * @implemented
45  */
46 #undef NdisEqualString
47 BOOLEAN
48 EXPORT
NdisEqualString(IN PNDIS_STRING String1,IN PNDIS_STRING String2,IN BOOLEAN CaseInsensitive)49 NdisEqualString(
50     IN  PNDIS_STRING    String1,
51     IN  PNDIS_STRING    String2,
52     IN  BOOLEAN         CaseInsensitive)
53 /*
54  * FUNCTION: Tests two strings for equality
55  * ARGUMENTS:
56  *     String1         = Pointer to first string
57  *     String2         = Pointer to second string
58  *     CaseInsensitive = TRUE if the compare should be case insensitive
59  * NOTES:
60  *     - caller must be at IRQL = PASSIVE_LEVEL
61  */
62 {
63   PAGED_CODE();
64   ASSERT(String1);
65   ASSERT(String2);
66 
67   return RtlEqualUnicodeString((PUNICODE_STRING)String1,
68       (PUNICODE_STRING)String2,
69       CaseInsensitive);
70 }
71 
72 /*
73  * @implemented
74  */
75 #undef NdisInitAnsiString
76 VOID
77 EXPORT
NdisInitAnsiString(IN OUT PANSI_STRING DestinationString,IN PCSTR SourceString)78 NdisInitAnsiString(
79     IN OUT  PANSI_STRING   DestinationString,
80     IN      PCSTR          SourceString)
81 /*
82  * FUNCTION: Initializes an ANSI string
83  * ARGUMENTS:
84  *     DestinationString = Address of buffer to place string in
85  *     SourceString      = Pointer to null terminated ANSI string
86  * NOTES:
87  *     - Caller must be at IRQL <= DISPATCH_LEVEL
88  */
89 {
90   ASSERT(DestinationString);
91   ASSERT(SourceString);
92 
93   RtlInitString((PANSI_STRING)DestinationString, (PCSZ)SourceString);
94 }
95 
96 /*
97  * @implemented
98  */
99 VOID
100 EXPORT
NdisInitializeString(IN OUT PNDIS_STRING DestinationString,IN PUCHAR SourceString)101 NdisInitializeString(
102     IN OUT  PNDIS_STRING    DestinationString,
103     IN      PUCHAR          SourceString)
104 /*
105  * FUNCTION: Initializes an NDIS (unicode) string
106  * ARGUMENTS:
107  *     DestinationString = Address of buffer to place string in
108  *     SourceString      = Pointer to null terminated ANSI string
109  * NOTES:
110  *     - Must be called at IRQL = PASSIVE_LEVEL
111  */
112 {
113   ANSI_STRING AnsiString;
114 
115   PAGED_CODE();
116   ASSERT(DestinationString);
117   ASSERT(SourceString);
118 
119   RtlInitAnsiString(&AnsiString, (PCSZ)SourceString);
120 
121   RtlAnsiStringToUnicodeString((PUNICODE_STRING)DestinationString, &AnsiString, TRUE);
122 }
123 
124 /*
125  * @implemented
126  */
127 #undef NdisInitUnicodeString
128 VOID
129 EXPORT
NdisInitUnicodeString(IN OUT PNDIS_STRING DestinationString,IN PCWSTR SourceString)130 NdisInitUnicodeString(
131     IN OUT  PNDIS_STRING    DestinationString,
132     IN      PCWSTR          SourceString)
133 /*
134  * FUNCTION: Initializes an unicode string
135  * ARGUMENTS:
136  *     DestinationString = Address of buffer to place string in
137  *     SourceString      = Pointer to null terminated unicode string
138  * NOTES:
139  *     - call with IRQL <= DISPATCH_LEVEL
140  */
141 {
142   ASSERT(DestinationString);
143   ASSERT(SourceString);
144 
145   RtlInitUnicodeString((PUNICODE_STRING)DestinationString, SourceString);
146 }
147 
148 /*
149  * @implemented
150  */
151 #undef NdisUnicodeStringToAnsiString
152 NDIS_STATUS
153 EXPORT
NdisUnicodeStringToAnsiString(IN OUT PANSI_STRING DestinationString,IN PNDIS_STRING SourceString)154 NdisUnicodeStringToAnsiString(
155     IN OUT  PANSI_STRING   DestinationString,
156     IN      PNDIS_STRING   SourceString)
157 /*
158  * FUNCTION: Converts an NDIS (unicode) string to an ANSI string
159  * ARGUMENTS:
160  *     DestinationString = Address of buffer to place converted string in
161  *     SourceString      = Pointer to unicode string to be converted
162  * NOTES:
163  *     - must be called at IRQL = PASSIVE_LEVEL
164  */
165 {
166   PAGED_CODE();
167   ASSERT(DestinationString);
168   ASSERT(SourceString);
169 
170   return (NDIS_STATUS)RtlUnicodeStringToAnsiString(
171       (PANSI_STRING)DestinationString,
172       (PUNICODE_STRING)SourceString,
173       FALSE);
174 }
175 
176 /*
177  * @implemented
178  */
179 #undef NdisUpcaseUnicodeString
180 NTSTATUS
181 EXPORT
NdisUpcaseUnicodeString(OUT PUNICODE_STRING DestinationString,IN PUNICODE_STRING SourceString)182 NdisUpcaseUnicodeString(
183     OUT PUNICODE_STRING DestinationString,
184     IN  PUNICODE_STRING SourceString)
185 /*
186  * FUNCTION: Uppercase a UNICODE string
187  * ARGUMENTS:
188  *     DestinationString: caller-allocated space for the uppercased string
189  *     SourceString: string to be uppercased
190  * NOTES:
191  *     - Currently requires caller to allocate destination string - XXX is this right?
192  *     - callers must be running at IRQL = PASSIVE_LEVEL
193  */
194 {
195   PAGED_CODE();
196   ASSERT(SourceString);
197   ASSERT(DestinationString);
198 
199   return RtlUpcaseUnicodeString (DestinationString, SourceString, FALSE );
200 }
201 
202 /* EOF */
203