The lstr* functions don't reset the last error on an exception. Also they handle...
[reactos.git] / reactos / dll / win32 / kernel32 / 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 STDCALL
18 lstrcmpA(
19 LPCSTR lpString1,
20 LPCSTR lpString2
21 )
22 {
23 int Result;
24
25 if (lpString1 == lpString2)
26 return 0;
27 if (lpString1 == NULL)
28 return -1;
29 if (lpString2 == NULL)
30 return 1;
31
32 Result = CompareStringA(GetThreadLocale(), 0, lpString1, -1, lpString2, -1);
33 if (Result) Result -= 2;
34
35 return Result;
36 }
37
38
39 /*
40 * @implemented
41 */
42 int
43 STDCALL
44 lstrcmpiA(
45 LPCSTR lpString1,
46 LPCSTR lpString2
47 )
48 {
49 int Result;
50
51 if (lpString1 == lpString2)
52 return 0;
53 if (lpString1 == NULL)
54 return -1;
55 if (lpString2 == NULL)
56 return 1;
57
58 Result = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpString1, -1,
59 lpString2, -1);
60 if (Result) Result -= 2;
61
62 return Result;
63 }
64
65 /*
66 * @implemented
67 */
68 LPSTR
69 STDCALL
70 lstrcpynA(
71 LPSTR lpString1,
72 LPCSTR lpString2,
73 int iMaxLength
74 )
75 {
76 LPSTR d = lpString1;
77 LPCSTR s = lpString2;
78 UINT count = iMaxLength;
79 LPSTR Ret = NULL;
80
81 _SEH_TRY
82 {
83 while ((count > 1) && *s)
84 {
85 count--;
86 *d++ = *s++;
87 }
88 if (count) *d = 0;
89
90 Ret = lpString1;
91 }
92 _SEH_HANDLE
93 _SEH_END;
94
95 return Ret;
96 }
97
98
99 /*
100 * @implemented
101 */
102 LPSTR
103 STDCALL
104 lstrcpyA(
105 LPSTR lpString1,
106 LPCSTR lpString2
107 )
108 {
109 LPSTR Ret = NULL;
110
111 _SEH_TRY
112 {
113 memmove(lpString1, lpString2, strlen(lpString2) + 1);
114 Ret = lpString1;
115 }
116 _SEH_HANDLE
117 _SEH_END;
118
119 return Ret;
120 }
121
122
123 /*
124 * @implemented
125 */
126 LPSTR
127 STDCALL
128 lstrcatA(
129 LPSTR lpString1,
130 LPCSTR lpString2
131 )
132 {
133 LPSTR Ret = NULL;
134
135 _SEH_TRY
136 {
137 Ret = strcat(lpString1, lpString2);
138 }
139 _SEH_HANDLE
140 _SEH_END;
141
142 return Ret;
143
144 }
145
146
147 /*
148 * @implemented
149 */
150 int
151 STDCALL
152 lstrlenA(
153 LPCSTR lpString
154 )
155 {
156 INT Ret = 0;
157
158 _SEH_TRY
159 {
160 Ret = strlen(lpString);
161 }
162 _SEH_HANDLE
163 _SEH_END;
164
165 return Ret;
166 }
167
168
169 /*
170 * @implemented
171 */
172 int
173 STDCALL
174 lstrcmpW(
175 LPCWSTR lpString1,
176 LPCWSTR lpString2
177 )
178 {
179 int Result;
180
181 if (lpString1 == lpString2)
182 return 0;
183 if (lpString1 == NULL)
184 return -1;
185 if (lpString2 == NULL)
186 return 1;
187
188 Result = CompareStringW(GetThreadLocale(), 0, lpString1, -1, lpString2, -1);
189 if (Result) Result -= 2;
190
191 return Result;
192 }
193
194
195 /*
196 * @implemented
197 */
198 int
199 STDCALL
200 lstrcmpiW(
201 LPCWSTR lpString1,
202 LPCWSTR lpString2
203 )
204 {
205 int Result;
206
207 if (lpString1 == lpString2)
208 return 0;
209 if (lpString1 == NULL)
210 return -1;
211 if (lpString2 == NULL)
212 return 1;
213
214 Result = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpString1, -1, lpString2, -1);
215 if (Result) Result -= 2;
216
217 return Result;
218 }
219
220
221 /*
222 * @implemented
223 */
224 LPWSTR
225 STDCALL
226 lstrcpynW(
227 LPWSTR lpString1,
228 LPCWSTR lpString2,
229 int iMaxLength
230 )
231 {
232 LPWSTR d = lpString1;
233 LPCWSTR s = lpString2;
234 UINT count = iMaxLength;
235 LPWSTR Ret = NULL;
236
237 _SEH_TRY
238 {
239 while ((count > 1) && *s)
240 {
241 count--;
242 *d++ = *s++;
243 }
244 if (count) *d = 0;
245
246 Ret = lpString1;
247 }
248 _SEH_HANDLE
249 _SEH_END;
250
251 return Ret;
252 }
253
254
255 /*
256 * @implemented
257 */
258 LPWSTR
259 STDCALL
260 lstrcpyW(
261 LPWSTR lpString1,
262 LPCWSTR lpString2
263 )
264 {
265 LPWSTR Ret = NULL;
266
267 _SEH_TRY
268 {
269 Ret = wcscpy(lpString1, lpString2);
270 }
271 _SEH_HANDLE
272 _SEH_END;
273
274 return Ret;
275 }
276
277
278 /*
279 * @implemented
280 */
281 LPWSTR
282 STDCALL
283 lstrcatW(
284 LPWSTR lpString1,
285 LPCWSTR lpString2
286 )
287 {
288 LPWSTR Ret = NULL;
289
290 _SEH_TRY
291 {
292 Ret = wcscat(lpString1, lpString2);
293 }
294 _SEH_HANDLE
295 _SEH_END;
296
297 return Ret;
298 }
299
300
301 /*
302 * @implemented
303 */
304 int
305 STDCALL
306 lstrlenW(
307 LPCWSTR lpString
308 )
309 {
310 INT Ret = 0;
311
312 _SEH_TRY
313 {
314 Ret = wcslen(lpString);
315 }
316 _SEH_HANDLE
317 _SEH_END;
318
319 return Ret;
320 }