| 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 | #include <limits.h> | 
|---|
| 22 | #include <stdlib.h> | 
|---|
| 23 | #include <stdio.h> | 
|---|
| 24 | #include <ctype.h> | 
|---|
| 25 | #include <string.h> | 
|---|
| 26 |  | 
|---|
| 27 | #include "msvcrt.h" | 
|---|
| 28 | #include "winnls.h" | 
|---|
| 29 | #include "wine/unicode.h" | 
|---|
| 30 |  | 
|---|
| 31 | #include "msvcrt/stdio.h" | 
|---|
| 32 | #include "msvcrt/stdlib.h" | 
|---|
| 33 | #include "msvcrt/string.h" | 
|---|
| 34 | #include "msvcrt/wctype.h" | 
|---|
| 35 |  | 
|---|
| 36 | #include "wine/debug.h" | 
|---|
| 37 |  | 
|---|
| 38 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | /* INTERNAL: MSVCRT_malloc() based wstrndup */ | 
|---|
| 42 | MSVCRT_wchar_t* msvcrt_wstrndup(const MSVCRT_wchar_t *buf, unsigned int size) | 
|---|
| 43 | { | 
|---|
| 44 | MSVCRT_wchar_t* ret; | 
|---|
| 45 | unsigned int len = strlenW(buf), max_len; | 
|---|
| 46 |  | 
|---|
| 47 | max_len = size <= len? size : len + 1; | 
|---|
| 48 |  | 
|---|
| 49 | ret = MSVCRT_malloc(max_len * sizeof (MSVCRT_wchar_t)); | 
|---|
| 50 | if (ret) | 
|---|
| 51 | { | 
|---|
| 52 | memcpy(ret,buf,max_len * sizeof (MSVCRT_wchar_t)); | 
|---|
| 53 | ret[max_len] = 0; | 
|---|
| 54 | } | 
|---|
| 55 | return ret; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | /********************************************************************* | 
|---|
| 59 | *              _wcsdup (MSVCRT.@) | 
|---|
| 60 | */ | 
|---|
| 61 | MSVCRT_wchar_t* _wcsdup( const MSVCRT_wchar_t* str ) | 
|---|
| 62 | { | 
|---|
| 63 | MSVCRT_wchar_t* ret = NULL; | 
|---|
| 64 | dprintf(("MSVCRT: _wcsdup %s",debugstr_w(str))); | 
|---|
| 65 | if (str) | 
|---|
| 66 | { | 
|---|
| 67 | int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t); | 
|---|
| 68 | ret = MSVCRT_malloc( size ); | 
|---|
| 69 | if (ret) memcpy( ret, str, size ); | 
|---|
| 70 | } | 
|---|
| 71 | return ret; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | /********************************************************************* | 
|---|
| 75 | *              _wcsicoll (MSVCRT.@) | 
|---|
| 76 | */ | 
|---|
| 77 | INT _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 ) | 
|---|
| 78 | { | 
|---|
| 79 | /* FIXME: handle collates */ | 
|---|
| 80 | return strcmpiW( str1, str2 ); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | /********************************************************************* | 
|---|
| 84 | *              _wcsnset (MSVCRT.@) | 
|---|
| 85 | */ | 
|---|
| 86 | MSVCRT_wchar_t* _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n ) | 
|---|
| 87 | { | 
|---|
| 88 | MSVCRT_wchar_t* ret = str; | 
|---|
| 89 | while ((n-- > 0) && *str) *str++ = c; | 
|---|
| 90 | return ret; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | /********************************************************************* | 
|---|
| 94 | *              _wcsrev (MSVCRT.@) | 
|---|
| 95 | */ | 
|---|
| 96 | MSVCRT_wchar_t* _wcsrev( MSVCRT_wchar_t* str ) | 
|---|
| 97 | { | 
|---|
| 98 | MSVCRT_wchar_t* ret = str; | 
|---|
| 99 | MSVCRT_wchar_t* end = str + strlenW(str) - 1; | 
|---|
| 100 | while (end > str) | 
|---|
| 101 | { | 
|---|
| 102 | MSVCRT_wchar_t t = *end; | 
|---|
| 103 | *end--  = *str; | 
|---|
| 104 | *str++  = t; | 
|---|
| 105 | } | 
|---|
| 106 | return ret; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | /********************************************************************* | 
|---|
| 110 | *              _wcsset (MSVCRT.@) | 
|---|
| 111 | */ | 
|---|
| 112 | MSVCRT_wchar_t* _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c ) | 
|---|
| 113 | { | 
|---|
| 114 | MSVCRT_wchar_t* ret = str; | 
|---|
| 115 | while (*str) *str++ = c; | 
|---|
| 116 | return ret; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | /********************************************************************* | 
|---|
| 120 | *              _vsnwprintf (MSVCRT.@) | 
|---|
| 121 | */ | 
|---|
| 122 | int _vsnwprintf(MSVCRT_wchar_t *str, unsigned int len, | 
|---|
| 123 | const MSVCRT_wchar_t *format, va_list valist) | 
|---|
| 124 | { | 
|---|
| 125 | return vsnprintfW(str, len, format, valist); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | /********************************************************************* | 
|---|
| 129 | *              vswprintf (MSVCRT.@) | 
|---|
| 130 | */ | 
|---|
| 131 | int MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args ) | 
|---|
| 132 | { | 
|---|
| 133 | return vsnprintfW( str, INT_MAX, format, args ); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | /********************************************************************* | 
|---|
| 137 | *              wcscoll (MSVCRT.@) | 
|---|
| 138 | */ | 
|---|
| 139 | int MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 ) | 
|---|
| 140 | { | 
|---|
| 141 | /* FIXME: handle collates */ | 
|---|
| 142 | return strcmpW( str1, str2 ); | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | /********************************************************************* | 
|---|
| 146 | *              wcspbrk (MSVCRT.@) | 
|---|
| 147 | */ | 
|---|
| 148 | MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept ) | 
|---|
| 149 | { | 
|---|
| 150 | const MSVCRT_wchar_t* p; | 
|---|
| 151 | while (*str) | 
|---|
| 152 | { | 
|---|
| 153 | for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str; | 
|---|
| 154 | str++; | 
|---|
| 155 | } | 
|---|
| 156 | return NULL; | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | /********************************************************************* | 
|---|
| 160 | *              wctomb (MSVCRT.@) | 
|---|
| 161 | */ | 
|---|
| 162 | INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch ) | 
|---|
| 163 | { | 
|---|
| 164 | return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL ); | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 | /********************************************************************* | 
|---|
| 168 | *              iswalnum (MSVCRT.@) | 
|---|
| 169 | */ | 
|---|
| 170 | INT MSVCRT_iswalnum( MSVCRT_wchar_t wc ) | 
|---|
| 171 | { | 
|---|
| 172 | return isalnumW( wc ); | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | /********************************************************************* | 
|---|
| 176 | *              iswalpha (MSVCRT.@) | 
|---|
| 177 | */ | 
|---|
| 178 | INT MSVCRT_iswalpha( MSVCRT_wchar_t wc ) | 
|---|
| 179 | { | 
|---|
| 180 | return isalphaW( wc ); | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|
| 183 | /********************************************************************* | 
|---|
| 184 | *              iswcntrl (MSVCRT.@) | 
|---|
| 185 | */ | 
|---|
| 186 | INT MSVCRT_iswcntrl( MSVCRT_wchar_t wc ) | 
|---|
| 187 | { | 
|---|
| 188 | return iscntrlW( wc ); | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | /********************************************************************* | 
|---|
| 192 | *              iswdigit (MSVCRT.@) | 
|---|
| 193 | */ | 
|---|
| 194 | INT MSVCRT_iswdigit( MSVCRT_wchar_t wc ) | 
|---|
| 195 | { | 
|---|
| 196 | return isdigitW( wc ); | 
|---|
| 197 | } | 
|---|
| 198 |  | 
|---|
| 199 | /********************************************************************* | 
|---|
| 200 | *              iswgraph (MSVCRT.@) | 
|---|
| 201 | */ | 
|---|
| 202 | INT MSVCRT_iswgraph( MSVCRT_wchar_t wc ) | 
|---|
| 203 | { | 
|---|
| 204 | return isgraphW( wc ); | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | /********************************************************************* | 
|---|
| 208 | *              iswlower (MSVCRT.@) | 
|---|
| 209 | */ | 
|---|
| 210 | INT MSVCRT_iswlower( MSVCRT_wchar_t wc ) | 
|---|
| 211 | { | 
|---|
| 212 | return islowerW( wc ); | 
|---|
| 213 | } | 
|---|
| 214 |  | 
|---|
| 215 | /********************************************************************* | 
|---|
| 216 | *              iswprint (MSVCRT.@) | 
|---|
| 217 | */ | 
|---|
| 218 | INT MSVCRT_iswprint( MSVCRT_wchar_t wc ) | 
|---|
| 219 | { | 
|---|
| 220 | return isprintW( wc ); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | /********************************************************************* | 
|---|
| 224 | *              iswpunct (MSVCRT.@) | 
|---|
| 225 | */ | 
|---|
| 226 | INT MSVCRT_iswpunct( MSVCRT_wchar_t wc ) | 
|---|
| 227 | { | 
|---|
| 228 | return ispunctW( wc ); | 
|---|
| 229 | } | 
|---|
| 230 |  | 
|---|
| 231 | /********************************************************************* | 
|---|
| 232 | *              iswspace (MSVCRT.@) | 
|---|
| 233 | */ | 
|---|
| 234 | INT MSVCRT_iswspace( MSVCRT_wchar_t wc ) | 
|---|
| 235 | { | 
|---|
| 236 | return isspaceW( wc ); | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | /********************************************************************* | 
|---|
| 240 | *              iswupper (MSVCRT.@) | 
|---|
| 241 | */ | 
|---|
| 242 | INT MSVCRT_iswupper( MSVCRT_wchar_t wc ) | 
|---|
| 243 | { | 
|---|
| 244 | return isupperW( wc ); | 
|---|
| 245 | } | 
|---|
| 246 |  | 
|---|
| 247 | /********************************************************************* | 
|---|
| 248 | *              iswxdigit (MSVCRT.@) | 
|---|
| 249 | */ | 
|---|
| 250 | INT MSVCRT_iswxdigit( MSVCRT_wchar_t wc ) | 
|---|
| 251 | { | 
|---|
| 252 | return isxdigitW( wc ); | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|