[FORMATTING] Fix indentation (4 spaces)
[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(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 STDCALL
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 STDCALL
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 _SEH_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 _SEH_HANDLE
85 _SEH_END;
86
87 return Ret;
88 }
89
90
91 /*
92 * @implemented
93 */
94 LPSTR
95 STDCALL
96 lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
97 {
98 LPSTR Ret = NULL;
99
100 _SEH_TRY
101 {
102 memmove(lpString1, lpString2, strlen(lpString2) + 1);
103 Ret = lpString1;
104 }
105 _SEH_HANDLE
106 _SEH_END;
107
108 return Ret;
109 }
110
111
112 /*
113 * @implemented
114 */
115 LPSTR
116 STDCALL
117 lstrcatA(LPSTR lpString1, LPCSTR lpString2)
118 {
119 LPSTR Ret = NULL;
120
121 _SEH_TRY
122 {
123 Ret = strcat(lpString1, lpString2);
124 }
125 _SEH_HANDLE
126 _SEH_END;
127
128 return Ret;
129 }
130
131
132 /*
133 * @implemented
134 */
135 int
136 STDCALL
137 lstrlenA(LPCSTR lpString)
138 {
139 INT Ret = 0;
140
141 _SEH_TRY
142 {
143 Ret = strlen(lpString);
144 }
145 _SEH_HANDLE
146 _SEH_END;
147
148 return Ret;
149 }
150
151
152 /*
153 * @implemented
154 */
155 int
156 STDCALL
157 lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
158 {
159 int Result;
160
161 if (lpString1 == lpString2)
162 return 0;
163 if (lpString1 == NULL)
164 return -1;
165 if (lpString2 == NULL)
166 return 1;
167
168 Result = CompareStringW(GetThreadLocale(), 0, lpString1, -1, lpString2, -1);
169 if (Result)
170 Result -= 2;
171
172 return Result;
173 }
174
175
176 /*
177 * @implemented
178 */
179 int
180 STDCALL
181 lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
182 {
183 int Result;
184
185 if (lpString1 == lpString2)
186 return 0;
187 if (lpString1 == NULL)
188 return -1;
189 if (lpString2 == NULL)
190 return 1;
191
192 Result = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpString1, -1, lpString2, -1);
193 if (Result)
194 Result -= 2;
195
196 return Result;
197 }
198
199
200 /*
201 * @implemented
202 */
203 LPWSTR
204 STDCALL
205 lstrcpynW(LPWSTR lpString1, LPCWSTR lpString2, int iMaxLength)
206 {
207 LPWSTR d = lpString1;
208 LPCWSTR s = lpString2;
209 UINT count = iMaxLength;
210 LPWSTR Ret = NULL;
211
212 _SEH_TRY
213 {
214 while ((count > 1) && *s)
215 {
216 count--;
217 *d++ = *s++;
218 }
219
220 if (count)
221 *d = 0;
222
223 Ret = lpString1;
224 }
225 _SEH_HANDLE
226 _SEH_END;
227
228 return Ret;
229 }
230
231
232 /*
233 * @implemented
234 */
235 LPWSTR
236 STDCALL
237 lstrcpyW(LPWSTR lpString1, LPCWSTR lpString2)
238 {
239 LPWSTR Ret = NULL;
240
241 _SEH_TRY
242 {
243 Ret = wcscpy(lpString1, lpString2);
244 }
245 _SEH_HANDLE
246 _SEH_END;
247
248 return Ret;
249 }
250
251
252 /*
253 * @implemented
254 */
255 LPWSTR
256 STDCALL
257 lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
258 {
259 LPWSTR Ret = NULL;
260
261 _SEH_TRY
262 {
263 Ret = wcscat(lpString1, lpString2);
264 }
265 _SEH_HANDLE
266 _SEH_END;
267
268 return Ret;
269 }
270
271
272 /*
273 * @implemented
274 */
275 int
276 STDCALL
277 lstrlenW(LPCWSTR lpString)
278 {
279 INT Ret = 0;
280
281 _SEH_TRY
282 {
283 Ret = wcslen(lpString);
284 }
285 _SEH_HANDLE
286 _SEH_END;
287
288 return Ret;
289 }