1 | /*
|
---|
2 | * msvcrt.dll wide-char functions
|
---|
3 | *
|
---|
4 | * Copyright 1999 Alexandre Julliard
|
---|
5 | * Copyright 2000 Jon Griffiths
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef __MINIVCRT__
|
---|
23 |
|
---|
24 | #include <limits.h>
|
---|
25 | #include <stdlib.h>
|
---|
26 | #include <stdio.h>
|
---|
27 | #include <ctype.h>
|
---|
28 | #include <string.h>
|
---|
29 |
|
---|
30 | #include "msvcrt.h"
|
---|
31 | #include "winnls.h"
|
---|
32 | #include "wine/unicode.h"
|
---|
33 |
|
---|
34 | #include "msvcrt/stdio.h"
|
---|
35 | #include "msvcrt/stdlib.h"
|
---|
36 | #include "msvcrt/string.h"
|
---|
37 | #include "msvcrt/wctype.h"
|
---|
38 |
|
---|
39 | #include "wine/debug.h"
|
---|
40 |
|
---|
41 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
42 |
|
---|
43 | #else /* !__MINIVCRT__ */
|
---|
44 |
|
---|
45 | #include <string.h>
|
---|
46 | #include <sys/limits.h>
|
---|
47 |
|
---|
48 | #include <winbase.h>
|
---|
49 |
|
---|
50 | #include "minivcrt.h"
|
---|
51 | #include "minivcrt_internal.h"
|
---|
52 |
|
---|
53 | #include "winternl.h"
|
---|
54 | #include "wine/unicode.h"
|
---|
55 |
|
---|
56 | #endif /* !__MINIVCRT__ */
|
---|
57 |
|
---|
58 | /* INTERNAL: MSVCRT_malloc() based wstrndup */
|
---|
59 | MSVCRT_wchar_t* msvcrt_wstrndup(const MSVCRT_wchar_t *buf, unsigned int size)
|
---|
60 | {
|
---|
61 | MSVCRT_wchar_t* ret;
|
---|
62 | unsigned int len = strlenW(buf), max_len;
|
---|
63 |
|
---|
64 | max_len = size <= len? size : len + 1;
|
---|
65 |
|
---|
66 | ret = MSVCRT_malloc(max_len * sizeof (MSVCRT_wchar_t));
|
---|
67 | if (ret)
|
---|
68 | {
|
---|
69 | memcpy(ret,buf,max_len * sizeof (MSVCRT_wchar_t));
|
---|
70 | ret[max_len] = 0;
|
---|
71 | }
|
---|
72 | return ret;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*********************************************************************
|
---|
76 | * _wcsdup (MSVCRT.@)
|
---|
77 | */
|
---|
78 | MSVCRT_wchar_t* _wcsdup( const MSVCRT_wchar_t* str )
|
---|
79 | {
|
---|
80 | MSVCRT_wchar_t* ret = NULL;
|
---|
81 | dprintf(("MSVCRT: _wcsdup %s",debugstr_w(str)));
|
---|
82 | if (str)
|
---|
83 | {
|
---|
84 | int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
|
---|
85 | ret = MSVCRT_malloc( size );
|
---|
86 | if (ret) memcpy( ret, str, size );
|
---|
87 | }
|
---|
88 | return ret;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*********************************************************************
|
---|
92 | * _wcsicoll (MSVCRT.@)
|
---|
93 | */
|
---|
94 | INT _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
---|
95 | {
|
---|
96 | /* FIXME: handle collates */
|
---|
97 | return strcmpiW( str1, str2 );
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*********************************************************************
|
---|
101 | * _wcsnset (MSVCRT.@)
|
---|
102 | */
|
---|
103 | MSVCRT_wchar_t* _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
|
---|
104 | {
|
---|
105 | MSVCRT_wchar_t* ret = str;
|
---|
106 | while ((n-- > 0) && *str) *str++ = c;
|
---|
107 | return ret;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /*********************************************************************
|
---|
111 | * _wcsrev (MSVCRT.@)
|
---|
112 | */
|
---|
113 | MSVCRT_wchar_t* _wcsrev( MSVCRT_wchar_t* str )
|
---|
114 | {
|
---|
115 | MSVCRT_wchar_t* ret = str;
|
---|
116 | MSVCRT_wchar_t* end = str + strlenW(str) - 1;
|
---|
117 | while (end > str)
|
---|
118 | {
|
---|
119 | MSVCRT_wchar_t t = *end;
|
---|
120 | *end-- = *str;
|
---|
121 | *str++ = t;
|
---|
122 | }
|
---|
123 | return ret;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /*********************************************************************
|
---|
127 | * _wcsset (MSVCRT.@)
|
---|
128 | */
|
---|
129 | MSVCRT_wchar_t* _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
|
---|
130 | {
|
---|
131 | MSVCRT_wchar_t* ret = str;
|
---|
132 | while (*str) *str++ = c;
|
---|
133 | return ret;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*********************************************************************
|
---|
137 | * _vsnwprintf (MSVCRT.@)
|
---|
138 | */
|
---|
139 | int _vsnwprintf(MSVCRT_wchar_t *str, unsigned int len,
|
---|
140 | const MSVCRT_wchar_t *format, va_list valist)
|
---|
141 | {
|
---|
142 | return vsnprintfW(str, len, format, valist);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /*********************************************************************
|
---|
146 | * vswprintf (MSVCRT.@)
|
---|
147 | */
|
---|
148 | int MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args )
|
---|
149 | {
|
---|
150 | return vsnprintfW( str, INT_MAX, format, args );
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*********************************************************************
|
---|
154 | * wcscoll (MSVCRT.@)
|
---|
155 | */
|
---|
156 | int MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
|
---|
157 | {
|
---|
158 | /* FIXME: handle collates */
|
---|
159 | return strcmpW( str1, str2 );
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*********************************************************************
|
---|
163 | * wcspbrk (MSVCRT.@)
|
---|
164 | */
|
---|
165 | MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
|
---|
166 | {
|
---|
167 | const MSVCRT_wchar_t* p;
|
---|
168 | while (*str)
|
---|
169 | {
|
---|
170 | for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
|
---|
171 | str++;
|
---|
172 | }
|
---|
173 | return NULL;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*********************************************************************
|
---|
177 | * wctomb (MSVCRT.@)
|
---|
178 | */
|
---|
179 | INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
|
---|
180 | {
|
---|
181 | return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
|
---|
182 | }
|
---|
183 |
|
---|
184 | #ifndef __MINIVCRT__
|
---|
185 |
|
---|
186 | /*********************************************************************
|
---|
187 | * iswalnum (MSVCRT.@)
|
---|
188 | */
|
---|
189 | INT MSVCRT_iswalnum( MSVCRT_wchar_t wc )
|
---|
190 | {
|
---|
191 | return isalnumW( wc );
|
---|
192 | }
|
---|
193 |
|
---|
194 | /*********************************************************************
|
---|
195 | * iswalpha (MSVCRT.@)
|
---|
196 | */
|
---|
197 | INT MSVCRT_iswalpha( MSVCRT_wchar_t wc )
|
---|
198 | {
|
---|
199 | return isalphaW( wc );
|
---|
200 | }
|
---|
201 |
|
---|
202 | /*********************************************************************
|
---|
203 | * iswcntrl (MSVCRT.@)
|
---|
204 | */
|
---|
205 | INT MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
|
---|
206 | {
|
---|
207 | return iscntrlW( wc );
|
---|
208 | }
|
---|
209 |
|
---|
210 | /*********************************************************************
|
---|
211 | * iswdigit (MSVCRT.@)
|
---|
212 | */
|
---|
213 | INT MSVCRT_iswdigit( MSVCRT_wchar_t wc )
|
---|
214 | {
|
---|
215 | return isdigitW( wc );
|
---|
216 | }
|
---|
217 |
|
---|
218 | /*********************************************************************
|
---|
219 | * iswgraph (MSVCRT.@)
|
---|
220 | */
|
---|
221 | INT MSVCRT_iswgraph( MSVCRT_wchar_t wc )
|
---|
222 | {
|
---|
223 | return isgraphW( wc );
|
---|
224 | }
|
---|
225 |
|
---|
226 | /*********************************************************************
|
---|
227 | * iswlower (MSVCRT.@)
|
---|
228 | */
|
---|
229 | INT MSVCRT_iswlower( MSVCRT_wchar_t wc )
|
---|
230 | {
|
---|
231 | return islowerW( wc );
|
---|
232 | }
|
---|
233 |
|
---|
234 | /*********************************************************************
|
---|
235 | * iswprint (MSVCRT.@)
|
---|
236 | */
|
---|
237 | INT MSVCRT_iswprint( MSVCRT_wchar_t wc )
|
---|
238 | {
|
---|
239 | return isprintW( wc );
|
---|
240 | }
|
---|
241 |
|
---|
242 | /*********************************************************************
|
---|
243 | * iswpunct (MSVCRT.@)
|
---|
244 | */
|
---|
245 | INT MSVCRT_iswpunct( MSVCRT_wchar_t wc )
|
---|
246 | {
|
---|
247 | return ispunctW( wc );
|
---|
248 | }
|
---|
249 |
|
---|
250 | /*********************************************************************
|
---|
251 | * iswspace (MSVCRT.@)
|
---|
252 | */
|
---|
253 | INT MSVCRT_iswspace( MSVCRT_wchar_t wc )
|
---|
254 | {
|
---|
255 | return isspaceW( wc );
|
---|
256 | }
|
---|
257 |
|
---|
258 | /*********************************************************************
|
---|
259 | * iswupper (MSVCRT.@)
|
---|
260 | */
|
---|
261 | INT MSVCRT_iswupper( MSVCRT_wchar_t wc )
|
---|
262 | {
|
---|
263 | return isupperW( wc );
|
---|
264 | }
|
---|
265 |
|
---|
266 | /*********************************************************************
|
---|
267 | * iswxdigit (MSVCRT.@)
|
---|
268 | */
|
---|
269 | INT MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
|
---|
270 | {
|
---|
271 | return isxdigitW( wc );
|
---|
272 | }
|
---|
273 |
|
---|
274 | #endif /* !__MINIVCRT__ */
|
---|