4 * Copyright 1993 Yngvi Sigurjonsson
5 * Copyright 1996 Alexandre Julliard
16 static const BYTE STRING_Oem2Ansi
[256] =
17 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\244"
18 "\020\021\022\023\266\247\026\027\030\031\032\033\034\035\036\037"
19 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
20 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
21 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
22 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
23 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
24 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
25 "\307\374\351\342\344\340\345\347\352\353\350\357\356\354\304\305"
26 "\311\346\306\364\366\362\373\371\377\326\334\242\243\245\120\203"
27 "\341\355\363\372\361\321\252\272\277\137\254\275\274\241\253\273"
28 "\137\137\137\246\246\246\246\053\053\246\246\053\053\053\053\053"
29 "\053\055\055\053\055\053\246\246\053\053\055\055\246\055\053\055"
30 "\055\055\055\053\053\053\053\053\053\053\053\137\137\246\137\137"
31 "\137\337\137\266\137\137\265\137\137\137\137\137\137\137\137\137"
32 "\137\261\137\137\137\137\367\137\260\225\267\137\156\262\137\137";
34 static const BYTE STRING_Ansi2Oem
[256] =
35 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
36 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
37 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
38 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
39 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
40 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
41 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
42 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
43 "\200\201\054\237\054\137\375\374\210\045\123\074\117\215\216\217"
44 "\220\140\047\042\042\371\055\137\230\231\163\076\157\235\236\131"
45 "\040\255\233\234\017\235\335\025\042\143\246\256\252\055\162\137"
46 "\370\361\375\063\047\346\024\372\054\061\247\257\254\253\137\250"
47 "\101\101\101\101\216\217\222\200\105\220\105\105\111\111\111\111"
48 "\104\245\117\117\117\117\231\170\117\125\125\125\232\131\137\341"
49 "\205\240\203\141\204\206\221\207\212\202\210\211\215\241\214\213"
50 "\144\244\225\242\223\157\224\366\157\227\243\226\201\171\137\230";
52 #define OEM_TO_ANSI(ch) (STRING_Oem2Ansi[(unsigned char)(ch)])
53 #define ANSI_TO_OEM(ch) (STRING_Ansi2Oem[(unsigned char)(ch)])
56 /***********************************************************************
57 * hmemcpy (KERNEL.348)
59 void WINAPI
hmemcpy( LPVOID dst
, LPCVOID src
, LONG count
)
61 memcpy( dst
, src
, count
);
65 /***********************************************************************
66 * lstrcat16 (KERNEL.89)
68 SEGPTR WINAPI
lstrcat16( SEGPTR dst
, LPCSTR src
)
70 lstrcat32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), src
);
75 /***********************************************************************
76 * lstrcat32A (KERNEL32.599)
78 LPSTR WINAPI
lstrcat32A( LPSTR dst
, LPCSTR src
)
80 TRACE(string
,"Append %s to %s\n",
81 debugstr_a (src
), debugstr_a (dst
));
82 /* Windows does not check for NULL pointers here, so we don't either */
88 /***********************************************************************
89 * lstrcat32W (KERNEL32.600)
91 LPWSTR WINAPI
lstrcat32W( LPWSTR dst
, LPCWSTR src
)
93 register LPWSTR p
= dst
;
94 TRACE(string
,"Append L%s to L%s\n",
95 debugstr_w (src
), debugstr_w (dst
));
96 /* Windows does not check for NULL pointers here, so we don't either */
98 while ((*p
++ = *src
++));
103 /***********************************************************************
104 * lstrcatn16 (KERNEL.352)
106 SEGPTR WINAPI
lstrcatn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
108 lstrcatn32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), src
, n
);
113 /***********************************************************************
114 * lstrcatn32A (Not a Windows API)
116 LPSTR WINAPI
lstrcatn32A( LPSTR dst
, LPCSTR src
, INT32 n
)
118 register LPSTR p
= dst
;
119 TRACE(string
,"strcatn add %d chars from %s to %s\n",
120 n
, debugstr_an (src
, n
), debugstr_a (dst
));
122 if ((n
-= (INT32
)(p
- dst
)) <= 0) return dst
;
123 lstrcpyn32A( p
, src
, n
);
128 /***********************************************************************
129 * lstrcatn32W (Not a Windows API)
131 LPWSTR WINAPI
lstrcatn32W( LPWSTR dst
, LPCWSTR src
, INT32 n
)
133 register LPWSTR p
= dst
;
134 TRACE(string
,"strcatn add %d chars from L%s to L%s\n",
135 n
, debugstr_wn (src
, n
), debugstr_w (dst
));
137 if ((n
-= (INT32
)(p
- dst
)) <= 0) return dst
;
138 lstrcpyn32W( p
, src
, n
);
143 /***********************************************************************
144 * lstrcmp16 (USER.430)
146 INT16 WINAPI
lstrcmp16( LPCSTR str1
, LPCSTR str2
)
148 return (INT16
)strcmp( str1
, str2
);
152 /***********************************************************************
153 * lstrcmp32A (KERNEL.602)
155 INT32 WINAPI
lstrcmp32A( LPCSTR str1
, LPCSTR str2
)
157 return CompareString32A(LOCALE_SYSTEM_DEFAULT
,0,str1
,-1,str2
,-1) - 2 ;
161 /***********************************************************************
162 * lstrcmp32W (KERNEL.603)
163 * FIXME : should call CompareString32W, when it is implemented.
164 * This implementation is not "word sort", as it should.
166 INT32 WINAPI
lstrcmp32W( LPCWSTR str1
, LPCWSTR str2
)
168 TRACE(string
,"L%s and L%s\n",
169 debugstr_w (str1
), debugstr_w (str2
));
170 if (!str1
|| !str2
) {
171 SetLastError(ERROR_INVALID_PARAMETER
);
174 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
175 return (INT32
)(*str1
- *str2
);
179 /***********************************************************************
180 * lstrcmpi16 (USER.471)
182 INT16 WINAPI
lstrcmpi16( LPCSTR str1
, LPCSTR str2
)
184 return (INT16
)lstrcmpi32A( str1
, str2
);
188 /***********************************************************************
189 * lstrcmpi32A (KERNEL32.605)
191 INT32 WINAPI
lstrcmpi32A( LPCSTR str1
, LPCSTR str2
)
192 { TRACE(string
,"strcmpi %s and %s\n",
193 debugstr_a (str1
), debugstr_a (str2
));
194 return CompareString32A(LOCALE_SYSTEM_DEFAULT
,NORM_IGNORECASE
,str1
,-1,str2
,-1)-2;
198 /***********************************************************************
199 * lstrcmpi32W (KERNEL32.606)
201 INT32 WINAPI
lstrcmpi32W( LPCWSTR str1
, LPCWSTR str2
)
206 /* Too much! (From registry loading.) */
207 TRACE(string
,"strcmpi L%s and L%s\n",
208 debugstr_w (str1
), debugstr_w (str2
));
210 if (!str1
|| !str2
) {
211 SetLastError(ERROR_INVALID_PARAMETER
);
216 if ((res
= towupper(*str1
) - towupper(*str2
)) != 0) return res
;
220 return towupper(*str1
) - towupper(*str2
);
224 /***********************************************************************
225 * lstrcpy16 (KERNEL.88)
227 SEGPTR WINAPI
lstrcpy16( SEGPTR dst
, LPCSTR src
)
229 lstrcpy32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), src
);
234 /***********************************************************************
235 * lstrcpy32A (KERNEL32.608)
237 LPSTR WINAPI
lstrcpy32A( LPSTR dst
, LPCSTR src
)
239 TRACE(string
,"strcpy %s\n", debugstr_a (src
));
240 /* Windows does not check for NULL pointers here, so we don't either */
246 /***********************************************************************
247 * lstrcpy32W (KERNEL32.609)
249 LPWSTR WINAPI
lstrcpy32W( LPWSTR dst
, LPCWSTR src
)
251 register LPWSTR p
= dst
;
252 TRACE(string
,"strcpy L%s\n", debugstr_w (src
));
253 /* Windows does not check for NULL pointers here, so we don't either */
254 while ((*p
++ = *src
++));
259 /***********************************************************************
260 * lstrcpyn16 (KERNEL.353)
262 SEGPTR WINAPI
lstrcpyn16( SEGPTR dst
, LPCSTR src
, INT16 n
)
264 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), src
, n
);
269 /***********************************************************************
270 * lstrcpyn32A (KERNEL32.611)
271 * Note: this function differs from the UNIX strncpy, it _always_ writes
274 LPSTR WINAPI
lstrcpyn32A( LPSTR dst
, LPCSTR src
, INT32 n
)
277 TRACE(string
,"strcpyn %s for %d chars\n",
278 debugstr_an (src
,n
), n
);
279 /* Windows does not check for NULL pointers here, so we don't either */
280 while ((n
-- > 1) && *src
) *p
++ = *src
++;
286 /***********************************************************************
287 * lstrcpyn32W (KERNEL32.612)
288 * Note: this function differs from the UNIX strncpy, it _always_ writes
291 LPWSTR WINAPI
lstrcpyn32W( LPWSTR dst
, LPCWSTR src
, INT32 n
)
294 TRACE(string
,"strcpyn L%s for %d chars\n",
295 debugstr_wn (src
,n
), n
);
296 /* Windows does not check for NULL pointers here, so we don't either */
297 while ((n
-- > 1) && *src
) *p
++ = *src
++;
303 /***********************************************************************
304 * lstrlen16 (KERNEL.90)
306 INT16 WINAPI
lstrlen16( LPCSTR str
)
308 return (INT16
)lstrlen32A( str
);
312 /***********************************************************************
313 * lstrlen32A (KERNEL32.614)
315 INT32 WINAPI
lstrlen32A( LPCSTR str
)
317 /* looks weird, but win3.1 KERNEL got a GeneralProtection handler
318 * in lstrlen() ... we check only for NULL pointer reference.
321 TRACE(string
,"strlen %s\n", debugstr_a (str
));
323 return (INT32
)strlen(str
);
327 /***********************************************************************
328 * lstrlen32W (KERNEL32.615)
330 INT32 WINAPI
lstrlen32W( LPCWSTR str
)
333 TRACE(string
,"strlen L%s\n", debugstr_w (str
));
335 while (*str
++) len
++;
340 /***********************************************************************
341 * lstrncmp32A (Not a Windows API)
343 INT32 WINAPI
lstrncmp32A( LPCSTR str1
, LPCSTR str2
, INT32 n
)
345 TRACE(string
,"strncmp %s and %s for %d chars\n",
346 debugstr_an (str1
, n
), debugstr_an (str2
, n
), n
);
347 return (INT32
)strncmp( str1
, str2
, n
);
351 /***********************************************************************
352 * lstrncmp32W (Not a Windows API)
354 INT32 WINAPI
lstrncmp32W( LPCWSTR str1
, LPCWSTR str2
, INT32 n
)
356 TRACE(string
,"strncmp L%s and L%s for %d chars\n",
357 debugstr_wn (str1
, n
), debugstr_wn (str2
, n
), n
);
359 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
360 return (INT32
)(*str1
- *str2
);
364 /***********************************************************************
365 * lstrncmpi32A (Not a Windows API)
367 INT32 WINAPI
lstrncmpi32A( LPCSTR str1
, LPCSTR str2
, INT32 n
)
371 TRACE(string
,"strncmpi %s and %s for %d chars\n",
372 debugstr_an (str1
, n
), debugstr_an (str2
, n
), n
);
374 while ((--n
> 0) && *str1
)
375 if ( (res
= toupper(*str1
++) - toupper(*str2
++)) ) return res
;
377 return toupper(*str1
) - toupper(*str2
);
381 /***********************************************************************
382 * lstrncmpi32W (Not a Windows API)
384 INT32 WINAPI
lstrncmpi32W( LPCWSTR str1
, LPCWSTR str2
, INT32 n
)
388 TRACE(string
,"strncmpi L%s and L%s for %d chars\n",
389 debugstr_wn (str1
, n
), debugstr_wn (str2
, n
), n
);
391 while ((--n
> 0) && *str1
)
393 if ((res
= towupper(*str1
) - towupper(*str2
)) != 0) return res
;
397 return towupper(*str1
) - towupper(*str2
);
401 /***********************************************************************
402 * lstrcpyAtoW (Not a Windows API)
404 LPWSTR WINAPI
lstrcpyAtoW( LPWSTR dst
, LPCSTR src
)
406 register LPWSTR p
= dst
;
407 while ((*p
++ = (WCHAR
)(unsigned char)*src
++));
412 /***********************************************************************
413 * lstrcpyWtoA (Not a Windows API)
415 LPSTR WINAPI
lstrcpyWtoA( LPSTR dst
, LPCWSTR src
)
417 register LPSTR p
= dst
;
418 while ((*p
++ = (CHAR
)*src
++));
423 /***********************************************************************
424 * lstrcpynAtoW (Not a Windows API)
425 * Note: this function differs from the UNIX strncpy, it _always_ writes
428 LPWSTR WINAPI
lstrcpynAtoW( LPWSTR dst
, LPCSTR src
, INT32 n
)
431 while ((n
-- > 1) && *src
) *p
++ = (WCHAR
)(unsigned char)*src
++;
437 /***********************************************************************
438 * lstrcpynWtoA (Not a Windows API)
439 * Note: this function differs from the UNIX strncpy, it _always_ writes
442 LPSTR WINAPI
lstrcpynWtoA( LPSTR dst
, LPCWSTR src
, INT32 n
)
445 while ((n
-- > 1) && *src
) *p
++ = (CHAR
)*src
++;
451 /***********************************************************************
454 void WINAPI
Copy( LPVOID src
, LPVOID dst
, WORD size
)
456 memcpy( dst
, src
, size
);
460 /***********************************************************************
461 * RtlFillMemory (KERNEL32.441)
463 VOID WINAPI
RtlFillMemory( LPVOID ptr
, UINT32 len
, UINT32 fill
)
465 memset( ptr
, fill
, len
);
469 /***********************************************************************
470 * RtlMoveMemory (KERNEL32.442)
472 VOID WINAPI
RtlMoveMemory( LPVOID dst
, LPCVOID src
, UINT32 len
)
474 memmove( dst
, src
, len
);
478 /***********************************************************************
479 * RtlZeroMemory (KERNEL32.444)
481 VOID WINAPI
RtlZeroMemory( LPVOID ptr
, UINT32 len
)
483 memset( ptr
, 0, len
);
487 /***********************************************************************
488 * AnsiToOem16 (KEYBOARD.5)
490 INT16 WINAPI
AnsiToOem16( LPCSTR s
, LPSTR d
)
492 CharToOem32A( s
, d
);
497 /***********************************************************************
498 * OemToAnsi16 (KEYBOARD.6)
500 INT16 WINAPI
OemToAnsi16( LPCSTR s
, LPSTR d
)
502 OemToChar32A( s
, d
);
507 /***********************************************************************
508 * AnsiToOemBuff16 (KEYBOARD.134)
510 void WINAPI
AnsiToOemBuff16( LPCSTR s
, LPSTR d
, UINT16 len
)
512 CharToOemBuff32A( s
, d
, len
? len
: 65536 );
516 /***********************************************************************
517 * OemToAnsiBuff16 (KEYBOARD.135)
519 void WINAPI
OemToAnsiBuff16( LPCSTR s
, LPSTR d
, UINT16 len
)
521 OemToCharBuff32A( s
, d
, len
? len
: 65536 );
525 /***********************************************************************
526 * CharToOem32A (USER32.37)
528 BOOL32 WINAPI
CharToOem32A( LPCSTR s
, LPSTR d
)
531 if (!s
|| !d
) return TRUE
;
532 TRACE(string
,"CharToOem %s\n", debugstr_a (s
));
533 while ((*d
++ = ANSI_TO_OEM(*s
++)));
534 TRACE(string
," to %s\n", debugstr_a (oldd
));
539 /***********************************************************************
540 * CharToOemBuff32A (USER32.38)
542 BOOL32 WINAPI
CharToOemBuff32A( LPCSTR s
, LPSTR d
, DWORD len
)
544 while (len
--) *d
++ = ANSI_TO_OEM(*s
++);
549 /***********************************************************************
550 * CharToOemBuff32W (USER32.39)
552 BOOL32 WINAPI
CharToOemBuff32W( LPCWSTR s
, LPSTR d
, DWORD len
)
554 while (len
--) *d
++ = ANSI_TO_OEM(*s
++);
559 /***********************************************************************
560 * CharToOem32W (USER32.40)
562 BOOL32 WINAPI
CharToOem32W( LPCWSTR s
, LPSTR d
)
565 if (!s
|| !d
) return TRUE
;
566 TRACE(string
,"CharToOem L%s\n", debugstr_w (s
));
567 while ((*d
++ = ANSI_TO_OEM(*s
++)));
568 TRACE(string
," to %s\n", debugstr_a (oldd
));
573 /***********************************************************************
574 * OemToChar32A (USER32.402)
576 BOOL32 WINAPI
OemToChar32A( LPCSTR s
, LPSTR d
)
579 TRACE(string
,"OemToChar %s\n", debugstr_a (s
));
580 while ((*d
++ = OEM_TO_ANSI(*s
++)));
581 TRACE(string
," to %s\n", debugstr_a (oldd
));
586 /***********************************************************************
587 * OemToCharBuff32A (USER32.403)
589 BOOL32 WINAPI
OemToCharBuff32A( LPCSTR s
, LPSTR d
, DWORD len
)
591 TRACE(string
,"OemToCharBuff %s\n", debugstr_an (s
, len
));
592 while (len
--) *d
++ = OEM_TO_ANSI(*s
++);
597 /***********************************************************************
598 * OemToCharBuff32W (USER32.404)
600 BOOL32 WINAPI
OemToCharBuff32W( LPCSTR s
, LPWSTR d
, DWORD len
)
602 TRACE(string
,"OemToCharBuff %s\n", debugstr_an (s
, len
));
603 while (len
--) *d
++ = (WCHAR
)OEM_TO_ANSI(*s
++);
608 /***********************************************************************
609 * OemToChar32W (USER32.405)
611 BOOL32 WINAPI
OemToChar32W( LPCSTR s
, LPWSTR d
)
613 while ((*d
++ = (WCHAR
)OEM_TO_ANSI(*s
++)));
617 /***********************************************************************
618 * WideCharToLocal (Not a Windows API)
619 * similar lstrcpyWtoA, should handle codepages properly
622 * strlen of the destination string
625 INT32 WINAPI
WideCharToLocal32(
630 TRACE(string
,"(%p, %s, %li)\n", pLocal
, debugstr_w(pWide
),dwChars
);
631 WideCharToMultiByte(CP_ACP
,0,pWide
,-1,pLocal
,dwChars
,NULL
,NULL
);
632 return strlen(pLocal
);
634 /***********************************************************************
635 * LocalToWideChar (Not a Windows API)
636 * similar lstrcpyAtoW, should handle codepages properly
639 * strlen of the destination string
641 INT32 WINAPI
LocalToWideChar32(
646 TRACE(string
,"(%p, %s, %li)\n",pWide
, pLocal
, dwChars
);
647 MultiByteToWideChar(CP_ACP
,0,pLocal
,-1,pWide
,dwChars
);
648 return lstrlen32W(pWide
);