Removed a few dependencies on kernel32 functions.
[wine] / dlls / crtdll / mbstring.c
1 /*
2  * CRTDLL multi-byte string functions
3  *
4  * Copyright 1999 Alexandre Julliard
5  */
6
7 #include "windef.h"
8 #include "winbase.h"
9 #include "winnls.h"
10 #include "crtdll.h"
11
12
13 /*********************************************************************
14  *           CRTDLL__mbsinc    (CRTDLL.205)
15  */
16 LPSTR __cdecl CRTDLL__mbsinc( LPCSTR str )
17 {
18     if (IsDBCSLeadByte( *str )) str++;
19     return (LPSTR)(str + 1);
20 }
21
22
23 /*********************************************************************
24  *           CRTDLL__mbslen    (CRTDLL.206)
25  */
26 INT __cdecl CRTDLL__mbslen( LPCSTR str )
27 {
28     INT len;
29     for (len = 0; *str; len++, str++) if (IsDBCSLeadByte(str[0]) && str[1]) str++;
30     return len;
31 }
32
33
34 /*********************************************************************
35  *           CRTDLL_mbtowc    (CRTDLL.430)
36  */
37 INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
38 {
39     if (n <= 0) return 0;
40     if (!str) return 0;
41     if (!MultiByteToWideChar( CP_ACP, 0, str, n, dst, 1 )) return 0;
42     /* return the number of bytes from src that have been used */
43     if (!*str) return 0;
44     if (n >= 2 && IsDBCSLeadByte(*str) && str[1]) return 2;
45     return 1;
46 }