[5574] | 1 | /*
|
---|
| 2 | * Rtl string functions
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 1996-1998 Marcus Meissner
|
---|
| 5 | * Copyright (C) 2000 Alexandre Julliard
|
---|
[8429] | 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
|
---|
[5574] | 20 | */
|
---|
| 21 |
|
---|
| 22 | #include "config.h"
|
---|
| 23 |
|
---|
[8429] | 24 | #include <assert.h>
|
---|
[5574] | 25 | #include <stdlib.h>
|
---|
| 26 | #include <string.h>
|
---|
| 27 | #include <ctype.h>
|
---|
[8429] | 28 |
|
---|
| 29 | #include "ntddk.h"
|
---|
[5574] | 30 | #include "wine/unicode.h"
|
---|
[8429] | 31 | #include "wine/debug.h"
|
---|
[9986] | 32 | #include "winnt.h"
|
---|
[5574] | 33 |
|
---|
[8429] | 34 | WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
---|
[5574] | 35 |
|
---|
[8690] | 36 | #ifdef __WIN32OS2__
|
---|
| 37 | #define RtlAllocateHeap HeapAlloc
|
---|
| 38 | #define RtlFreeHeap HeapFree
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
[9684] | 41 |
|
---|
[8429] | 42 | UINT NlsAnsiCodePage = 1252;
|
---|
| 43 | BYTE NlsMbCodePageTag = 0;
|
---|
| 44 | BYTE NlsMbOemCodePageTag = 0;
|
---|
[5574] | 45 |
|
---|
[8429] | 46 | static const union cptable *ansi_table;
|
---|
| 47 | static const union cptable *oem_table;
|
---|
| 48 |
|
---|
| 49 | inline static const union cptable *get_ansi_table(void)
|
---|
| 50 | {
|
---|
| 51 | if (!ansi_table) ansi_table = cp_get_table( 1252 );
|
---|
| 52 | return ansi_table;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | inline static const union cptable *get_oem_table(void)
|
---|
| 56 | {
|
---|
| 57 | if (!oem_table) oem_table = cp_get_table( 437 );
|
---|
| 58 | return oem_table;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
[5574] | 62 | /**************************************************************************
|
---|
[8429] | 63 | * __wine_init_codepages (NTDLL.@)
|
---|
| 64 | *
|
---|
| 65 | * Set the code page once kernel32 is loaded. Should be done differently.
|
---|
| 66 | */
|
---|
| 67 | void __wine_init_codepages( const union cptable *ansi, const union cptable *oem )
|
---|
| 68 | {
|
---|
| 69 | ansi_table = ansi;
|
---|
| 70 | oem_table = oem;
|
---|
| 71 | NlsAnsiCodePage = ansi->info.codepage;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | /**************************************************************************
|
---|
[6712] | 76 | * RtlInitAnsiString (NTDLL.@)
|
---|
[5574] | 77 | */
|
---|
| 78 | void WINAPI RtlInitAnsiString( PSTRING target, LPCSTR source)
|
---|
| 79 | {
|
---|
| 80 | if ((target->Buffer = (LPSTR)source))
|
---|
| 81 | {
|
---|
| 82 | target->Length = strlen(source);
|
---|
| 83 | target->MaximumLength = target->Length + 1;
|
---|
| 84 | }
|
---|
| 85 | else target->Length = target->MaximumLength = 0;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | /**************************************************************************
|
---|
[6712] | 90 | * RtlInitString (NTDLL.@)
|
---|
[5574] | 91 | */
|
---|
| 92 | void WINAPI RtlInitString( PSTRING target, LPCSTR source )
|
---|
| 93 | {
|
---|
[8429] | 94 | return RtlInitAnsiString( target, source );
|
---|
[5574] | 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | /**************************************************************************
|
---|
[6712] | 99 | * RtlFreeAnsiString (NTDLL.@)
|
---|
[5574] | 100 | */
|
---|
| 101 | void WINAPI RtlFreeAnsiString( PSTRING str )
|
---|
| 102 | {
|
---|
[8429] | 103 | if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
|
---|
[5574] | 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | /**************************************************************************
|
---|
[6712] | 108 | * RtlFreeOemString (NTDLL.@)
|
---|
[5574] | 109 | */
|
---|
| 110 | void WINAPI RtlFreeOemString( PSTRING str )
|
---|
| 111 | {
|
---|
| 112 | RtlFreeAnsiString( str );
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | /**************************************************************************
|
---|
[6712] | 117 | * RtlCopyString (NTDLL.@)
|
---|
[5574] | 118 | */
|
---|
| 119 | void WINAPI RtlCopyString( STRING *dst, const STRING *src )
|
---|
| 120 | {
|
---|
| 121 | if (src)
|
---|
| 122 | {
|
---|
| 123 | unsigned int len = min( src->Length, dst->MaximumLength );
|
---|
| 124 | memcpy( dst->Buffer, src->Buffer, len );
|
---|
| 125 | dst->Length = len;
|
---|
| 126 | }
|
---|
| 127 | else dst->Length = 0;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | /**************************************************************************
|
---|
[6712] | 132 | * RtlInitUnicodeString (NTDLL.@)
|
---|
[5574] | 133 | */
|
---|
| 134 | void WINAPI RtlInitUnicodeString( PUNICODE_STRING target, LPCWSTR source )
|
---|
| 135 | {
|
---|
| 136 | if ((target->Buffer = (LPWSTR)source))
|
---|
| 137 | {
|
---|
| 138 | target->Length = strlenW(source) * sizeof(WCHAR);
|
---|
| 139 | target->MaximumLength = target->Length + sizeof(WCHAR);
|
---|
| 140 | }
|
---|
| 141 | else target->Length = target->MaximumLength = 0;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | /**************************************************************************
|
---|
[6712] | 146 | * RtlCreateUnicodeString (NTDLL.@)
|
---|
[5574] | 147 | */
|
---|
| 148 | BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
|
---|
| 149 | {
|
---|
| 150 | int len = (strlenW(src) + 1) * sizeof(WCHAR);
|
---|
[8429] | 151 | if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
|
---|
[5574] | 152 | memcpy( target->Buffer, src, len );
|
---|
| 153 | target->MaximumLength = len;
|
---|
[9986] | 154 | target->Length = len - sizeof(WCHAR);
|
---|
[5574] | 155 | return TRUE;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | /**************************************************************************
|
---|
[6712] | 160 | * RtlCreateUnicodeStringFromAsciiz (NTDLL.@)
|
---|
[5574] | 161 | */
|
---|
| 162 | BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR src )
|
---|
| 163 | {
|
---|
| 164 | STRING ansi;
|
---|
| 165 | RtlInitAnsiString( &ansi, src );
|
---|
| 166 | return !RtlAnsiStringToUnicodeString( target, &ansi, TRUE );
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | /**************************************************************************
|
---|
[6712] | 171 | * RtlFreeUnicodeString (NTDLL.@)
|
---|
[5574] | 172 | */
|
---|
| 173 | void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
|
---|
| 174 | {
|
---|
[8429] | 175 | if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
|
---|
[5574] | 176 | }
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | /**************************************************************************
|
---|
[6712] | 180 | * RtlCopyUnicodeString (NTDLL.@)
|
---|
[5574] | 181 | */
|
---|
| 182 | void WINAPI RtlCopyUnicodeString( UNICODE_STRING *dst, const UNICODE_STRING *src )
|
---|
| 183 | {
|
---|
| 184 | if (src)
|
---|
| 185 | {
|
---|
| 186 | unsigned int len = min( src->Length, dst->MaximumLength );
|
---|
| 187 | memcpy( dst->Buffer, src->Buffer, len );
|
---|
| 188 | dst->Length = len;
|
---|
| 189 | /* append terminating NULL if enough space */
|
---|
| 190 | if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
|
---|
| 191 | }
|
---|
| 192 | else dst->Length = 0;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | /**************************************************************************
|
---|
[6712] | 197 | * RtlEraseUnicodeString (NTDLL.@)
|
---|
[5574] | 198 | */
|
---|
| 199 | void WINAPI RtlEraseUnicodeString( UNICODE_STRING *str )
|
---|
| 200 | {
|
---|
| 201 | if (str->Buffer)
|
---|
| 202 | {
|
---|
| 203 | memset( str->Buffer, 0, str->MaximumLength );
|
---|
| 204 | str->Length = 0;
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | /*
|
---|
| 209 | COMPARISON FUNCTIONS
|
---|
| 210 | */
|
---|
| 211 |
|
---|
| 212 | /******************************************************************************
|
---|
[6712] | 213 | * RtlCompareString (NTDLL.@)
|
---|
[5574] | 214 | */
|
---|
| 215 | LONG WINAPI RtlCompareString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
|
---|
| 216 | {
|
---|
| 217 | unsigned int len;
|
---|
| 218 | LONG ret = 0;
|
---|
| 219 | LPCSTR p1, p2;
|
---|
| 220 |
|
---|
| 221 | len = min(s1->Length, s2->Length);
|
---|
| 222 | p1 = s1->Buffer;
|
---|
| 223 | p2 = s2->Buffer;
|
---|
| 224 |
|
---|
| 225 | if (CaseInsensitive)
|
---|
| 226 | {
|
---|
| 227 | while (!ret && len--) ret = toupper(*p1++) - toupper(*p2++);
|
---|
| 228 | }
|
---|
| 229 | else
|
---|
| 230 | {
|
---|
| 231 | while (!ret && len--) ret = *p1++ - *p2++;
|
---|
| 232 | }
|
---|
| 233 | if (!ret) ret = s1->Length - s2->Length;
|
---|
| 234 | return ret;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | /******************************************************************************
|
---|
[6712] | 239 | * RtlCompareUnicodeString (NTDLL.@)
|
---|
[5574] | 240 | */
|
---|
| 241 | LONG WINAPI RtlCompareUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
|
---|
| 242 | BOOLEAN CaseInsensitive )
|
---|
| 243 | {
|
---|
| 244 | unsigned int len;
|
---|
| 245 | LONG ret = 0;
|
---|
| 246 | LPCWSTR p1, p2;
|
---|
| 247 |
|
---|
| 248 | len = min(s1->Length, s2->Length) / sizeof(WCHAR);
|
---|
| 249 | p1 = s1->Buffer;
|
---|
| 250 | p2 = s2->Buffer;
|
---|
| 251 |
|
---|
| 252 | if (CaseInsensitive)
|
---|
| 253 | {
|
---|
| 254 | while (!ret && len--) ret = toupperW(*p1++) - toupperW(*p2++);
|
---|
| 255 | }
|
---|
| 256 | else
|
---|
| 257 | {
|
---|
| 258 | while (!ret && len--) ret = *p1++ - *p2++;
|
---|
| 259 | }
|
---|
| 260 | if (!ret) ret = s1->Length - s2->Length;
|
---|
| 261 | return ret;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | /**************************************************************************
|
---|
[6712] | 266 | * RtlEqualString (NTDLL.@)
|
---|
[5574] | 267 | */
|
---|
| 268 | BOOLEAN WINAPI RtlEqualString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
|
---|
| 269 | {
|
---|
| 270 | if (s1->Length != s2->Length) return FALSE;
|
---|
| 271 | return !RtlCompareString( s1, s2, CaseInsensitive );
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 | /**************************************************************************
|
---|
[6712] | 276 | * RtlEqualUnicodeString (NTDLL.@)
|
---|
[5574] | 277 | */
|
---|
| 278 | BOOLEAN WINAPI RtlEqualUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
|
---|
| 279 | BOOLEAN CaseInsensitive )
|
---|
| 280 | {
|
---|
| 281 | if (s1->Length != s2->Length) return FALSE;
|
---|
| 282 | return !RtlCompareUnicodeString( s1, s2, CaseInsensitive );
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 | /**************************************************************************
|
---|
[6712] | 287 | * RtlPrefixString (NTDLL.@)
|
---|
[5574] | 288 | *
|
---|
| 289 | * Test if s1 is a prefix in s2
|
---|
| 290 | */
|
---|
| 291 | BOOLEAN WINAPI RtlPrefixString( const STRING *s1, const STRING *s2, BOOLEAN ignore_case )
|
---|
| 292 | {
|
---|
| 293 | unsigned int i;
|
---|
| 294 |
|
---|
| 295 | if (s1->Length > s2->Length) return FALSE;
|
---|
| 296 | if (ignore_case)
|
---|
| 297 | {
|
---|
| 298 | for (i = 0; i < s1->Length; i++)
|
---|
| 299 | if (toupper(s1->Buffer[i]) != toupper(s2->Buffer[i])) return FALSE;
|
---|
| 300 | }
|
---|
| 301 | else
|
---|
| 302 | {
|
---|
| 303 | for (i = 0; i < s1->Length; i++)
|
---|
| 304 | if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
|
---|
| 305 | }
|
---|
| 306 | return TRUE;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | /**************************************************************************
|
---|
[6712] | 311 | * RtlPrefixUnicodeString (NTDLL.@)
|
---|
[5574] | 312 | *
|
---|
| 313 | * Test if s1 is a prefix in s2
|
---|
| 314 | */
|
---|
| 315 | BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1,
|
---|
| 316 | const UNICODE_STRING *s2,
|
---|
| 317 | BOOLEAN ignore_case )
|
---|
| 318 | {
|
---|
| 319 | unsigned int i;
|
---|
| 320 |
|
---|
| 321 | if (s1->Length > s2->Length) return FALSE;
|
---|
| 322 | if (ignore_case)
|
---|
| 323 | {
|
---|
| 324 | for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
|
---|
| 325 | if (toupper(s1->Buffer[i]) != toupper(s2->Buffer[i])) return FALSE;
|
---|
| 326 | }
|
---|
| 327 | else
|
---|
| 328 | {
|
---|
| 329 | for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
|
---|
| 330 | if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
|
---|
| 331 | }
|
---|
| 332 | return TRUE;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[9986] | 335 | /**************************************************************************
|
---|
| 336 | * RtlEqualComputerName (NTDLL.@)
|
---|
| 337 | *
|
---|
| 338 | * Determine if two computer names are the same.
|
---|
| 339 | *
|
---|
| 340 | * PARAMS
|
---|
| 341 | * left [I] First computer name
|
---|
| 342 | * right [I] Second computer name
|
---|
| 343 | *
|
---|
| 344 | * RETURNS
|
---|
| 345 | * 0 if the names are equal, non-zero otherwise.
|
---|
| 346 | *
|
---|
| 347 | * NOTES
|
---|
| 348 | * The comparason is case insensitive.
|
---|
| 349 | */
|
---|
| 350 | NTSTATUS WINAPI RtlEqualComputerName(const UNICODE_STRING *left,
|
---|
| 351 | const UNICODE_STRING *right)
|
---|
| 352 | {
|
---|
| 353 | NTSTATUS ret;
|
---|
| 354 | STRING upLeft, upRight;
|
---|
[5574] | 355 |
|
---|
[9986] | 356 | if (!(ret = RtlUpcaseUnicodeStringToOemString( &upLeft, left, TRUE )))
|
---|
| 357 | {
|
---|
| 358 | if (!(ret = RtlUpcaseUnicodeStringToOemString( &upRight, right, TRUE )))
|
---|
| 359 | {
|
---|
| 360 | ret = RtlEqualString( &upLeft, &upRight, FALSE );
|
---|
| 361 | RtlFreeOemString( &upRight );
|
---|
| 362 | }
|
---|
| 363 | RtlFreeOemString( &upLeft );
|
---|
| 364 | }
|
---|
| 365 | return ret;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /**************************************************************************
|
---|
| 369 | * RtlEqualDomainName (NTDLL.@)
|
---|
| 370 | *
|
---|
| 371 | * Determine if two domain names are the same.
|
---|
| 372 | *
|
---|
| 373 | * PARAMS
|
---|
| 374 | * left [I] First domain name
|
---|
| 375 | * right [I] Second domain name
|
---|
| 376 | *
|
---|
| 377 | * RETURNS
|
---|
| 378 | * 0 if the names are equal, non-zero otherwise.
|
---|
| 379 | *
|
---|
| 380 | * NOTES
|
---|
| 381 | * The comparason is case insensitive.
|
---|
| 382 | */
|
---|
| 383 | NTSTATUS WINAPI RtlEqualDomainName(const UNICODE_STRING *left,
|
---|
| 384 | const UNICODE_STRING *right)
|
---|
| 385 | {
|
---|
| 386 | return RtlEqualComputerName(left, right);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 |
|
---|
[5574] | 390 | /*
|
---|
[6712] | 391 | COPY BETWEEN ANSI_STRING or UNICODE_STRING
|
---|
| 392 | there is no parameter checking, it just crashes
|
---|
[5574] | 393 | */
|
---|
| 394 |
|
---|
| 395 |
|
---|
| 396 | /**************************************************************************
|
---|
[6712] | 397 | * RtlAnsiStringToUnicodeString (NTDLL.@)
|
---|
[5574] | 398 | *
|
---|
| 399 | * NOTES:
|
---|
| 400 | * writes terminating 0
|
---|
| 401 | */
|
---|
| 402 | NTSTATUS WINAPI RtlAnsiStringToUnicodeString( UNICODE_STRING *uni,
|
---|
| 403 | const STRING *ansi,
|
---|
| 404 | BOOLEAN doalloc )
|
---|
| 405 | {
|
---|
[8429] | 406 | DWORD total = RtlAnsiStringToUnicodeSize( ansi );
|
---|
[5574] | 407 |
|
---|
| 408 | if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
|
---|
[8429] | 409 | uni->Length = total - sizeof(WCHAR);
|
---|
[5574] | 410 | if (doalloc)
|
---|
| 411 | {
|
---|
| 412 | uni->MaximumLength = total;
|
---|
[8429] | 413 | if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 414 | }
|
---|
| 415 | else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
---|
| 416 |
|
---|
[8429] | 417 | RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
|
---|
| 418 | uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
|
---|
[5574] | 419 | return STATUS_SUCCESS;
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 |
|
---|
| 423 | /**************************************************************************
|
---|
[6712] | 424 | * RtlOemStringToUnicodeString (NTDLL.@)
|
---|
[5574] | 425 | *
|
---|
| 426 | * NOTES
|
---|
| 427 | * writes terminating 0
|
---|
| 428 | * if resulting length > 0xffff it returns STATUS_INVALID_PARAMETER_2
|
---|
| 429 | */
|
---|
| 430 | NTSTATUS WINAPI RtlOemStringToUnicodeString( UNICODE_STRING *uni,
|
---|
| 431 | const STRING *oem,
|
---|
| 432 | BOOLEAN doalloc )
|
---|
| 433 | {
|
---|
[8429] | 434 | DWORD total = RtlOemStringToUnicodeSize( oem );
|
---|
[5574] | 435 |
|
---|
| 436 | if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
|
---|
[8429] | 437 | uni->Length = total - sizeof(WCHAR);
|
---|
[5574] | 438 | if (doalloc)
|
---|
| 439 | {
|
---|
| 440 | uni->MaximumLength = total;
|
---|
[8429] | 441 | if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 442 | }
|
---|
| 443 | else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
---|
| 444 |
|
---|
[8429] | 445 | RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
|
---|
| 446 | uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
|
---|
[5574] | 447 | return STATUS_SUCCESS;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 |
|
---|
| 451 | /**************************************************************************
|
---|
[6712] | 452 | * RtlUnicodeStringToAnsiString (NTDLL.@)
|
---|
[5574] | 453 | *
|
---|
| 454 | * NOTES
|
---|
| 455 | * writes terminating 0
|
---|
| 456 | * copies a part if the buffer is too small
|
---|
| 457 | */
|
---|
| 458 | NTSTATUS WINAPI RtlUnicodeStringToAnsiString( STRING *ansi,
|
---|
| 459 | const UNICODE_STRING *uni,
|
---|
| 460 | BOOLEAN doalloc )
|
---|
| 461 | {
|
---|
| 462 | NTSTATUS ret = STATUS_SUCCESS;
|
---|
| 463 | DWORD len = RtlUnicodeStringToAnsiSize( uni );
|
---|
| 464 |
|
---|
[8429] | 465 | ansi->Length = len - 1;
|
---|
[5574] | 466 | if (doalloc)
|
---|
| 467 | {
|
---|
[8429] | 468 | ansi->MaximumLength = len;
|
---|
| 469 | if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 470 | }
|
---|
[8429] | 471 | else if (ansi->MaximumLength < len)
|
---|
[5574] | 472 | {
|
---|
| 473 | if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
---|
| 474 | ansi->Length = ansi->MaximumLength - 1;
|
---|
| 475 | ret = STATUS_BUFFER_OVERFLOW;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
[8429] | 478 | RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
|
---|
[5574] | 479 | ansi->Buffer[ansi->Length] = 0;
|
---|
| 480 | return ret;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 |
|
---|
| 484 | /**************************************************************************
|
---|
[6712] | 485 | * RtlUnicodeStringToOemString (NTDLL.@)
|
---|
[5574] | 486 | *
|
---|
| 487 | * NOTES
|
---|
| 488 | * allocates uni->Length+1
|
---|
| 489 | * writes terminating 0
|
---|
| 490 | */
|
---|
| 491 | NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
|
---|
| 492 | const UNICODE_STRING *uni,
|
---|
| 493 | BOOLEAN doalloc )
|
---|
| 494 | {
|
---|
| 495 | NTSTATUS ret = STATUS_SUCCESS;
|
---|
| 496 | DWORD len = RtlUnicodeStringToOemSize( uni );
|
---|
| 497 |
|
---|
[8429] | 498 | oem->Length = len - 1;
|
---|
[5574] | 499 | if (doalloc)
|
---|
| 500 | {
|
---|
[8429] | 501 | oem->MaximumLength = len;
|
---|
| 502 | if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 503 | }
|
---|
[8429] | 504 | else if (oem->MaximumLength < len)
|
---|
[5574] | 505 | {
|
---|
| 506 | if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
---|
| 507 | oem->Length = oem->MaximumLength - 1;
|
---|
| 508 | ret = STATUS_BUFFER_OVERFLOW;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
[8429] | 511 | RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
|
---|
[5574] | 512 | oem->Buffer[oem->Length] = 0;
|
---|
| 513 | return ret;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 |
|
---|
| 517 | /**************************************************************************
|
---|
[6712] | 518 | * RtlMultiByteToUnicodeN (NTDLL.@)
|
---|
[5574] | 519 | *
|
---|
| 520 | * NOTES
|
---|
| 521 | * if unistr is too small a part is copied
|
---|
| 522 | */
|
---|
| 523 | NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 524 | LPCSTR src, DWORD srclen )
|
---|
| 525 | {
|
---|
[8429] | 526 |
|
---|
| 527 | int ret = cp_mbstowcs( get_ansi_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
|
---|
[5574] | 528 | if (reslen)
|
---|
[8429] | 529 | *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
|
---|
[5574] | 530 | return STATUS_SUCCESS;
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 |
|
---|
| 534 | /**************************************************************************
|
---|
[6712] | 535 | * RtlOemToUnicodeN (NTDLL.@)
|
---|
[5574] | 536 | */
|
---|
| 537 | NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 538 | LPCSTR src, DWORD srclen )
|
---|
| 539 | {
|
---|
[8429] | 540 | int ret = cp_mbstowcs( get_oem_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
|
---|
[5574] | 541 | if (reslen)
|
---|
[8429] | 542 | *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
|
---|
[5574] | 543 | return STATUS_SUCCESS;
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 |
|
---|
| 547 | /**************************************************************************
|
---|
[6712] | 548 | * RtlUnicodeToMultiByteN (NTDLL.@)
|
---|
[5574] | 549 | */
|
---|
| 550 | NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 551 | LPCWSTR src, DWORD srclen )
|
---|
| 552 | {
|
---|
[8429] | 553 | int ret = cp_wcstombs( get_ansi_table(), 0, src, srclen / sizeof(WCHAR),
|
---|
| 554 | dst, dstlen, NULL, NULL );
|
---|
[5574] | 555 | if (reslen)
|
---|
[8429] | 556 | *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
|
---|
[5574] | 557 | return STATUS_SUCCESS;
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 |
|
---|
| 561 | /**************************************************************************
|
---|
[6712] | 562 | * RtlUnicodeToOemN (NTDLL.@)
|
---|
[5574] | 563 | */
|
---|
| 564 | NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 565 | LPCWSTR src, DWORD srclen )
|
---|
| 566 | {
|
---|
[8429] | 567 | int ret = cp_wcstombs( get_oem_table(), 0, src, srclen / sizeof(WCHAR),
|
---|
| 568 | dst, dstlen, NULL, NULL );
|
---|
[5574] | 569 | if (reslen)
|
---|
[8429] | 570 | *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
|
---|
[5574] | 571 | return STATUS_SUCCESS;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 |
|
---|
| 575 | /*
|
---|
| 576 | CASE CONVERSIONS
|
---|
| 577 | */
|
---|
| 578 |
|
---|
| 579 | /**************************************************************************
|
---|
[9986] | 580 | * RtlUpperChar (NTDLL.@)
|
---|
| 581 | *
|
---|
| 582 | * Converts an Ascii character to uppercase.
|
---|
| 583 | *
|
---|
| 584 | * PARAMS
|
---|
| 585 | * ch [I] Character to convert
|
---|
| 586 | *
|
---|
| 587 | * RETURNS
|
---|
| 588 | * The uppercase character value.
|
---|
| 589 | *
|
---|
| 590 | * NOTES
|
---|
| 591 | * For the input characters from 'a' .. 'z' it returns 'A' .. 'Z'.
|
---|
| 592 | * All other input characters are returned unchanged. The locale and
|
---|
| 593 | * multibyte characters are not taken into account (as native DLL).
|
---|
| 594 | */
|
---|
| 595 | CHAR WINAPI RtlUpperChar( CHAR ch )
|
---|
| 596 | {
|
---|
| 597 | if (ch >= 'a' && ch <= 'z') {
|
---|
| 598 | return ch - 'a' + 'A';
|
---|
| 599 | } else {
|
---|
| 600 | return ch;
|
---|
| 601 | } /* if */
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | /**************************************************************************
|
---|
[6712] | 605 | * RtlUpperString (NTDLL.@)
|
---|
[9986] | 606 | *
|
---|
| 607 | * Converts an Ascii string to uppercase.
|
---|
| 608 | *
|
---|
| 609 | * PARAMS
|
---|
| 610 | * dst [O] Destination for converted string
|
---|
| 611 | * src [I] Source string to convert
|
---|
| 612 | *
|
---|
| 613 | * RETURNS
|
---|
| 614 | * Nothing.
|
---|
| 615 | *
|
---|
| 616 | * NOTES
|
---|
| 617 | * For the src characters from 'a' .. 'z' it assigns 'A' .. 'Z' to dst.
|
---|
| 618 | * All other src characters are copied unchanged to dst. The locale and
|
---|
| 619 | * multibyte characters are not taken into account (as native DLL).
|
---|
| 620 | * The number of character copied is the minimum of src->Length and
|
---|
| 621 | * the dst->MaximumLength.
|
---|
[5574] | 622 | */
|
---|
| 623 | void WINAPI RtlUpperString( STRING *dst, const STRING *src )
|
---|
| 624 | {
|
---|
| 625 | unsigned int i, len = min(src->Length, dst->MaximumLength);
|
---|
| 626 |
|
---|
[9986] | 627 | for (i = 0; i < len; i++) dst->Buffer[i] = RtlUpperChar(src->Buffer[i]);
|
---|
[5574] | 628 | dst->Length = len;
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 |
|
---|
| 632 | /**************************************************************************
|
---|
[9986] | 633 | * RtlUpcaseUnicodeChar (NTDLL.@)
|
---|
| 634 | *
|
---|
| 635 | * Converts an Unicode character to uppercase.
|
---|
| 636 | *
|
---|
| 637 | * PARAMS
|
---|
| 638 | * wch [I] Character to convert
|
---|
| 639 | *
|
---|
| 640 | * RETURNS
|
---|
| 641 | * The uppercase character value.
|
---|
| 642 | */
|
---|
| 643 | WCHAR WINAPI RtlUpcaseUnicodeChar( WCHAR wch )
|
---|
| 644 | {
|
---|
| 645 | return toupperW(wch);
|
---|
| 646 | }
|
---|
| 647 |
|
---|
| 648 | /**************************************************************************
|
---|
| 649 | * RtlDowncaseUnicodeChar (NTDLL.@)
|
---|
| 650 | *
|
---|
| 651 | * Converts an Unicode character to lowercase.
|
---|
| 652 | *
|
---|
| 653 | * PARAMS
|
---|
| 654 | * wch [I] Character to convert
|
---|
| 655 | *
|
---|
| 656 | * RETURNS
|
---|
| 657 | * The lowercase character value.
|
---|
| 658 | */
|
---|
| 659 | WCHAR WINAPI RtlDowncaseUnicodeChar(WCHAR wch)
|
---|
| 660 | {
|
---|
| 661 | return tolowerW(wch);
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | /**************************************************************************
|
---|
[6712] | 665 | * RtlUpcaseUnicodeString (NTDLL.@)
|
---|
[5574] | 666 | *
|
---|
| 667 | * NOTES:
|
---|
| 668 | * destination string is never 0-terminated because dest can be equal to src
|
---|
| 669 | * and src might be not 0-terminated
|
---|
| 670 | * dest.Length only set when success
|
---|
| 671 | */
|
---|
| 672 | NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
|
---|
| 673 | const UNICODE_STRING *src,
|
---|
| 674 | BOOLEAN doalloc )
|
---|
| 675 | {
|
---|
| 676 | DWORD i, len = src->Length;
|
---|
| 677 |
|
---|
| 678 | if (doalloc)
|
---|
| 679 | {
|
---|
| 680 | dest->MaximumLength = len;
|
---|
[8429] | 681 | if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 682 | }
|
---|
| 683 | else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
---|
| 684 |
|
---|
| 685 | for (i = 0; i < len/sizeof(WCHAR); i++) dest->Buffer[i] = toupperW(src->Buffer[i]);
|
---|
| 686 | dest->Length = len;
|
---|
| 687 | return STATUS_SUCCESS;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 |
|
---|
| 691 | /**************************************************************************
|
---|
[9986] | 692 | * RtlDowncaseUnicodeString (NTDLL.@)
|
---|
| 693 | *
|
---|
| 694 | * Converts an Unicode string to lowercase.
|
---|
| 695 | *
|
---|
| 696 | * PARAMS
|
---|
| 697 | * dest [O] Destination for converted string
|
---|
| 698 | * src [I] Source string to convert
|
---|
| 699 | * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
|
---|
| 700 | *
|
---|
| 701 | * RETURNS
|
---|
| 702 | * Success: STATUS_SUCCESS. dest contains the converted string.
|
---|
| 703 | * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
|
---|
| 704 | * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
|
---|
| 705 | *
|
---|
| 706 | * NOTES
|
---|
| 707 | * dest is never NUL terminated because it may be equal to src, and src
|
---|
| 708 | * might not be NUL terminated. dest->Length is only set upon success.
|
---|
| 709 | */
|
---|
| 710 | NTSTATUS WINAPI RtlDowncaseUnicodeString(
|
---|
| 711 | UNICODE_STRING *dest,
|
---|
| 712 | const UNICODE_STRING *src,
|
---|
| 713 | BOOLEAN doalloc)
|
---|
| 714 | {
|
---|
| 715 | DWORD i;
|
---|
| 716 | DWORD len = src->Length;
|
---|
| 717 |
|
---|
| 718 | if (doalloc) {
|
---|
| 719 | dest->MaximumLength = len;
|
---|
| 720 | if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) {
|
---|
| 721 | return STATUS_NO_MEMORY;
|
---|
| 722 | } /* if */
|
---|
| 723 | } else if (len > dest->MaximumLength) {
|
---|
| 724 | return STATUS_BUFFER_OVERFLOW;
|
---|
| 725 | } /* if */
|
---|
| 726 |
|
---|
| 727 | for (i = 0; i < len/sizeof(WCHAR); i++) {
|
---|
| 728 | dest->Buffer[i] = tolowerW(src->Buffer[i]);
|
---|
| 729 | } /* for */
|
---|
| 730 | dest->Length = len;
|
---|
| 731 | return STATUS_SUCCESS;
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | /**************************************************************************
|
---|
[6712] | 735 | * RtlUpcaseUnicodeStringToAnsiString (NTDLL.@)
|
---|
[5574] | 736 | *
|
---|
| 737 | * NOTES
|
---|
| 738 | * writes terminating 0
|
---|
| 739 | */
|
---|
| 740 | NTSTATUS WINAPI RtlUpcaseUnicodeStringToAnsiString( STRING *dst,
|
---|
| 741 | const UNICODE_STRING *src,
|
---|
| 742 | BOOLEAN doalloc )
|
---|
| 743 | {
|
---|
| 744 | NTSTATUS ret;
|
---|
| 745 | UNICODE_STRING upcase;
|
---|
| 746 |
|
---|
| 747 | if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
|
---|
| 748 | {
|
---|
| 749 | ret = RtlUnicodeStringToAnsiString( dst, &upcase, doalloc );
|
---|
| 750 | RtlFreeUnicodeString( &upcase );
|
---|
| 751 | }
|
---|
| 752 | return ret;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | /**************************************************************************
|
---|
[6712] | 757 | * RtlUpcaseUnicodeStringToOemString (NTDLL.@)
|
---|
[5574] | 758 | *
|
---|
| 759 | * NOTES
|
---|
| 760 | * writes terminating 0
|
---|
| 761 | */
|
---|
| 762 | NTSTATUS WINAPI RtlUpcaseUnicodeStringToOemString( STRING *dst,
|
---|
| 763 | const UNICODE_STRING *src,
|
---|
| 764 | BOOLEAN doalloc )
|
---|
| 765 | {
|
---|
| 766 | NTSTATUS ret;
|
---|
| 767 | UNICODE_STRING upcase;
|
---|
| 768 |
|
---|
| 769 | if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
|
---|
| 770 | {
|
---|
| 771 | ret = RtlUnicodeStringToOemString( dst, &upcase, doalloc );
|
---|
| 772 | RtlFreeUnicodeString( &upcase );
|
---|
| 773 | }
|
---|
| 774 | return ret;
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 |
|
---|
| 778 | /**************************************************************************
|
---|
[6712] | 779 | * RtlUpcaseUnicodeToMultiByteN (NTDLL.@)
|
---|
[5574] | 780 | */
|
---|
| 781 | NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 782 | LPCWSTR src, DWORD srclen )
|
---|
| 783 | {
|
---|
| 784 | NTSTATUS ret;
|
---|
| 785 | LPWSTR upcase;
|
---|
| 786 | DWORD i;
|
---|
| 787 |
|
---|
[8429] | 788 | if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 789 | for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
|
---|
| 790 | ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
|
---|
[8429] | 791 | RtlFreeHeap( GetProcessHeap(), 0, upcase );
|
---|
[5574] | 792 | return ret;
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 |
|
---|
| 796 | /**************************************************************************
|
---|
[6712] | 797 | * RtlUpcaseUnicodeToOemN (NTDLL.@)
|
---|
[5574] | 798 | */
|
---|
| 799 | NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
|
---|
| 800 | LPCWSTR src, DWORD srclen )
|
---|
| 801 | {
|
---|
| 802 | NTSTATUS ret;
|
---|
| 803 | LPWSTR upcase;
|
---|
| 804 | DWORD i;
|
---|
| 805 |
|
---|
[8429] | 806 | if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
|
---|
[5574] | 807 | for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
|
---|
| 808 | ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
|
---|
[8429] | 809 | RtlFreeHeap( GetProcessHeap(), 0, upcase );
|
---|
[5574] | 810 | return ret;
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 |
|
---|
| 814 | /*
|
---|
[6712] | 815 | STRING SIZE
|
---|
[5574] | 816 | */
|
---|
| 817 |
|
---|
| 818 | /**************************************************************************
|
---|
| 819 | * RtlOemStringToUnicodeSize (NTDLL.@)
|
---|
[8429] | 820 | * RtlxOemStringToUnicodeSize (NTDLL.@)
|
---|
[5574] | 821 | *
|
---|
| 822 | * Return the size in bytes necessary for the Unicode conversion of 'str',
|
---|
| 823 | * including the terminating NULL.
|
---|
| 824 | */
|
---|
[7983] | 825 | UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
|
---|
[5574] | 826 | {
|
---|
[8429] | 827 | int ret = cp_mbstowcs( get_oem_table(), 0, str->Buffer, str->Length, NULL, 0 );
|
---|
[5574] | 828 | return (ret + 1) * sizeof(WCHAR);
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 |
|
---|
| 832 | /**************************************************************************
|
---|
| 833 | * RtlAnsiStringToUnicodeSize (NTDLL.@)
|
---|
[8429] | 834 | * RtlxAnsiStringToUnicodeSize (NTDLL.@)
|
---|
[5574] | 835 | *
|
---|
| 836 | * Return the size in bytes necessary for the Unicode conversion of 'str',
|
---|
| 837 | * including the terminating NULL.
|
---|
| 838 | */
|
---|
[7983] | 839 | DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
|
---|
[5574] | 840 | {
|
---|
[8429] | 841 | DWORD ret;
|
---|
| 842 | RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
|
---|
| 843 | return ret + sizeof(WCHAR);
|
---|
[5574] | 844 | }
|
---|
| 845 |
|
---|
| 846 |
|
---|
| 847 | /**************************************************************************
|
---|
| 848 | * RtlMultiByteToUnicodeSize (NTDLL.@)
|
---|
| 849 | *
|
---|
| 850 | * Compute the size in bytes necessary for the Unicode conversion of 'str',
|
---|
| 851 | * without the terminating NULL.
|
---|
| 852 | */
|
---|
| 853 | NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
|
---|
| 854 | {
|
---|
[8429] | 855 | *size = cp_mbstowcs( get_ansi_table(), 0, str, len, NULL, 0 ) * sizeof(WCHAR);
|
---|
| 856 | return STATUS_SUCCESS;
|
---|
[5574] | 857 | }
|
---|
| 858 |
|
---|
| 859 |
|
---|
| 860 | /**************************************************************************
|
---|
| 861 | * RtlUnicodeToMultiByteSize (NTDLL.@)
|
---|
| 862 | *
|
---|
| 863 | * Compute the size necessary for the multibyte conversion of 'str',
|
---|
| 864 | * without the terminating NULL.
|
---|
| 865 | */
|
---|
| 866 | NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len )
|
---|
| 867 | {
|
---|
[8429] | 868 | *size = cp_wcstombs( get_ansi_table(), 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
|
---|
| 869 | return STATUS_SUCCESS;
|
---|
[5574] | 870 | }
|
---|
| 871 |
|
---|
| 872 |
|
---|
| 873 | /**************************************************************************
|
---|
| 874 | * RtlUnicodeStringToAnsiSize (NTDLL.@)
|
---|
[8429] | 875 | * RtlxUnicodeStringToAnsiSize (NTDLL.@)
|
---|
[5574] | 876 | *
|
---|
| 877 | * Return the size in bytes necessary for the Ansi conversion of 'str',
|
---|
| 878 | * including the terminating NULL.
|
---|
| 879 | */
|
---|
| 880 | DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
|
---|
| 881 | {
|
---|
[8429] | 882 | DWORD ret;
|
---|
| 883 | RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
|
---|
| 884 | return ret + 1;
|
---|
[5574] | 885 | }
|
---|
| 886 |
|
---|
| 887 |
|
---|
| 888 | /**************************************************************************
|
---|
| 889 | * RtlUnicodeStringToOemSize (NTDLL.@)
|
---|
[8429] | 890 | * RtlxUnicodeStringToOemSize (NTDLL.@)
|
---|
[5574] | 891 | *
|
---|
| 892 | * Return the size in bytes necessary for the OEM conversion of 'str',
|
---|
| 893 | * including the terminating NULL.
|
---|
| 894 | */
|
---|
| 895 | DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
|
---|
| 896 | {
|
---|
[8429] | 897 | return cp_wcstombs( get_oem_table(), 0, str->Buffer, str->Length / sizeof(WCHAR),
|
---|
| 898 | NULL, 0, NULL, NULL ) + 1;
|
---|
[5574] | 899 | }
|
---|
| 900 |
|
---|
| 901 |
|
---|
| 902 | /**************************************************************************
|
---|
| 903 | * RtlAppendStringToString (NTDLL.@)
|
---|
| 904 | */
|
---|
| 905 | NTSTATUS WINAPI RtlAppendStringToString( STRING *dst, const STRING *src )
|
---|
| 906 | {
|
---|
| 907 | unsigned int len = src->Length + dst->Length;
|
---|
| 908 | if (len > dst->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
|
---|
| 909 | memcpy( dst->Buffer + dst->Length, src->Buffer, src->Length );
|
---|
| 910 | dst->Length = len;
|
---|
| 911 | return STATUS_SUCCESS;
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 |
|
---|
| 915 | /**************************************************************************
|
---|
| 916 | * RtlAppendAsciizToString (NTDLL.@)
|
---|
| 917 | */
|
---|
| 918 | NTSTATUS WINAPI RtlAppendAsciizToString( STRING *dst, LPCSTR src )
|
---|
| 919 | {
|
---|
| 920 | if (src)
|
---|
| 921 | {
|
---|
| 922 | unsigned int srclen = strlen(src);
|
---|
| 923 | unsigned int total = srclen + dst->Length;
|
---|
| 924 | if (total > dst->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
|
---|
| 925 | memcpy( dst->Buffer + dst->Length, src, srclen );
|
---|
| 926 | dst->Length = total;
|
---|
| 927 | }
|
---|
| 928 | return STATUS_SUCCESS;
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 |
|
---|
| 932 | /**************************************************************************
|
---|
| 933 | * RtlAppendUnicodeToString (NTDLL.@)
|
---|
| 934 | */
|
---|
| 935 | NTSTATUS WINAPI RtlAppendUnicodeToString( UNICODE_STRING *dst, LPCWSTR src )
|
---|
| 936 | {
|
---|
| 937 | if (src)
|
---|
| 938 | {
|
---|
| 939 | unsigned int srclen = strlenW(src) * sizeof(WCHAR);
|
---|
| 940 | unsigned int total = srclen + dst->Length;
|
---|
| 941 | if (total > dst->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
|
---|
| 942 | memcpy( dst->Buffer + dst->Length/sizeof(WCHAR), src, srclen );
|
---|
| 943 | dst->Length = total;
|
---|
| 944 | /* append terminating NULL if enough space */
|
---|
| 945 | if (total < dst->MaximumLength) dst->Buffer[total / sizeof(WCHAR)] = 0;
|
---|
| 946 | }
|
---|
| 947 | return STATUS_SUCCESS;
|
---|
| 948 | }
|
---|
| 949 |
|
---|
| 950 |
|
---|
| 951 | /**************************************************************************
|
---|
| 952 | * RtlAppendUnicodeStringToString (NTDLL.@)
|
---|
| 953 | */
|
---|
| 954 | NTSTATUS WINAPI RtlAppendUnicodeStringToString( UNICODE_STRING *dst, const UNICODE_STRING *src )
|
---|
| 955 | {
|
---|
| 956 | unsigned int len = src->Length + dst->Length;
|
---|
[9986] | 957 | if (src->Length == 0) return STATUS_SUCCESS;
|
---|
[5574] | 958 | if (len > dst->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
|
---|
| 959 | memcpy( dst->Buffer + dst->Length/sizeof(WCHAR), src->Buffer, src->Length );
|
---|
| 960 | dst->Length = len;
|
---|
| 961 | /* append terminating NULL if enough space */
|
---|
| 962 | if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
|
---|
| 963 | return STATUS_SUCCESS;
|
---|
| 964 | }
|
---|
| 965 |
|
---|
| 966 |
|
---|
| 967 | /*
|
---|
[6712] | 968 | MISC
|
---|
[5574] | 969 | */
|
---|
| 970 |
|
---|
| 971 | /**************************************************************************
|
---|
[8429] | 972 | * RtlIsTextUnicode (NTDLL.@)
|
---|
[5574] | 973 | *
|
---|
[6712] | 974 | * Apply various feeble heuristics to guess whether
|
---|
| 975 | * the text buffer contains Unicode.
|
---|
| 976 | * FIXME: should implement more tests.
|
---|
[5574] | 977 | */
|
---|
| 978 | DWORD WINAPI RtlIsTextUnicode(
|
---|
[6712] | 979 | LPVOID buf,
|
---|
| 980 | DWORD len,
|
---|
| 981 | DWORD *pf)
|
---|
[5574] | 982 | {
|
---|
[6712] | 983 | LPWSTR s = buf;
|
---|
| 984 | DWORD flags = -1, out_flags = 0;
|
---|
[5574] | 985 |
|
---|
[6712] | 986 | if (!len)
|
---|
| 987 | goto out;
|
---|
| 988 | if (pf)
|
---|
| 989 | flags = *pf;
|
---|
| 990 | /*
|
---|
| 991 | * Apply various tests to the text string. According to the
|
---|
| 992 | * docs, each test "passed" sets the corresponding flag in
|
---|
| 993 | * the output flags. But some of the tests are mutually
|
---|
| 994 | * exclusive, so I don't see how you could pass all tests ...
|
---|
| 995 | */
|
---|
[5574] | 996 |
|
---|
[6712] | 997 | /* Check for an odd length ... pass if even. */
|
---|
| 998 | if (!(len & 1))
|
---|
| 999 | out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
|
---|
[5574] | 1000 |
|
---|
[6712] | 1001 | /* Check for the special unicode marker byte. */
|
---|
| 1002 | if (*s == 0xFEFF)
|
---|
| 1003 | out_flags |= IS_TEXT_UNICODE_SIGNATURE;
|
---|
[5574] | 1004 |
|
---|
[6712] | 1005 | /*
|
---|
| 1006 | * Check whether the string passed all of the tests.
|
---|
| 1007 | */
|
---|
| 1008 | flags &= ITU_IMPLEMENTED_TESTS;
|
---|
| 1009 | if ((out_flags & flags) != flags)
|
---|
| 1010 | len = 0;
|
---|
[5574] | 1011 | out:
|
---|
[6712] | 1012 | if (pf)
|
---|
| 1013 | *pf = out_flags;
|
---|
| 1014 | return len;
|
---|
[5574] | 1015 | }
|
---|
[9684] | 1016 |
|
---|
| 1017 | /**************************************************************************
|
---|
[9986] | 1018 | * RtlCharToInteger (NTDLL.@)
|
---|
[9684] | 1019 | *
|
---|
[9986] | 1020 | * Converts a character string into its integer equivalent.
|
---|
| 1021 | *
|
---|
| 1022 | * RETURNS
|
---|
| 1023 | * Success: STATUS_SUCCESS. value contains the converted number
|
---|
| 1024 | * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
|
---|
| 1025 | * STATUS_ACCESS_VIOLATION, if value is NULL.
|
---|
| 1026 | *
|
---|
| 1027 | * NOTES
|
---|
| 1028 | * For base 0 it uses 10 as base and the string should be in the format
|
---|
| 1029 | * "{whitespace} [+|-] [0[x|o|b]] {digits}".
|
---|
| 1030 | * For other bases the string should be in the format
|
---|
| 1031 | * "{whitespace} [+|-] {digits}".
|
---|
| 1032 | * No check is made for value overflow, only the lower 32 bits are assigned.
|
---|
| 1033 | * If str is NULL it crashes, as the native function does.
|
---|
| 1034 | *
|
---|
| 1035 | * DIFFERENCES
|
---|
| 1036 | * This function does not read garbage behind '\0' as the native version does.
|
---|
[9684] | 1037 | */
|
---|
[9986] | 1038 | NTSTATUS WINAPI RtlCharToInteger(
|
---|
| 1039 | PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
|
---|
| 1040 | ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
---|
| 1041 | ULONG *value) /* [O] Destination for the converted value */
|
---|
| 1042 | {
|
---|
| 1043 | CHAR chCurrent;
|
---|
| 1044 | int digit;
|
---|
| 1045 | ULONG RunningTotal = 0;
|
---|
| 1046 | char bMinus = 0;
|
---|
| 1047 |
|
---|
| 1048 | while (*str != '\0' && *str <= ' ') {
|
---|
| 1049 | str++;
|
---|
| 1050 | } /* while */
|
---|
| 1051 |
|
---|
| 1052 | if (*str == '+') {
|
---|
| 1053 | str++;
|
---|
| 1054 | } else if (*str == '-') {
|
---|
| 1055 | bMinus = 1;
|
---|
| 1056 | str++;
|
---|
| 1057 | } /* if */
|
---|
| 1058 |
|
---|
| 1059 | if (base == 0) {
|
---|
| 1060 | base = 10;
|
---|
| 1061 | if (str[0] == '0') {
|
---|
| 1062 | if (str[1] == 'b') {
|
---|
| 1063 | str += 2;
|
---|
| 1064 | base = 2;
|
---|
| 1065 | } else if (str[1] == 'o') {
|
---|
| 1066 | str += 2;
|
---|
| 1067 | base = 8;
|
---|
| 1068 | } else if (str[1] == 'x') {
|
---|
| 1069 | str += 2;
|
---|
| 1070 | base = 16;
|
---|
| 1071 | } /* if */
|
---|
| 1072 | } /* if */
|
---|
| 1073 | } else if (base != 2 && base != 8 && base != 10 && base != 16) {
|
---|
| 1074 | return STATUS_INVALID_PARAMETER;
|
---|
| 1075 | } /* if */
|
---|
| 1076 |
|
---|
| 1077 | if (value == NULL) {
|
---|
| 1078 | return STATUS_ACCESS_VIOLATION;
|
---|
| 1079 | } /* if */
|
---|
| 1080 |
|
---|
| 1081 | while (*str != '\0') {
|
---|
| 1082 | chCurrent = *str;
|
---|
| 1083 | if (chCurrent >= '0' && chCurrent <= '9') {
|
---|
| 1084 | digit = chCurrent - '0';
|
---|
| 1085 | } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
|
---|
| 1086 | digit = chCurrent - 'A' + 10;
|
---|
| 1087 | } else if (chCurrent >= 'a' && chCurrent <= 'z') {
|
---|
| 1088 | digit = chCurrent - 'a' + 10;
|
---|
| 1089 | } else {
|
---|
| 1090 | digit = -1;
|
---|
| 1091 | } /* if */
|
---|
| 1092 | if (digit < 0 || digit >= base) {
|
---|
| 1093 | *value = bMinus ? -RunningTotal : RunningTotal;
|
---|
| 1094 | return STATUS_SUCCESS;
|
---|
| 1095 | } /* if */
|
---|
| 1096 |
|
---|
| 1097 | RunningTotal = RunningTotal * base + digit;
|
---|
| 1098 | str++;
|
---|
| 1099 | } /* while */
|
---|
| 1100 |
|
---|
| 1101 | *value = bMinus ? -RunningTotal : RunningTotal;
|
---|
| 1102 | return STATUS_SUCCESS;
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
| 1105 | /**************************************************************************
|
---|
| 1106 | * RtlIntegerToChar (NTDLL.@)
|
---|
| 1107 | *
|
---|
| 1108 | * Converts an unsigned integer to a character string.
|
---|
| 1109 | *
|
---|
| 1110 | * RETURNS
|
---|
| 1111 | * Success: STATUS_SUCCESS. str contains the converted number
|
---|
| 1112 | * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
|
---|
| 1113 | * STATUS_BUFFER_OVERFLOW, if str would be larger than length.
|
---|
| 1114 | * STATUS_ACCESS_VIOLATION, if str is NULL.
|
---|
| 1115 | *
|
---|
| 1116 | * NOTES
|
---|
| 1117 | * Instead of base 0 it uses 10 as base.
|
---|
| 1118 | * Writes at most length characters to the string str.
|
---|
| 1119 | * Str is '\0' terminated when length allowes it.
|
---|
| 1120 | * When str fits exactly in length characters the '\0' is ommitted.
|
---|
| 1121 | */
|
---|
| 1122 | NTSTATUS WINAPI RtlIntegerToChar(
|
---|
| 1123 | ULONG value, /* [I] Value to be converted */
|
---|
| 1124 | ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
---|
| 1125 | ULONG length, /* [I] Length of the str buffer in bytes */
|
---|
| 1126 | PCHAR str) /* [O] Destination for the converted value */
|
---|
| 1127 | {
|
---|
| 1128 | CHAR buffer[33];
|
---|
| 1129 | PCHAR pos;
|
---|
| 1130 | CHAR digit;
|
---|
| 1131 | ULONG len;
|
---|
| 1132 |
|
---|
| 1133 | if (base == 0) {
|
---|
| 1134 | base = 10;
|
---|
| 1135 | } else if (base != 2 && base != 8 && base != 10 && base != 16) {
|
---|
| 1136 | return STATUS_INVALID_PARAMETER;
|
---|
| 1137 | } /* if */
|
---|
| 1138 |
|
---|
| 1139 | pos = &buffer[32];
|
---|
| 1140 | *pos = '\0';
|
---|
| 1141 |
|
---|
| 1142 | do {
|
---|
| 1143 | pos--;
|
---|
| 1144 | digit = value % base;
|
---|
| 1145 | value = value / base;
|
---|
| 1146 | if (digit < 10) {
|
---|
| 1147 | *pos = '0' + digit;
|
---|
| 1148 | } else {
|
---|
| 1149 | *pos = 'A' + digit - 10;
|
---|
| 1150 | } /* if */
|
---|
| 1151 | } while (value != 0L);
|
---|
| 1152 |
|
---|
| 1153 | len = &buffer[32] - pos;
|
---|
| 1154 | if (len > length) {
|
---|
| 1155 | return STATUS_BUFFER_OVERFLOW;
|
---|
| 1156 | } else if (str == NULL) {
|
---|
| 1157 | return STATUS_ACCESS_VIOLATION;
|
---|
| 1158 | } else if (len == length) {
|
---|
| 1159 | memcpy(str, pos, len);
|
---|
| 1160 | } else {
|
---|
| 1161 | memcpy(str, pos, len + 1);
|
---|
| 1162 | } /* if */
|
---|
| 1163 | return STATUS_SUCCESS;
|
---|
| 1164 | }
|
---|
| 1165 |
|
---|
| 1166 | /**************************************************************************
|
---|
| 1167 | * RtlUnicodeStringToInteger (NTDLL.@)
|
---|
| 1168 | *
|
---|
| 1169 | * Converts an unicode string into its integer equivalent.
|
---|
| 1170 | *
|
---|
| 1171 | * RETURNS
|
---|
| 1172 | * Success: STATUS_SUCCESS. value contains the converted number
|
---|
| 1173 | * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
|
---|
| 1174 | * STATUS_ACCESS_VIOLATION, if value is NULL.
|
---|
| 1175 | *
|
---|
| 1176 | * NOTES
|
---|
| 1177 | * For base 0 it uses 10 as base and the string should be in the format
|
---|
| 1178 | * "{whitespace} [+|-] [0[x|o|b]] {digits}".
|
---|
| 1179 | * For other bases the string should be in the format
|
---|
| 1180 | * "{whitespace} [+|-] {digits}".
|
---|
| 1181 | * No check is made for value overflow, only the lower 32 bits are assigned.
|
---|
| 1182 | * If str is NULL it crashes, as the native function does.
|
---|
| 1183 | *
|
---|
| 1184 | * DIFFERENCES
|
---|
| 1185 | * This function does not read garbage on string length 0 as the native
|
---|
| 1186 | * version does.
|
---|
| 1187 | */
|
---|
[9684] | 1188 | NTSTATUS WINAPI RtlUnicodeStringToInteger(
|
---|
[9986] | 1189 | const UNICODE_STRING *str, /* [I] Unicode string to be converted */
|
---|
| 1190 | ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
---|
| 1191 | ULONG *value) /* [O] Destination for the converted value */
|
---|
[9684] | 1192 | {
|
---|
[9986] | 1193 | LPWSTR lpwstr = str->Buffer;
|
---|
| 1194 | USHORT CharsRemaining = str->Length / sizeof(WCHAR);
|
---|
| 1195 | WCHAR wchCurrent;
|
---|
| 1196 | int digit;
|
---|
| 1197 | ULONG RunningTotal = 0;
|
---|
| 1198 | char bMinus = 0;
|
---|
[9684] | 1199 |
|
---|
[9986] | 1200 | while (CharsRemaining >= 1 && *lpwstr <= ' ') {
|
---|
| 1201 | lpwstr++;
|
---|
| 1202 | CharsRemaining--;
|
---|
| 1203 | } /* while */
|
---|
[9684] | 1204 |
|
---|
[9986] | 1205 | if (CharsRemaining >= 1) {
|
---|
| 1206 | if (*lpwstr == '+') {
|
---|
| 1207 | lpwstr++;
|
---|
| 1208 | CharsRemaining--;
|
---|
| 1209 | } else if (*lpwstr == '-') {
|
---|
| 1210 | bMinus = 1;
|
---|
| 1211 | lpwstr++;
|
---|
| 1212 | CharsRemaining--;
|
---|
| 1213 | } /* if */
|
---|
| 1214 | } /* if */
|
---|
[9684] | 1215 |
|
---|
[9986] | 1216 | if (base == 0) {
|
---|
| 1217 | base = 10;
|
---|
| 1218 | if (CharsRemaining >= 2 && lpwstr[0] == '0') {
|
---|
| 1219 | if (lpwstr[1] == 'b') {
|
---|
| 1220 | lpwstr += 2;
|
---|
| 1221 | CharsRemaining -= 2;
|
---|
| 1222 | base = 2;
|
---|
| 1223 | } else if (lpwstr[1] == 'o') {
|
---|
| 1224 | lpwstr += 2;
|
---|
| 1225 | CharsRemaining -= 2;
|
---|
| 1226 | base = 8;
|
---|
| 1227 | } else if (lpwstr[1] == 'x') {
|
---|
| 1228 | lpwstr += 2;
|
---|
| 1229 | CharsRemaining -= 2;
|
---|
[9684] | 1230 | base = 16;
|
---|
[9986] | 1231 | } /* if */
|
---|
| 1232 | } /* if */
|
---|
| 1233 | } else if (base != 2 && base != 8 && base != 10 && base != 16) {
|
---|
| 1234 | return STATUS_INVALID_PARAMETER;
|
---|
| 1235 | } /* if */
|
---|
[9684] | 1236 |
|
---|
[9986] | 1237 | if (value == NULL) {
|
---|
| 1238 | return STATUS_ACCESS_VIOLATION;
|
---|
| 1239 | } /* if */
|
---|
[9684] | 1240 |
|
---|
[9986] | 1241 | while (CharsRemaining >= 1) {
|
---|
| 1242 | wchCurrent = *lpwstr;
|
---|
| 1243 | if (wchCurrent >= '0' && wchCurrent <= '9') {
|
---|
| 1244 | digit = wchCurrent - '0';
|
---|
| 1245 | } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
|
---|
| 1246 | digit = wchCurrent - 'A' + 10;
|
---|
| 1247 | } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
|
---|
| 1248 | digit = wchCurrent - 'a' + 10;
|
---|
| 1249 | } else {
|
---|
| 1250 | digit = -1;
|
---|
| 1251 | } /* if */
|
---|
| 1252 | if (digit < 0 || digit >= base) {
|
---|
| 1253 | *value = bMinus ? -RunningTotal : RunningTotal;
|
---|
| 1254 | return STATUS_SUCCESS;
|
---|
| 1255 | } /* if */
|
---|
[9684] | 1256 |
|
---|
[9986] | 1257 | RunningTotal = RunningTotal * base + digit;
|
---|
| 1258 | lpwstr++;
|
---|
| 1259 | CharsRemaining--;
|
---|
| 1260 | } /* while */
|
---|
[9684] | 1261 |
|
---|
[9986] | 1262 | *value = bMinus ? -RunningTotal : RunningTotal;
|
---|
| 1263 | return STATUS_SUCCESS;
|
---|
[9684] | 1264 | }
|
---|
[9986] | 1265 |
|
---|
| 1266 | /**************************************************************************
|
---|
| 1267 | * RtlIntegerToUnicodeString (NTDLL.@)
|
---|
| 1268 | *
|
---|
| 1269 | * Converts an unsigned integer to a '\0' terminated unicode string.
|
---|
| 1270 | *
|
---|
| 1271 | * RETURNS
|
---|
| 1272 | * Success: STATUS_SUCCESS. str contains the converted number
|
---|
| 1273 | * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
|
---|
| 1274 | * STATUS_BUFFER_OVERFLOW, if str is too small to hold the string
|
---|
| 1275 | * (with the '\0' termination). In this case str->Length
|
---|
| 1276 | * is set to the length, the string would have (which can
|
---|
| 1277 | * be larger than the MaximumLength).
|
---|
| 1278 | *
|
---|
| 1279 | * NOTES
|
---|
| 1280 | * Instead of base 0 it uses 10 as base.
|
---|
| 1281 | * If str is NULL it crashes, as the native function does.
|
---|
| 1282 | *
|
---|
| 1283 | * DIFFERENCES
|
---|
| 1284 | * Do not return STATUS_BUFFER_OVERFLOW when the string is long enough.
|
---|
| 1285 | * The native function does this when the string would be longer than 16
|
---|
| 1286 | * characters even when the string parameter is long enough.
|
---|
| 1287 | */
|
---|
| 1288 | NTSTATUS WINAPI RtlIntegerToUnicodeString(
|
---|
| 1289 | ULONG value, /* [I] Value to be converted */
|
---|
| 1290 | ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
---|
| 1291 | UNICODE_STRING *str) /* [O] Destination for the converted value */
|
---|
| 1292 | {
|
---|
| 1293 | WCHAR buffer[33];
|
---|
| 1294 | PWCHAR pos;
|
---|
| 1295 | WCHAR digit;
|
---|
| 1296 |
|
---|
| 1297 | if (base == 0) {
|
---|
| 1298 | base = 10;
|
---|
| 1299 | } else if (base != 2 && base != 8 && base != 10 && base != 16) {
|
---|
| 1300 | return STATUS_INVALID_PARAMETER;
|
---|
| 1301 | } /* if */
|
---|
| 1302 |
|
---|
| 1303 | pos = &buffer[32];
|
---|
| 1304 | *pos = '\0';
|
---|
| 1305 |
|
---|
| 1306 | do {
|
---|
| 1307 | pos--;
|
---|
| 1308 | digit = value % base;
|
---|
| 1309 | value = value / base;
|
---|
| 1310 | if (digit < 10) {
|
---|
| 1311 | *pos = '0' + digit;
|
---|
| 1312 | } else {
|
---|
| 1313 | *pos = 'A' + digit - 10;
|
---|
| 1314 | } /* if */
|
---|
| 1315 | } while (value != 0L);
|
---|
| 1316 |
|
---|
| 1317 | str->Length = (&buffer[32] - pos) * sizeof(WCHAR);
|
---|
| 1318 | if (str->Length >= str->MaximumLength) {
|
---|
| 1319 | return STATUS_BUFFER_OVERFLOW;
|
---|
| 1320 | } else {
|
---|
| 1321 | memcpy(str->Buffer, pos, str->Length + sizeof(WCHAR));
|
---|
| 1322 | } /* if */
|
---|
| 1323 | return STATUS_SUCCESS;
|
---|
| 1324 | }
|
---|