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
25 #include "wine/unicode.h"
27 #include "msvcrt/stdio.h"
28 #include "msvcrt/stdlib.h"
29 #include "msvcrt/string.h"
30 #include "msvcrt/wctype.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
37 /* INTERNAL: MSVCRT_malloc() based wstrndup */
38 MSVCRT_wchar_t
* msvcrt_wstrndup(const MSVCRT_wchar_t
*buf
, unsigned int size
)
41 unsigned int len
= strlenW(buf
), max_len
;
43 max_len
= size
<= len
? size
: len
+ 1;
45 ret
= MSVCRT_malloc(max_len
* sizeof (MSVCRT_wchar_t
));
48 memcpy(ret
,buf
,max_len
* sizeof (MSVCRT_wchar_t
));
54 /*********************************************************************
57 MSVCRT_wchar_t
* _wcsdup( const MSVCRT_wchar_t
* str
)
59 MSVCRT_wchar_t
* ret
= NULL
;
62 int size
= (strlenW(str
) + 1) * sizeof(MSVCRT_wchar_t
);
63 ret
= MSVCRT_malloc( size
);
64 if (ret
) memcpy( ret
, str
, size
);
69 /*********************************************************************
70 * _wcsicoll (MSVCRT.@)
72 INT
_wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
74 /* FIXME: handle collates */
75 return strcmpiW( str1
, str2
);
78 /*********************************************************************
81 MSVCRT_wchar_t
* _wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
83 MSVCRT_wchar_t
* ret
= str
;
84 while ((n
-- > 0) && *str
) *str
++ = c
;
88 /*********************************************************************
91 MSVCRT_wchar_t
* _wcsrev( MSVCRT_wchar_t
* str
)
93 MSVCRT_wchar_t
* ret
= str
;
94 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
97 MSVCRT_wchar_t t
= *end
;
104 /*********************************************************************
107 MSVCRT_wchar_t
* _wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
109 MSVCRT_wchar_t
* ret
= str
;
110 while (*str
) *str
++ = c
;
114 /*********************************************************************
117 double MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
119 const MSVCRT_wchar_t
* str
= lpszStr
;
121 double ret
= 0, divisor
= 10.0;
123 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr
), end
);
126 * - Should set errno on failure
127 * - Should fail on overflow
128 * - Need to check which input formats are allowed
130 while (isspaceW(*str
))
139 while (isdigitW(*str
))
141 ret
= ret
* 10.0 + (*str
- '0');
146 while (isdigitW(*str
))
148 ret
= ret
+ (*str
- '0') / divisor
;
154 *end
= (MSVCRT_wchar_t
*)str
;
156 TRACE("returning %g\n", ret
);
160 /*********************************************************************
161 * _vsnwprintf (MSVCRT.@)
163 int _vsnwprintf(MSVCRT_wchar_t
*str
, unsigned int len
,
164 const MSVCRT_wchar_t
*format
, va_list valist
)
166 return vsnprintfW(str
, len
, format
, valist
);
169 /*********************************************************************
170 * vswprintf (MSVCRT.@)
172 int MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, va_list args
)
174 return vsnprintfW( str
, INT_MAX
, format
, args
);
177 /*********************************************************************
180 int MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
182 /* FIXME: handle collates */
183 return strcmpW( str1
, str2
);
186 /*********************************************************************
189 MSVCRT_wchar_t
* MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
191 const MSVCRT_wchar_t
* p
;
194 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
200 /*********************************************************************
203 INT
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
205 return WideCharToMultiByte( CP_ACP
, 0, &ch
, 1, dst
, 6, NULL
, NULL
);
208 /*********************************************************************
209 * iswalnum (MSVCRT.@)
211 INT
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
213 return isalnumW( wc
);
216 /*********************************************************************
217 * iswalpha (MSVCRT.@)
219 INT
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
221 return isalphaW( wc
);
224 /*********************************************************************
225 * iswcntrl (MSVCRT.@)
227 INT
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
229 return iscntrlW( wc
);
232 /*********************************************************************
233 * iswdigit (MSVCRT.@)
235 INT
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
237 return isdigitW( wc
);
240 /*********************************************************************
241 * iswgraph (MSVCRT.@)
243 INT
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
245 return isgraphW( wc
);
248 /*********************************************************************
249 * iswlower (MSVCRT.@)
251 INT
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
253 return islowerW( wc
);
256 /*********************************************************************
257 * iswprint (MSVCRT.@)
259 INT
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
261 return isprintW( wc
);
264 /*********************************************************************
265 * iswpunct (MSVCRT.@)
267 INT
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
269 return ispunctW( wc
);
272 /*********************************************************************
273 * iswspace (MSVCRT.@)
275 INT
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
277 return isspaceW( wc
);
280 /*********************************************************************
281 * iswupper (MSVCRT.@)
283 INT
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
285 return isupperW( wc
);
288 /*********************************************************************
289 * iswxdigit (MSVCRT.@)
291 INT
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
293 return isxdigitW( wc
);