- Update to r53061
[reactos.git] / dll / win32 / kernel32 / winnls / string / lstring.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/file/lstring.c
5 * PURPOSE: Local string functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11 #include <k32.h>
12
13 /*
14 * @implemented
15 */
16 int
17 WINAPI
18 lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
19 {
20 int Result;
21
22 if (lpString1 == lpString2)
23 return 0;
24 if (lpString1 == NULL)
25 return -1;
26 if (lpString2 == NULL)
27 return 1;
28
29 Result = CompareStringA(GetThreadLocale(), 0, lpString1, -1, lpString2, -1);
30 if (Result) Result -= 2;
31
32 return Result;
33 }
34
35
36 /*
37 * @implemented
38 */
39 int
40 WINAPI
41 lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
42 {
43 int Result;
44
45 if (lpString1 == lpString2)
46 return 0;
47 if (lpString1 == NULL)
48 return -1;
49 if (lpString2 == NULL)
50 return 1;
51
52 Result = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpString1, -1, lpString2, -1);
53 if (Result)
54 Result -= 2;
55
56 return Result;
57 }
58
59 /*
60 * @implemented
61 */
62 LPSTR
63 WINAPI
64 lstrcpynA(LPSTR lpString1, LPCSTR lpString2, int iMaxLength)
65 {
66 LPSTR d = lpString1;
67 LPCSTR s = lpString2;
68 UINT count = iMaxLength;
69 LPSTR Ret = NULL;
70
71 _SEH2_TRY
72 {
73 while ((count > 1) && *s)
74 {
75 count--;
76 *d++ = *s++;
77 }
78
79 if (count)
80 *d = 0;
81
82 Ret = lpString1;
83 }
84 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
85 {
86 }
87 _SEH2_END;
88
89 return Ret;
90 }
91
92
93 /*
94 * @implemented
95 */
96 LPSTR
97 WINAPI
98 lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
99 {
100 LPSTR Ret = NULL;
101
102 _SEH2_TRY
103 {
104 memmove(lpString1, lpString2, strlen(lpString2) + 1);
105 Ret = lpString1;
106 }
107 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
108 {
109 }
110 _SEH2_END;
111
112 return Ret;
113 }
114
115
116 /*
117 * @implemented
118 */
119 LPSTR
120 WINAPI
121 lstrcatA(LPSTR lpString1, LPCSTR lpString2)
122 {
123 LPSTR Ret = NULL;
124
125 _SEH2_TRY
126 {
127 Ret = strcat(lpString1, lpString2);
128 }
129 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
130 {
131 }
132 _SEH2_END;
133
134 return Ret;
135 }
136
137
138 /*
139 * @implemented
140 */
141 int
142 WINAPI
143 lstrlenA(LPCSTR lpString)
144 {
145 INT Ret = 0;
146
147 _SEH2_TRY
148 {
149 Ret = strlen(lpString);
150 }
151 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
152 {
153 }
154 _SEH2_END;
155
156 return Ret;
157 }
158
159
160 /*
161 * @implemented
162 */
163 int
164 WINAPI
165 lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
166 {
167 int Result;
168
169 if (lpString1 == lpString2)
170 return 0;
171 if (lpString1 == NULL)
172 return -1;
173 if (lpString2 == NULL)
174 return 1;
175
176 Result = CompareStringW(GetThreadLocale(), 0, lpString1, -1, lpString2, -1);
177 if (Result)
178 Result -= 2;
179
180 return Result;
181 }
182
183
184 /*
185 * @implemented
186 */
187 int
188 WINAPI
189 lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
190 {
191 int Result;
192
193 if (lpString1 == lpString2)
194 return 0;
195 if (lpString1 == NULL)
196 return -1;
197 if (lpString2 == NULL)
198 return 1;
199
200 Result = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpString1, -1, lpString2, -1);
201 if (Result)
202 Result -= 2;
203
204 return Result;
205 }
206
207
208 /*
209 * @implemented
210 */
211 LPWSTR
212 WINAPI
213 lstrcpynW(LPWSTR lpString1, LPCWSTR lpString2, int iMaxLength)
214 {
215 LPWSTR d = lpString1;
216 LPCWSTR s = lpString2;
217 UINT count = iMaxLength;
218 LPWSTR Ret = NULL;
219
220 _SEH2_TRY
221 {
222 while ((count > 1) && *s)
223 {
224 count--;
225 *d++ = *s++;
226 }
227
228 if (count)
229 *d = 0;
230
231 Ret = lpString1;
232 }
233 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
234 {
235 }
236 _SEH2_END;
237
238 return Ret;
239 }
240
241
242 /*
243 * @implemented
244 */
245 LPWSTR
246 WINAPI
247 lstrcpyW(LPWSTR lpString1, LPCWSTR lpString2)
248 {
249 LPWSTR Ret = NULL;
250
251 _SEH2_TRY
252 {
253 Ret = wcscpy(lpString1, lpString2);
254 }
255 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
256 {
257 }
258 _SEH2_END;
259
260 return Ret;
261 }
262
263
264 /*
265 * @implemented
266 */
267 LPWSTR
268 WINAPI
269 lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
270 {
271 LPWSTR Ret = NULL;
272
273 _SEH2_TRY
274 {
275 Ret = wcscat(lpString1, lpString2);
276 }
277 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
278 {
279 }
280 _SEH2_END;
281
282 return Ret;
283 }
284
285
286 /*
287 * @implemented
288 */
289 int
290 WINAPI
291 lstrlenW(LPCWSTR lpString)
292 {
293 INT Ret = 0;
294
295 _SEH2_TRY
296 {
297 Ret = wcslen(lpString);
298 }
299 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
300 {
301 }
302 _SEH2_END;
303
304 return Ret;
305 }