| 1 | /*
|
|---|
| 2 | * NTDLL wide-char functions
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 2000 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 | #include "config.h"
|
|---|
| 23 |
|
|---|
| 24 | #include <ctype.h>
|
|---|
| 25 | #include <limits.h>
|
|---|
| 26 | #include <stdlib.h>
|
|---|
| 27 | #include <string.h>
|
|---|
| 28 | #include <stdio.h>
|
|---|
| 29 |
|
|---|
| 30 | #include "ntddk.h"
|
|---|
| 31 | #include "wine/unicode.h"
|
|---|
| 32 | #include "wine/debug.h"
|
|---|
| 33 |
|
|---|
| 34 | WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | /*********************************************************************
|
|---|
| 38 | * _wcsicmp (NTDLL.@)
|
|---|
| 39 | */
|
|---|
| 40 | INT __cdecl NTDLL__wcsicmp( LPCWSTR str1, LPCWSTR str2 )
|
|---|
| 41 | {
|
|---|
| 42 | return strcmpiW( str1, str2 );
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | /*********************************************************************
|
|---|
| 47 | * _wcslwr (NTDLL.@)
|
|---|
| 48 | */
|
|---|
| 49 | LPWSTR __cdecl NTDLL__wcslwr( LPWSTR str )
|
|---|
| 50 | {
|
|---|
| 51 | return strlwrW( str );
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | /*********************************************************************
|
|---|
| 56 | * _wcsnicmp (NTDLL.@)
|
|---|
| 57 | */
|
|---|
| 58 | INT __cdecl NTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n )
|
|---|
| 59 | {
|
|---|
| 60 | return strncmpiW( str1, str2, n );
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | /*********************************************************************
|
|---|
| 65 | * _wcsupr (NTDLL.@)
|
|---|
| 66 | */
|
|---|
| 67 | LPWSTR __cdecl NTDLL__wcsupr( LPWSTR str )
|
|---|
| 68 | {
|
|---|
| 69 | return struprW( str );
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | /*********************************************************************
|
|---|
| 74 | * towlower (NTDLL.@)
|
|---|
| 75 | */
|
|---|
| 76 | WCHAR __cdecl NTDLL_towlower( WCHAR ch )
|
|---|
| 77 | {
|
|---|
| 78 | return tolowerW(ch);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | /*********************************************************************
|
|---|
| 83 | * towupper (NTDLL.@)
|
|---|
| 84 | */
|
|---|
| 85 | WCHAR __cdecl NTDLL_towupper( WCHAR ch )
|
|---|
| 86 | {
|
|---|
| 87 | return toupperW(ch);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | /***********************************************************************
|
|---|
| 92 | * wcscat (NTDLL.@)
|
|---|
| 93 | */
|
|---|
| 94 | LPWSTR __cdecl NTDLL_wcscat( LPWSTR dst, LPCWSTR src )
|
|---|
| 95 | {
|
|---|
| 96 | return strcatW( dst, src );
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /*********************************************************************
|
|---|
| 101 | * wcschr (NTDLL.@)
|
|---|
| 102 | */
|
|---|
| 103 | LPWSTR __cdecl NTDLL_wcschr( LPCWSTR str, WCHAR ch )
|
|---|
| 104 | {
|
|---|
| 105 | return strchrW( str, ch );
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | /*********************************************************************
|
|---|
| 110 | * wcscmp (NTDLL.@)
|
|---|
| 111 | */
|
|---|
| 112 | INT __cdecl NTDLL_wcscmp( LPCWSTR str1, LPCWSTR str2 )
|
|---|
| 113 | {
|
|---|
| 114 | return strcmpW( str1, str2 );
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | /***********************************************************************
|
|---|
| 119 | * wcscpy (NTDLL.@)
|
|---|
| 120 | */
|
|---|
| 121 | LPWSTR __cdecl NTDLL_wcscpy( LPWSTR dst, LPCWSTR src )
|
|---|
| 122 | {
|
|---|
| 123 | return strcpyW( dst, src );
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | /*********************************************************************
|
|---|
| 128 | * wcscspn (NTDLL.@)
|
|---|
| 129 | */
|
|---|
| 130 | INT __cdecl NTDLL_wcscspn( LPCWSTR str, LPCWSTR reject )
|
|---|
| 131 | {
|
|---|
| 132 | LPCWSTR start = str;
|
|---|
| 133 | while (*str)
|
|---|
| 134 | {
|
|---|
| 135 | LPCWSTR p = reject;
|
|---|
| 136 | while (*p && (*p != *str)) p++;
|
|---|
| 137 | if (*p) break;
|
|---|
| 138 | str++;
|
|---|
| 139 | }
|
|---|
| 140 | return str - start;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | /***********************************************************************
|
|---|
| 145 | * wcslen (NTDLL.@)
|
|---|
| 146 | */
|
|---|
| 147 | INT __cdecl NTDLL_wcslen( LPCWSTR str )
|
|---|
| 148 | {
|
|---|
| 149 | return strlenW( str );
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | /*********************************************************************
|
|---|
| 154 | * wcsncat (NTDLL.@)
|
|---|
| 155 | */
|
|---|
| 156 | LPWSTR __cdecl NTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT n )
|
|---|
| 157 | {
|
|---|
| 158 | LPWSTR ret = s1;
|
|---|
| 159 | while (*s1) s1++;
|
|---|
| 160 | while (n-- > 0) if (!(*s1++ = *s2++)) return ret;
|
|---|
| 161 | *s1 = 0;
|
|---|
| 162 | return ret;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 | /*********************************************************************
|
|---|
| 167 | * wcsncmp (NTDLL.@)
|
|---|
| 168 | */
|
|---|
| 169 | INT __cdecl NTDLL_wcsncmp( LPCWSTR str1, LPCWSTR str2, INT n )
|
|---|
| 170 | {
|
|---|
| 171 | return strncmpW( str1, str2, n );
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | /*********************************************************************
|
|---|
| 176 | * wcsncpy (NTDLL.@)
|
|---|
| 177 | */
|
|---|
| 178 | LPWSTR __cdecl NTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT n )
|
|---|
| 179 | {
|
|---|
| 180 | return strncpyW( s1, s2, n );
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | /*********************************************************************
|
|---|
| 185 | * wcspbrk (NTDLL.@)
|
|---|
| 186 | */
|
|---|
| 187 | LPWSTR __cdecl NTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept )
|
|---|
| 188 | {
|
|---|
| 189 | LPCWSTR p;
|
|---|
| 190 | while (*str)
|
|---|
| 191 | {
|
|---|
| 192 | for (p = accept; *p; p++) if (*p == *str) return (LPWSTR)str;
|
|---|
| 193 | str++;
|
|---|
| 194 | }
|
|---|
| 195 | return NULL;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | /*********************************************************************
|
|---|
| 200 | * wcsrchr (NTDLL.@)
|
|---|
| 201 | */
|
|---|
| 202 | LPWSTR __cdecl NTDLL_wcsrchr( LPWSTR str, WCHAR ch )
|
|---|
| 203 | {
|
|---|
| 204 | LPWSTR last = NULL;
|
|---|
| 205 | while (*str)
|
|---|
| 206 | {
|
|---|
| 207 | if (*str == ch) last = str;
|
|---|
| 208 | str++;
|
|---|
| 209 | }
|
|---|
| 210 | return last;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | /*********************************************************************
|
|---|
| 215 | * wcsspn (NTDLL.@)
|
|---|
| 216 | */
|
|---|
| 217 | INT __cdecl NTDLL_wcsspn( LPCWSTR str, LPCWSTR accept )
|
|---|
| 218 | {
|
|---|
| 219 | LPCWSTR start = str;
|
|---|
| 220 | while (*str)
|
|---|
| 221 | {
|
|---|
| 222 | LPCWSTR p = accept;
|
|---|
| 223 | while (*p && (*p != *str)) p++;
|
|---|
| 224 | if (!*p) break;
|
|---|
| 225 | str++;
|
|---|
| 226 | }
|
|---|
| 227 | return str - start;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 | /*********************************************************************
|
|---|
| 232 | * wcsstr (NTDLL.@)
|
|---|
| 233 | */
|
|---|
| 234 | LPWSTR __cdecl NTDLL_wcsstr( LPCWSTR str, LPCWSTR sub )
|
|---|
| 235 | {
|
|---|
| 236 | return strstrW( str, sub );
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | /*********************************************************************
|
|---|
| 241 | * wcstok (NTDLL.@)
|
|---|
| 242 | */
|
|---|
| 243 | LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim )
|
|---|
| 244 | {
|
|---|
| 245 | static LPWSTR next = NULL;
|
|---|
| 246 | LPWSTR ret;
|
|---|
| 247 |
|
|---|
| 248 | if (!str)
|
|---|
| 249 | if (!(str = next)) return NULL;
|
|---|
| 250 |
|
|---|
| 251 | while (*str && NTDLL_wcschr( delim, *str )) str++;
|
|---|
| 252 | if (!*str) return NULL;
|
|---|
| 253 | ret = str++;
|
|---|
| 254 | while (*str && !NTDLL_wcschr( delim, *str )) str++;
|
|---|
| 255 | if (*str) *str++ = 0;
|
|---|
| 256 | next = str;
|
|---|
| 257 | return ret;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | /*********************************************************************
|
|---|
| 262 | * wcstombs (NTDLL.@)
|
|---|
| 263 | */
|
|---|
| 264 | INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
|
|---|
| 265 | {
|
|---|
| 266 | DWORD len;
|
|---|
| 267 |
|
|---|
| 268 | if (!dst)
|
|---|
| 269 | {
|
|---|
| 270 | RtlUnicodeToMultiByteSize( &len, src, strlenW(src)*sizeof(WCHAR) );
|
|---|
| 271 | return len;
|
|---|
| 272 | }
|
|---|
| 273 | else
|
|---|
| 274 | {
|
|---|
| 275 | if (n <= 0) return 0;
|
|---|
| 276 | RtlUnicodeToMultiByteN( dst, n, &len, src, strlenW(src)*sizeof(WCHAR) );
|
|---|
| 277 | if (len < n) dst[len] = 0;
|
|---|
| 278 | }
|
|---|
| 279 | return len;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 | /*********************************************************************
|
|---|
| 284 | * mbstowcs (NTDLL.@)
|
|---|
| 285 | */
|
|---|
| 286 | INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
|
|---|
| 287 | {
|
|---|
| 288 | DWORD len;
|
|---|
| 289 |
|
|---|
| 290 | if (!dst)
|
|---|
| 291 | {
|
|---|
| 292 | RtlMultiByteToUnicodeSize( &len, src, strlen(src) );
|
|---|
| 293 | }
|
|---|
| 294 | else
|
|---|
| 295 | {
|
|---|
| 296 | if (n <= 0) return 0;
|
|---|
| 297 | RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) );
|
|---|
| 298 | if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0;
|
|---|
| 299 | }
|
|---|
| 300 | return len / sizeof(WCHAR);
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 | /*********************************************************************
|
|---|
| 305 | * wcstol (NTDLL.@)
|
|---|
| 306 | * Like strtol, but for wide character strings.
|
|---|
| 307 | */
|
|---|
| 308 | INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base)
|
|---|
| 309 | {
|
|---|
| 310 | UNICODE_STRING uni;
|
|---|
| 311 | ANSI_STRING ansi;
|
|---|
| 312 | INT ret;
|
|---|
| 313 | LPSTR endA;
|
|---|
| 314 |
|
|---|
| 315 | RtlInitUnicodeString( &uni, s );
|
|---|
| 316 | RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE );
|
|---|
| 317 | ret = strtol( ansi.Buffer, &endA, base );
|
|---|
| 318 | if (end)
|
|---|
| 319 | {
|
|---|
| 320 | DWORD len;
|
|---|
| 321 | RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer );
|
|---|
| 322 | *end = (LPWSTR)s + len/sizeof(WCHAR);
|
|---|
| 323 | }
|
|---|
| 324 | RtlFreeAnsiString( &ansi );
|
|---|
| 325 | return ret;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 | /*********************************************************************
|
|---|
| 330 | * wcstoul (NTDLL.@)
|
|---|
| 331 | * Like strtoul, but for wide character strings.
|
|---|
| 332 | */
|
|---|
| 333 | INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base)
|
|---|
| 334 | {
|
|---|
| 335 | UNICODE_STRING uni;
|
|---|
| 336 | ANSI_STRING ansi;
|
|---|
| 337 | INT ret;
|
|---|
| 338 | LPSTR endA;
|
|---|
| 339 |
|
|---|
| 340 | RtlInitUnicodeString( &uni, s );
|
|---|
| 341 | RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE );
|
|---|
| 342 | ret = strtoul( ansi.Buffer, &endA, base );
|
|---|
| 343 | if (end)
|
|---|
| 344 | {
|
|---|
| 345 | DWORD len;
|
|---|
| 346 | RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer );
|
|---|
| 347 | *end = (LPWSTR)s + len/sizeof(WCHAR);
|
|---|
| 348 | }
|
|---|
| 349 | RtlFreeAnsiString( &ansi );
|
|---|
| 350 | return ret;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 | /*********************************************************************
|
|---|
| 355 | * iswctype (NTDLL.@)
|
|---|
| 356 | */
|
|---|
| 357 | INT __cdecl NTDLL_iswctype( WCHAR wc, WCHAR wct )
|
|---|
| 358 | {
|
|---|
| 359 | return (get_char_typeW(wc) & 0xfff) & wct;
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 | /*********************************************************************
|
|---|
| 364 | * iswalpha (NTDLL.@)
|
|---|
| 365 | */
|
|---|
| 366 | INT __cdecl NTDLL_iswalpha( WCHAR wc )
|
|---|
| 367 | {
|
|---|
| 368 | return get_char_typeW(wc) & C1_ALPHA;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 | /*********************************************************************
|
|---|
| 373 | * _ultow (NTDLL.@)
|
|---|
| 374 | * Like _ultoa, but for wide character strings.
|
|---|
| 375 | */
|
|---|
| 376 | LPWSTR __cdecl _ultow(ULONG value, LPWSTR string, INT radix)
|
|---|
| 377 | {
|
|---|
| 378 | WCHAR tmp[33];
|
|---|
| 379 | LPWSTR tp = tmp;
|
|---|
| 380 | LPWSTR sp;
|
|---|
| 381 | LONG i;
|
|---|
| 382 | ULONG v = value;
|
|---|
| 383 |
|
|---|
| 384 | if (radix > 36 || radix <= 1)
|
|---|
| 385 | return 0;
|
|---|
| 386 |
|
|---|
| 387 | while (v || tp == tmp)
|
|---|
| 388 | {
|
|---|
| 389 | i = v % radix;
|
|---|
| 390 | v = v / radix;
|
|---|
| 391 | if (i < 10)
|
|---|
| 392 | *tp++ = i + '0';
|
|---|
| 393 | else
|
|---|
| 394 | *tp++ = i + 'a' - 10;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | sp = string;
|
|---|
| 398 | while (tp > tmp)
|
|---|
| 399 | *sp++ = *--tp;
|
|---|
| 400 | *sp = 0;
|
|---|
| 401 | return string;
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | /*********************************************************************
|
|---|
| 405 | * _wtol (NTDLL.@)
|
|---|
| 406 | * Like atol, but for wide character strings.
|
|---|
| 407 | */
|
|---|
| 408 | LONG __cdecl _wtol(LPWSTR string)
|
|---|
| 409 | {
|
|---|
| 410 | char buffer[30];
|
|---|
| 411 | NTDLL_wcstombs( buffer, string, sizeof(buffer) );
|
|---|
| 412 | return atol( buffer );
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | /*********************************************************************
|
|---|
| 416 | * _wtoi (NTDLL.@)
|
|---|
| 417 | */
|
|---|
| 418 | INT __cdecl _wtoi(LPWSTR string)
|
|---|
| 419 | {
|
|---|
| 420 | return _wtol(string);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | /* INTERNAL: Wide char snprintf
|
|---|
| 424 | * If you fix a bug in this function, fix it in msvcrt/wcs.c also!
|
|---|
| 425 | */
|
|---|
| 426 | static int __cdecl NTDLL_vsnwprintf(WCHAR *str, unsigned int len,
|
|---|
| 427 | const WCHAR *format, va_list valist)
|
|---|
| 428 | {
|
|---|
| 429 | unsigned int written = 0;
|
|---|
| 430 | const WCHAR *iter = format;
|
|---|
| 431 | char bufa[256], fmtbufa[64], *fmta;
|
|---|
| 432 |
|
|---|
| 433 | TRACE("(%d,%s)\n",len,debugstr_w(format));
|
|---|
| 434 |
|
|---|
| 435 | while (*iter)
|
|---|
| 436 | {
|
|---|
| 437 | while (*iter && *iter != (WCHAR)L'%')
|
|---|
| 438 | {
|
|---|
| 439 | if (written++ >= len)
|
|---|
| 440 | return -1;
|
|---|
| 441 | *str++ = *iter++;
|
|---|
| 442 | }
|
|---|
| 443 | if (*iter == (WCHAR)L'%')
|
|---|
| 444 | {
|
|---|
| 445 | fmta = fmtbufa;
|
|---|
| 446 | *fmta++ = *iter++;
|
|---|
| 447 | while (*iter == (WCHAR)L'0' ||
|
|---|
| 448 | *iter == (WCHAR)L'+' ||
|
|---|
| 449 | *iter == (WCHAR)L'-' ||
|
|---|
| 450 | *iter == (WCHAR)L' ' ||
|
|---|
| 451 | *iter == (WCHAR)L'0' ||
|
|---|
| 452 | *iter == (WCHAR)L'*' ||
|
|---|
| 453 | *iter == (WCHAR)L'#')
|
|---|
| 454 | {
|
|---|
| 455 | if (*iter == (WCHAR)L'*')
|
|---|
| 456 | {
|
|---|
| 457 | char *buffiter = bufa;
|
|---|
| 458 | int fieldlen = va_arg(valist, int);
|
|---|
| 459 | sprintf(buffiter, "%d", fieldlen);
|
|---|
| 460 | while (*buffiter)
|
|---|
| 461 | *fmta++ = *buffiter++;
|
|---|
| 462 | }
|
|---|
| 463 | else
|
|---|
| 464 | *fmta++ = *iter;
|
|---|
| 465 | iter++;
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | while (isdigit(*iter))
|
|---|
| 469 | *fmta++ = *iter++;
|
|---|
| 470 |
|
|---|
| 471 | if (*iter == (WCHAR)L'.')
|
|---|
| 472 | {
|
|---|
| 473 | *fmta++ = *iter++;
|
|---|
| 474 | if (*iter == (WCHAR)L'*')
|
|---|
| 475 | {
|
|---|
| 476 | char *buffiter = bufa;
|
|---|
| 477 | int fieldlen = va_arg(valist, int);
|
|---|
| 478 | sprintf(buffiter, "%d", fieldlen);
|
|---|
| 479 | while (*buffiter)
|
|---|
| 480 | *fmta++ = *buffiter++;
|
|---|
| 481 | }
|
|---|
| 482 | else
|
|---|
| 483 | while (isdigit(*iter))
|
|---|
| 484 | *fmta++ = *iter++;
|
|---|
| 485 | }
|
|---|
| 486 | if (*iter == (WCHAR)L'h' ||
|
|---|
| 487 | *iter == (WCHAR)L'l')
|
|---|
| 488 | {
|
|---|
| 489 | *fmta++ = *iter++;
|
|---|
| 490 | *fmta++ = *iter++;
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| 493 | switch (*iter)
|
|---|
| 494 | {
|
|---|
| 495 | case (WCHAR)L's':
|
|---|
| 496 | {
|
|---|
| 497 | static const WCHAR none[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
|
|---|
| 498 | const WCHAR *wstr = va_arg(valist, const WCHAR *);
|
|---|
| 499 | const WCHAR *striter = wstr ? wstr : none;
|
|---|
| 500 | while (*striter)
|
|---|
| 501 | {
|
|---|
| 502 | if (written++ >= len)
|
|---|
| 503 | return -1;
|
|---|
| 504 | *str++ = *striter++;
|
|---|
| 505 | }
|
|---|
| 506 | iter++;
|
|---|
| 507 | break;
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | case (WCHAR)L'c':
|
|---|
| 511 | if (written++ >= len)
|
|---|
| 512 | return -1;
|
|---|
| 513 | *str++ = (WCHAR)va_arg(valist, int);
|
|---|
| 514 | iter++;
|
|---|
| 515 | break;
|
|---|
| 516 |
|
|---|
| 517 | default:
|
|---|
| 518 | {
|
|---|
| 519 | /* For non wc types, use system sprintf and append to wide char output */
|
|---|
| 520 | /* FIXME: for unrecognised types, should ignore % when printing */
|
|---|
| 521 | char *bufaiter = bufa;
|
|---|
| 522 | if (*iter == (WCHAR)L'p')
|
|---|
| 523 | sprintf(bufaiter, "%08lX", va_arg(valist, long));
|
|---|
| 524 | else
|
|---|
| 525 | {
|
|---|
| 526 | *fmta++ = *iter;
|
|---|
| 527 | *fmta = '\0';
|
|---|
| 528 | if (*iter == (WCHAR)L'f')
|
|---|
| 529 | sprintf(bufaiter, fmtbufa, va_arg(valist, double));
|
|---|
| 530 | else
|
|---|
| 531 | sprintf(bufaiter, fmtbufa, va_arg(valist, void *));
|
|---|
| 532 | }
|
|---|
| 533 | while (*bufaiter)
|
|---|
| 534 | {
|
|---|
| 535 | if (written++ >= len)
|
|---|
| 536 | return -1;
|
|---|
| 537 | *str++ = *bufaiter++;
|
|---|
| 538 | }
|
|---|
| 539 | iter++;
|
|---|
| 540 | break;
|
|---|
| 541 | }
|
|---|
| 542 | }
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 | if (written >= len)
|
|---|
| 546 | return -1;
|
|---|
| 547 | *str++ = (WCHAR)L'\0';
|
|---|
| 548 | return (int)written;
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 | /***********************************************************************
|
|---|
| 553 | * _snwprintf (NTDLL.@)
|
|---|
| 554 | */
|
|---|
| 555 | int __cdecl _snwprintf(WCHAR *str, unsigned int len, const WCHAR *format, ...)
|
|---|
| 556 | {
|
|---|
| 557 | int retval;
|
|---|
| 558 | va_list valist;
|
|---|
| 559 | va_start(valist, format);
|
|---|
| 560 | retval = NTDLL_vsnwprintf(str, len, format, valist);
|
|---|
| 561 | va_end(valist);
|
|---|
| 562 | return retval;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 | /***********************************************************************
|
|---|
| 567 | * swprintf (NTDLL.@)
|
|---|
| 568 | */
|
|---|
| 569 | int __cdecl NTDLL_swprintf(WCHAR *str, const WCHAR *format, ...)
|
|---|
| 570 | {
|
|---|
| 571 | int retval;
|
|---|
| 572 | va_list valist;
|
|---|
| 573 | va_start(valist, format);
|
|---|
| 574 | retval = NTDLL_vsnwprintf(str, INT_MAX, format, valist);
|
|---|
| 575 | va_end(valist);
|
|---|
| 576 | return retval;
|
|---|
| 577 | }
|
|---|