2 * msvcrt.dll wide-char functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
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.
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.
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
26 #include "wine/unicode.h"
28 #include "msvcrt/stdio.h"
29 #include "msvcrt/stdlib.h"
30 #include "msvcrt/string.h"
31 #include "msvcrt/wctype.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
38 /* INTERNAL: MSVCRT_malloc() based wstrndup */
39 MSVCRT_wchar_t* msvcrt_wstrndup(const MSVCRT_wchar_t *buf, unsigned int size)
42 unsigned int len = strlenW(buf), max_len;
44 max_len = size <= len? size : len + 1;
46 ret = MSVCRT_malloc(max_len * sizeof (MSVCRT_wchar_t));
49 memcpy(ret,buf,max_len * sizeof (MSVCRT_wchar_t));
55 /*********************************************************************
58 MSVCRT_wchar_t* _wcsdup( const MSVCRT_wchar_t* str )
60 MSVCRT_wchar_t* ret = NULL;
63 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
64 ret = MSVCRT_malloc( size );
65 if (ret) memcpy( ret, str, size );
70 /*********************************************************************
71 * _wcsicoll (MSVCRT.@)
73 INT _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
75 /* FIXME: handle collates */
76 return strcmpiW( str1, str2 );
79 /*********************************************************************
82 MSVCRT_wchar_t* _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
84 MSVCRT_wchar_t* ret = str;
85 while ((n-- > 0) && *str) *str++ = c;
89 /*********************************************************************
92 MSVCRT_wchar_t* _wcsrev( MSVCRT_wchar_t* str )
94 MSVCRT_wchar_t* ret = str;
95 MSVCRT_wchar_t* end = str + strlenW(str) - 1;
98 MSVCRT_wchar_t t = *end;
105 /*********************************************************************
108 MSVCRT_wchar_t* _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
110 MSVCRT_wchar_t* ret = str;
111 while (*str) *str++ = c;
115 /*********************************************************************
118 double MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
120 const MSVCRT_wchar_t* str = lpszStr;
122 double ret = 0, divisor = 10.0;
124 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end);
127 * - Should set errno on failure
128 * - Should fail on overflow
129 * - Need to check which input formats are allowed
131 while (isspaceW(*str))
140 while (isdigitW(*str))
142 ret = ret * 10.0 + (*str - '0');
147 while (isdigitW(*str))
149 ret = ret + (*str - '0') / divisor;
154 if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd')
156 int negativeExponent = 0;
160 negativeExponent = 1;
163 while (isdigitW(*str))
165 exponent = exponent * 10 + (*str - '0');
170 if (negativeExponent)
171 ret = ret / pow(10.0, exponent);
173 ret = ret * pow(10.0, exponent);
181 *end = (MSVCRT_wchar_t*)str;
183 TRACE("returning %g\n", ret);
187 /*********************************************************************
188 * _vsnwprintf (MSVCRT.@)
190 int _vsnwprintf(MSVCRT_wchar_t *str, unsigned int len,
191 const MSVCRT_wchar_t *format, va_list valist)
193 return vsnprintfW(str, len, format, valist);
196 /*********************************************************************
197 * vswprintf (MSVCRT.@)
199 int MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args )
201 return vsnprintfW( str, INT_MAX, format, args );
204 /*********************************************************************
207 int MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
209 /* FIXME: handle collates */
210 return strcmpW( str1, str2 );
213 /*********************************************************************
216 MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
218 const MSVCRT_wchar_t* p;
221 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
227 /*********************************************************************
230 INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
232 return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
235 /*********************************************************************
236 * iswalnum (MSVCRT.@)
238 INT MSVCRT_iswalnum( MSVCRT_wchar_t wc )
240 return isalnumW( wc );
243 /*********************************************************************
244 * iswalpha (MSVCRT.@)
246 INT MSVCRT_iswalpha( MSVCRT_wchar_t wc )
248 return isalphaW( wc );
251 /*********************************************************************
252 * iswcntrl (MSVCRT.@)
254 INT MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
256 return iscntrlW( wc );
259 /*********************************************************************
260 * iswdigit (MSVCRT.@)
262 INT MSVCRT_iswdigit( MSVCRT_wchar_t wc )
264 return isdigitW( wc );
267 /*********************************************************************
268 * iswgraph (MSVCRT.@)
270 INT MSVCRT_iswgraph( MSVCRT_wchar_t wc )
272 return isgraphW( wc );
275 /*********************************************************************
276 * iswlower (MSVCRT.@)
278 INT MSVCRT_iswlower( MSVCRT_wchar_t wc )
280 return islowerW( wc );
283 /*********************************************************************
284 * iswprint (MSVCRT.@)
286 INT MSVCRT_iswprint( MSVCRT_wchar_t wc )
288 return isprintW( wc );
291 /*********************************************************************
292 * iswpunct (MSVCRT.@)
294 INT MSVCRT_iswpunct( MSVCRT_wchar_t wc )
296 return ispunctW( wc );
299 /*********************************************************************
300 * iswspace (MSVCRT.@)
302 INT MSVCRT_iswspace( MSVCRT_wchar_t wc )
304 return isspaceW( wc );
307 /*********************************************************************
308 * iswupper (MSVCRT.@)
310 INT MSVCRT_iswupper( MSVCRT_wchar_t wc )
312 return isupperW( wc );
315 /*********************************************************************
316 * iswxdigit (MSVCRT.@)
318 INT MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
320 return isxdigitW( wc );