4 * Copyright 1993 Yngvi Sigurjonsson
5 * Copyright 1996 Alexandre Julliard
15 static const BYTE STRING_Oem2Ansi
[256] =
16 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\244"
17 "\020\021\022\023\266\247\026\027\030\031\032\033\034\035\036\037"
18 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
19 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
20 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
21 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
22 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
23 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
24 "\307\374\351\342\344\340\345\347\352\353\350\357\356\354\304\305"
25 "\311\346\306\364\366\362\373\371\377\326\334\242\243\245\120\203"
26 "\341\355\363\372\361\321\252\272\277\137\254\275\274\241\253\273"
27 "\137\137\137\246\246\246\246\053\053\246\246\053\053\053\053\053"
28 "\053\055\055\053\055\053\246\246\053\053\055\055\246\055\053\055"
29 "\055\055\055\053\053\053\053\053\053\053\053\137\137\246\137\137"
30 "\137\337\137\266\137\137\265\137\137\137\137\137\137\137\137\137"
31 "\137\261\137\137\137\137\367\137\260\225\267\137\156\262\137\137";
33 static const BYTE STRING_Ansi2Oem
[256] =
34 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
35 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
36 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
37 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
38 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
39 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
40 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
41 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
42 "\200\201\054\237\054\137\375\374\210\045\123\074\117\215\216\217"
43 "\220\140\047\042\042\371\055\137\230\231\163\076\157\235\236\131"
44 "\040\255\233\234\017\235\335\025\042\143\246\256\252\055\162\137"
45 "\370\361\375\063\047\346\024\372\054\061\247\257\254\253\137\250"
46 "\101\101\101\101\216\217\222\200\105\220\105\105\111\111\111\111"
47 "\104\245\117\117\117\117\231\170\117\125\125\125\232\131\137\341"
48 "\205\240\203\141\204\206\221\207\212\202\210\211\215\241\214\213"
49 "\144\244\225\242\223\157\224\366\157\227\243\226\201\171\137\230";
51 #define OEM_TO_ANSI(ch) (STRING_Oem2Ansi[(unsigned char)(ch)])
52 #define ANSI_TO_OEM(ch) (STRING_Ansi2Oem[(unsigned char)(ch)])
55 /***********************************************************************
56 * hmemcpy (KERNEL.348)
58 void hmemcpy( LPVOID dst
, LPCVOID src
, LONG count
)
60 memcpy( dst
, src
, count
);
64 /***********************************************************************
65 * lstrcat16 (KERNEL.89)
67 SEGPTR
lstrcat16( SEGPTR dst
, SEGPTR src
)
69 lstrcat32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), (LPCSTR
)PTR_SEG_TO_LIN(src
) );
74 /***********************************************************************
75 * lstrcat32A (KERNEL32.599)
77 LPSTR
lstrcat32A( LPSTR dst
, LPCSTR src
)
79 dprintf_string(stddeb
,"strcat: Append '%s' to '%s'\n",
80 (src
)?src
:"NULL",(dst
)?dst
:"NULL");
86 /***********************************************************************
87 * lstrcat32W (KERNEL32.600)
89 LPWSTR
lstrcat32W( LPWSTR dst
, LPCWSTR src
)
91 register LPWSTR p
= dst
;
93 while ((*p
++ = *src
++));
98 /***********************************************************************
99 * lstrcatn16 (KERNEL.352)
101 SEGPTR
lstrcatn16( SEGPTR dst
, SEGPTR src
, INT16 n
)
103 lstrcatn32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), (LPCSTR
)PTR_SEG_TO_LIN(src
), n
);
108 /***********************************************************************
109 * lstrcatn32A (Not a Windows API)
111 LPSTR
lstrcatn32A( LPSTR dst
, LPCSTR src
, INT32 n
)
113 register LPSTR p
= dst
;
114 dprintf_string(stddeb
,"strcatn add %d chars from '%s' to '%s'\n",
115 n
,(src
)?src
:"NULL",(dst
)?dst
:"NULL");
117 if ((n
-= (INT32
)(p
- dst
)) <= 0) return dst
;
118 lstrcpyn32A( p
, src
, n
);
123 /***********************************************************************
124 * lstrcatn32W (Not a Windows API)
126 LPWSTR
lstrcatn32W( LPWSTR dst
, LPCWSTR src
, INT32 n
)
128 register LPWSTR p
= dst
;
130 if ((n
-= (INT32
)(p
- dst
)) <= 0) return dst
;
131 lstrcpyn32W( p
, src
, n
);
136 /***********************************************************************
137 * lstrcmp16 (USER.430)
139 INT16
lstrcmp16( LPCSTR str1
, LPCSTR str2
)
141 return (INT16
)lstrcmp32A( str1
, str2
);
145 /***********************************************************************
146 * lstrcmp32A (KERNEL.602)
148 INT32
lstrcmp32A( LPCSTR str1
, LPCSTR str2
)
150 dprintf_string(stddeb
,"strcmp: '%s' and '%s'\n",
151 (str1
)?str1
:"NULL",(str2
)?str2
:"NULL");
152 return (INT32
)strcmp( str1
, str2
);
156 /***********************************************************************
157 * lstrcmp32W (KERNEL.603)
159 INT32
lstrcmp32W( LPCWSTR str1
, LPCWSTR str2
)
161 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
162 return (INT32
)(*str1
- *str2
);
166 /***********************************************************************
167 * lstrcmpi16 (USER.471)
169 INT16
lstrcmpi16( LPCSTR str1
, LPCSTR str2
)
171 return (INT16
)lstrcmpi32A( str1
, str2
);
175 /***********************************************************************
176 * lstrcmpi32A (KERNEL32.605)
178 INT32
lstrcmpi32A( LPCSTR str1
, LPCSTR str2
)
182 dprintf_string(stddeb
,"strcmpi '%s' and '%s'\n",
183 (str1
)?str1
:"NULL",(str2
)?str2
:"NULL");
186 if ((res
= toupper(*str1
) - toupper(*str2
)) != 0) return res
;
190 return toupper(*str1
) - toupper(*str2
);
194 /***********************************************************************
195 * lstrcmpi32W (KERNEL32.606)
197 INT32
lstrcmpi32W( LPCWSTR str1
, LPCWSTR str2
)
204 if ((res
= toupper(*str1
) - toupper(*str2
)) != 0) return res
;
208 return toupper(*str1
) - toupper(*str2
);
212 /***********************************************************************
213 * lstrcpy16 (KERNEL.88)
215 SEGPTR
lstrcpy16( SEGPTR dst
, SEGPTR src
)
217 lstrcpy32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), (LPCSTR
)PTR_SEG_TO_LIN(src
) );
222 /***********************************************************************
223 * lstrcpy32A (KERNEL32.608)
225 LPSTR
lstrcpy32A( LPSTR dst
, LPCSTR src
)
227 dprintf_string(stddeb
,"strcpy '%s'\n",
229 if (!src
|| !dst
) return NULL
;
235 /***********************************************************************
236 * lstrcpy32W (KERNEL32.609)
238 LPWSTR
lstrcpy32W( LPWSTR dst
, LPCWSTR src
)
240 register LPWSTR p
= dst
;
241 while ((*p
++ = *src
++));
246 /***********************************************************************
247 * lstrcpyn16 (KERNEL.353)
249 SEGPTR
lstrcpyn16( SEGPTR dst
, SEGPTR src
, INT16 n
)
251 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(dst
), (LPCSTR
)PTR_SEG_TO_LIN(src
), n
);
256 /***********************************************************************
257 * lstrcpyn32A (KERNEL32.611)
259 LPSTR
lstrcpyn32A( LPSTR dst
, LPCSTR src
, INT32 n
)
262 dprintf_string(stddeb
,"strcpyn '%s' for %d chars\n",
264 while ((n
-- > 1) && *src
) *p
++ = *src
++;
270 /***********************************************************************
271 * lstrcpyn32W (KERNEL32.612)
273 LPWSTR
lstrcpyn32W( LPWSTR dst
, LPCWSTR src
, INT32 n
)
276 while ((n
-- > 1) && *src
) *p
++ = *src
++;
282 /***********************************************************************
283 * lstrlen16 (KERNEL.90)
285 INT16
lstrlen16( LPCSTR str
)
287 return (INT16
)lstrlen32A( str
);
291 /***********************************************************************
292 * lstrlen32A (KERNEL32.614)
294 INT32
lstrlen32A( LPCSTR str
)
296 /* looks weird, but win3.1 KERNEL got a GeneralProtection handler
297 * in lstrlen() ... we check only for NULL pointer reference.
300 dprintf_string(stddeb
,"strlen '%s'\n", (str
)?str
:"NULL");
302 return (INT32
)strlen(str
);
306 /***********************************************************************
307 * lstrlen32W (KERNEL32.615)
309 INT32
lstrlen32W( LPCWSTR str
)
313 while (*str
++) len
++;
318 /***********************************************************************
319 * lstrncmp32A (Not a Windows API)
321 INT32
lstrncmp32A( LPCSTR str1
, LPCSTR str2
, INT32 n
)
323 dprintf_string(stddeb
,"strncmp '%s' and '%s' for %d chars\n",
324 (str1
)?str1
:"NULL",(str2
)?str2
:"NULL",n
);
325 return (INT32
)strncmp( str1
, str2
, n
);
329 /***********************************************************************
330 * lstrncmp32W (Not a Windows API)
332 INT32
lstrncmp32W( LPCWSTR str1
, LPCWSTR str2
, INT32 n
)
335 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
336 return (INT32
)(*str1
- *str2
);
340 /***********************************************************************
341 * lstrncmpi32A (Not a Windows API)
343 INT32
lstrncmpi32A( LPCSTR str1
, LPCSTR str2
, INT32 n
)
347 dprintf_string(stddeb
,"strncmpi '%s' and '%s' for %d chars\n",
348 (str1
)?str1
:"NULL",(str2
)?str2
:"NULL",n
);
350 while ((--n
> 0) && *str1
)
351 if ( (res
= toupper(*str1
++) - toupper(*str2
++)) ) return res
;
353 return toupper(*str1
) - toupper(*str2
);
357 /***********************************************************************
358 * lstrncmpi32W (Not a Windows API)
360 INT32
lstrncmpi32W( LPCWSTR str1
, LPCWSTR str2
, INT32 n
)
365 while ((--n
> 0) && *str1
)
368 if ((res
= toupper(*str1
) - toupper(*str2
)) != 0) return res
;
372 return toupper(*str1
) - toupper(*str2
);
376 /***********************************************************************
377 * lstrcpyAtoW (Not a Windows API)
379 LPWSTR
lstrcpyAtoW( LPWSTR dst
, LPCSTR src
)
381 register LPWSTR p
= dst
;
382 while ((*p
++ = (WCHAR
)(unsigned char)*src
++));
387 /***********************************************************************
388 * lstrcpyWtoA (Not a Windows API)
390 LPSTR
lstrcpyWtoA( LPSTR dst
, LPCWSTR src
)
392 register LPSTR p
= dst
;
393 while ((*p
++ = (CHAR
)*src
++));
398 /***********************************************************************
399 * lstrcpynAtoW (Not a Windows API)
401 LPWSTR
lstrcpynAtoW( LPWSTR dst
, LPCSTR src
, INT32 n
)
404 while ((n
-- > 1) && *src
) *p
++ = (WCHAR
)(unsigned char)*src
++;
410 /***********************************************************************
411 * lstrcpynWtoA (Not a Windows API)
413 LPSTR
lstrcpynWtoA( LPSTR dst
, LPCWSTR src
, INT32 n
)
416 while ((n
-- > 1) && *src
) *p
++ = (CHAR
)*src
++;
422 /***********************************************************************
425 void Copy( LPVOID src
, LPVOID dst
, WORD size
)
427 memcpy( dst
, src
, size
);
431 /***********************************************************************
432 * RtlFillMemory (KERNEL32.441)
434 VOID
RtlFillMemory( LPVOID ptr
, UINT32 len
, UINT32 fill
)
436 memset( ptr
, fill
, len
);
440 /***********************************************************************
441 * RtlMoveMemory (KERNEL32.442)
443 VOID
RtlMoveMemory( LPVOID dst
, LPCVOID src
, UINT32 len
)
445 memmove( dst
, src
, len
);
449 /***********************************************************************
450 * RtlZeroMemory (KERNEL32.444)
452 VOID
RtlZeroMemory( LPVOID ptr
, UINT32 len
)
454 memset( ptr
, 0, len
);
458 /***********************************************************************
459 * AnsiToOem16 (KEYBOARD.5)
461 INT16
AnsiToOem16( LPCSTR s
, LPSTR d
)
463 CharToOem32A( s
, d
);
468 /***********************************************************************
469 * OemToAnsi16 (KEYBOARD.6)
471 INT16
OemToAnsi16( LPCSTR s
, LPSTR d
)
473 OemToChar32A( s
, d
);
478 /***********************************************************************
479 * AnsiToOemBuff16 (KEYBOARD.134)
481 void AnsiToOemBuff16( LPCSTR s
, LPSTR d
, UINT16 len
)
483 CharToOemBuff32A( s
, d
, len
? len
: 65536 );
487 /***********************************************************************
488 * OemToAnsiBuff16 (KEYBOARD.135)
490 void OemToAnsiBuff16( LPCSTR s
, LPSTR d
, UINT16 len
)
492 OemToCharBuff32A( s
, d
, len
? len
: 65536 );
496 /***********************************************************************
497 * CharToOem32A (USER32.36)
499 BOOL32
CharToOem32A( LPCSTR s
, LPSTR d
)
501 if (!s
|| !d
) return TRUE
;
502 dprintf_string(stddeb
,"CharToOem '%s'\n", (s
)?s
:"NULL");
503 while ((*d
++ = ANSI_TO_OEM(*s
++)));
504 dprintf_string(stddeb
," to '%s'\n", (d
)?d
:"NULL");
509 /***********************************************************************
510 * CharToOemBuff32A (USER32.37)
512 BOOL32
CharToOemBuff32A( LPCSTR s
, LPSTR d
, DWORD len
)
514 while (len
--) *d
++ = ANSI_TO_OEM(*s
++);
519 /***********************************************************************
520 * CharToOemBuff32W (USER32.38)
522 BOOL32
CharToOemBuff32W( LPCWSTR s
, LPSTR d
, DWORD len
)
524 while (len
--) *d
++ = ANSI_TO_OEM(*s
++);
529 /***********************************************************************
530 * CharToOem32W (USER32.39)
532 BOOL32
CharToOem32W( LPCWSTR s
, LPSTR d
)
534 while ((*d
++ = ANSI_TO_OEM(*s
++)));
539 /***********************************************************************
540 * OemToChar32A (USER32.401)
542 BOOL32
OemToChar32A( LPCSTR s
, LPSTR d
)
544 dprintf_string(stddeb
,"OemToChar '%s'\n", (s
)?s
:"NULL");
545 while ((*d
++ = OEM_TO_ANSI(*s
++)));
546 dprintf_string(stddeb
," to '%s'\n", (d
)?d
:"NULL");
551 /***********************************************************************
552 * OemToCharBuff32A (USER32.402)
554 BOOL32
OemToCharBuff32A( LPCSTR s
, LPSTR d
, DWORD len
)
556 dprintf_string(stddeb
,"OemToCharBuff '%s' for %ld chars\n", (s
)?s
:"NULL",len
);
557 while (len
--) *d
++ = OEM_TO_ANSI(*s
++);
562 /***********************************************************************
563 * OemToCharBuff32W (USER32.403)
565 BOOL32
OemToCharBuff32W( LPCSTR s
, LPWSTR d
, DWORD len
)
567 while (len
--) *d
++ = (WCHAR
)OEM_TO_ANSI(*s
++);
572 /***********************************************************************
573 * OemToChar32W (USER32.404)
575 BOOL32
OemToChar32W( LPCSTR s
, LPWSTR d
)
577 while ((*d
++ = (WCHAR
)OEM_TO_ANSI(*s
++)));