Added a framework for testing CreateProcess and a few tests.
[wine] / dlls / imm32 / string.c
1 /*
2  *      Helper functions for ANSI<->UNICODE string conversion
3  *
4  *      Copyright 2000 Hidenori Takeshima
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "winbase.h"
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "winnls.h"
29 #include "immddk.h"
30 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(imm);
32
33 #include "imm_private.h"
34
35
36 INT IMM32_strlenAtoW( LPCSTR lpstr )
37 {
38         INT     len;
39
40         len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, NULL, 0 );
41         return ( len > 0 ) ? (len-1) : 0;
42 }
43
44 INT IMM32_strlenWtoA( LPCWSTR lpwstr )
45 {
46         INT     len;
47
48         len = WideCharToMultiByte( CP_ACP, 0, lpwstr, -1,
49                                    NULL, 0, NULL, NULL );
50         return ( len > 0 ) ? (len-1) : 0;
51 }
52
53 LPWSTR IMM32_strncpyAtoW( LPWSTR lpwstr, LPCSTR lpstr, INT wbuflen )
54 {
55         INT     len;
56
57         len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, lpwstr, wbuflen );
58         if ( len == 0 )
59                 *lpwstr = 0;
60         return lpwstr;
61 }
62
63 LPSTR IMM32_strncpyWtoA( LPSTR lpstr, LPCWSTR lpwstr, INT abuflen )
64 {
65         INT     len;
66
67         len = WideCharToMultiByte( CP_ACP, 0, lpwstr, -1,
68                                    lpstr, abuflen, NULL, NULL );
69         if ( len == 0 )
70                 *lpstr = 0;
71         return lpstr;
72 }
73
74 LPWSTR IMM32_strdupAtoW( LPCSTR lpstr )
75 {
76         INT len;
77         LPWSTR lpwstr = NULL;
78
79         len = IMM32_strlenAtoW( lpstr );
80         if ( len > 0 )
81         {
82                 lpwstr = (LPWSTR)IMM32_HeapAlloc( 0, sizeof(WCHAR)*(len+1) );
83                 if ( lpwstr != NULL )
84                         (void)IMM32_strncpyAtoW( lpwstr, lpstr, len+1 );
85         }
86
87         return lpwstr;
88 }
89
90 LPSTR IMM32_strdupWtoA( LPCWSTR lpwstr )
91 {
92         INT len;
93         LPSTR lpstr = NULL;
94
95         len = IMM32_strlenWtoA( lpwstr );
96         if ( len > 0 )
97         {
98                 lpstr = (LPSTR)IMM32_HeapAlloc( 0, sizeof(CHAR)*(len+1) );
99                 if ( lpstr != NULL )
100                         (void)IMM32_strncpyWtoA( lpstr, lpwstr, len+1 );
101         }
102
103         return lpstr;
104 }