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