| 1 | /* $Id: rtlstr.cpp,v 1.8 1999-08-22 22:45:53 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 5 | * Win32 NT Runtime / NTDLL for OS/2
|
|---|
| 6 | * Rtl string functions
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright 1996-1998 Marcus Meissner
|
|---|
| 9 | * Copyright 1998, 1999 Patrick Haller (phaller@gmx.net)
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #include "config.h"
|
|---|
| 13 |
|
|---|
| 14 | #include <stdlib.h>
|
|---|
| 15 | #include <string.h>
|
|---|
| 16 | #include <ctype.h>
|
|---|
| 17 |
|
|---|
| 18 | #include <os2win.h>
|
|---|
| 19 | #include <unicode.h>
|
|---|
| 20 |
|
|---|
| 21 | #include "ntdll.h"
|
|---|
| 22 | #include "windef.h"
|
|---|
| 23 |
|
|---|
| 24 | #define HAVE_WCTYPE_H
|
|---|
| 25 | #ifdef HAVE_WCTYPE_H
|
|---|
| 26 | # include <wctype.h>
|
|---|
| 27 | #endif
|
|---|
| 28 | #include "wine/winestring.h"
|
|---|
| 29 | #include "winnls.h"
|
|---|
| 30 | //#include <heapstring.h>
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | /*
|
|---|
| 34 | * STRING FUNCTIONS
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | /**************************************************************************
|
|---|
| 38 | * RtlAnsiStringToUnicodeString [NTDLL.269]
|
|---|
| 39 | */
|
|---|
| 40 | DWORD WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,
|
|---|
| 41 | PANSI_STRING ansi,
|
|---|
| 42 | BOOLEAN doalloc)
|
|---|
| 43 | {
|
|---|
| 44 | DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
|
|---|
| 45 |
|
|---|
| 46 | dprintf(("NTDLL: RtlAnsiStringToUnicodeString(%08xh,%08xh,%08xh)\n",
|
|---|
| 47 | uni,
|
|---|
| 48 | ansi,
|
|---|
| 49 | doalloc));
|
|---|
| 50 |
|
|---|
| 51 | if (unilen>0xFFFF)
|
|---|
| 52 | return STATUS_INVALID_PARAMETER_2;
|
|---|
| 53 |
|
|---|
| 54 | uni->Length = unilen;
|
|---|
| 55 | if (doalloc)
|
|---|
| 56 | {
|
|---|
| 57 | uni->MaximumLength = unilen;
|
|---|
| 58 | uni->Buffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
|
|---|
| 59 | if (!uni->Buffer)
|
|---|
| 60 | return STATUS_NO_MEMORY;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | if (unilen>uni->MaximumLength)
|
|---|
| 64 | return STATUS_BUFFER_OVERFLOW;
|
|---|
| 65 |
|
|---|
| 66 | AsciiToUnicodeN(ansi->Buffer,
|
|---|
| 67 | uni->Buffer,
|
|---|
| 68 | unilen/2);
|
|---|
| 69 |
|
|---|
| 70 | return STATUS_SUCCESS;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | /**************************************************************************
|
|---|
| 75 | * RtlOemStringToUnicodeString [NTDLL.447]
|
|---|
| 76 | */
|
|---|
| 77 | DWORD WINAPI RtlOemStringToUnicodeString(PUNICODE_STRING uni,
|
|---|
| 78 | PSTRING ansi,
|
|---|
| 79 | BOOLEAN doalloc)
|
|---|
| 80 | {
|
|---|
| 81 | DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
|
|---|
| 82 |
|
|---|
| 83 | dprintf(("NTDLL: RtlOemStringToUnicodeString(%08xh,%08xh,%08xh)\n",
|
|---|
| 84 | uni,
|
|---|
| 85 | ansi,
|
|---|
| 86 | doalloc));
|
|---|
| 87 |
|
|---|
| 88 | if (unilen>0xFFFF)
|
|---|
| 89 | return STATUS_INVALID_PARAMETER_2;
|
|---|
| 90 |
|
|---|
| 91 | uni->Length = unilen;
|
|---|
| 92 | if (doalloc)
|
|---|
| 93 | {
|
|---|
| 94 | uni->MaximumLength = unilen;
|
|---|
| 95 | uni->Buffer = (WCHAR *)HeapAlloc(GetProcessHeap(),
|
|---|
| 96 | HEAP_ZERO_MEMORY,
|
|---|
| 97 | unilen);
|
|---|
| 98 |
|
|---|
| 99 | if (!uni->Buffer)
|
|---|
| 100 | return STATUS_NO_MEMORY;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | if (unilen>uni->MaximumLength)
|
|---|
| 104 | return STATUS_BUFFER_OVERFLOW;
|
|---|
| 105 |
|
|---|
| 106 | AsciiToUnicodeN(ansi->Buffer,
|
|---|
| 107 | uni->Buffer,
|
|---|
| 108 | unilen/2);
|
|---|
| 109 | return STATUS_SUCCESS;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | /**************************************************************************
|
|---|
| 114 | * RtlMultiByteToUnicodeN [NTDLL.436]
|
|---|
| 115 | * FIXME: multibyte support
|
|---|
| 116 | */
|
|---|
| 117 | DWORD WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,
|
|---|
| 118 | DWORD unilen,
|
|---|
| 119 | LPDWORD reslen,
|
|---|
| 120 | LPSTR oemstr,
|
|---|
| 121 | DWORD oemlen)
|
|---|
| 122 | {
|
|---|
| 123 | DWORD len;
|
|---|
| 124 | LPWSTR x;
|
|---|
| 125 |
|
|---|
| 126 | dprintf(("NTDLL: RtlMultiByteToUnicodeN(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
|---|
| 127 | unistr,
|
|---|
| 128 | unilen,
|
|---|
| 129 | reslen,
|
|---|
| 130 | oemstr,
|
|---|
| 131 | oemlen));
|
|---|
| 132 |
|
|---|
| 133 | len = oemlen;
|
|---|
| 134 |
|
|---|
| 135 | if (unilen/2 < len)
|
|---|
| 136 | len = unilen/2;
|
|---|
| 137 |
|
|---|
| 138 | x=(LPWSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 139 | HEAP_ZERO_MEMORY,
|
|---|
| 140 | (len+1)*sizeof(WCHAR));
|
|---|
| 141 |
|
|---|
| 142 | AsciiToUnicodeN(oemstr,
|
|---|
| 143 | x,
|
|---|
| 144 | len+1);
|
|---|
| 145 |
|
|---|
| 146 | memcpy(unistr,
|
|---|
| 147 | x,
|
|---|
| 148 | len*2);
|
|---|
| 149 |
|
|---|
| 150 | if (reslen)
|
|---|
| 151 | *reslen = len*2;
|
|---|
| 152 |
|
|---|
| 153 | return 0;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | /**************************************************************************
|
|---|
| 158 | * RtlOemToUnicodeN [NTDLL.448]
|
|---|
| 159 | */
|
|---|
| 160 | DWORD WINAPI RtlOemToUnicodeN(LPWSTR unistr,
|
|---|
| 161 | DWORD unilen,
|
|---|
| 162 | LPDWORD reslen,
|
|---|
| 163 | LPSTR oemstr,
|
|---|
| 164 | DWORD oemlen)
|
|---|
| 165 | {
|
|---|
| 166 | DWORD len;
|
|---|
| 167 | LPWSTR x;
|
|---|
| 168 |
|
|---|
| 169 | dprintf(("NTDLL: RtlOemToUnicodeN(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
|---|
| 170 | unistr,
|
|---|
| 171 | unilen,
|
|---|
| 172 | reslen,
|
|---|
| 173 | oemstr,
|
|---|
| 174 | oemlen));
|
|---|
| 175 |
|
|---|
| 176 | len = oemlen;
|
|---|
| 177 |
|
|---|
| 178 | if (unilen/2 < len)
|
|---|
| 179 | len = unilen/2;
|
|---|
| 180 |
|
|---|
| 181 | x=(LPWSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 182 | HEAP_ZERO_MEMORY,
|
|---|
| 183 | (len+1)*sizeof(WCHAR));
|
|---|
| 184 |
|
|---|
| 185 | AsciiToUnicodeN(oemstr,
|
|---|
| 186 | x,
|
|---|
| 187 | len+1);
|
|---|
| 188 |
|
|---|
| 189 | memcpy(unistr,
|
|---|
| 190 | x,
|
|---|
| 191 | len*2);
|
|---|
| 192 |
|
|---|
| 193 | if (reslen)
|
|---|
| 194 | *reslen = len*2;
|
|---|
| 195 |
|
|---|
| 196 | return 0;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 | /**************************************************************************
|
|---|
| 201 | * RtlInitAnsiString [NTDLL.399]
|
|---|
| 202 | */
|
|---|
| 203 | VOID WINAPI RtlInitAnsiString(PANSI_STRING target,
|
|---|
| 204 | LPCSTR source)
|
|---|
| 205 | {
|
|---|
| 206 | dprintf(("NTDLL: RtlInitAnsiString(%08xh, %08xh)\n",
|
|---|
| 207 | target,
|
|---|
| 208 | source));
|
|---|
| 209 |
|
|---|
| 210 | target->Length = target->MaximumLength = 0;
|
|---|
| 211 | target->Buffer = (LPSTR)source;
|
|---|
| 212 | if (!source)
|
|---|
| 213 | return;
|
|---|
| 214 |
|
|---|
| 215 | target->MaximumLength = lstrlenA(target->Buffer);
|
|---|
| 216 | target->Length = target->MaximumLength+1;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 | /**************************************************************************
|
|---|
| 221 | * RtlInitOemString
|
|---|
| 222 | */
|
|---|
| 223 | VOID WINAPI RtlInitOemString(POEM_STRING target,
|
|---|
| 224 | LPCSTR source)
|
|---|
| 225 | {
|
|---|
| 226 | dprintf(("NTDLL: RtlInitOemString(%08xh, %08xh)\n",
|
|---|
| 227 | target,
|
|---|
| 228 | source));
|
|---|
| 229 |
|
|---|
| 230 | target->Length = target->MaximumLength = 0;
|
|---|
| 231 | target->Buffer = (LPSTR)source;
|
|---|
| 232 | if (!source)
|
|---|
| 233 | return;
|
|---|
| 234 |
|
|---|
| 235 | target->MaximumLength = lstrlenA(target->Buffer);
|
|---|
| 236 | target->Length = target->MaximumLength+1;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 | /**************************************************************************
|
|---|
| 242 | * RtlInitString [NTDLL.402]
|
|---|
| 243 | */
|
|---|
| 244 | VOID WINAPI RtlInitString(PSTRING target,
|
|---|
| 245 | LPCSTR source)
|
|---|
| 246 | {
|
|---|
| 247 | dprintf (("NTDLL: RtlInitString(%08xh, %08xh)\n",
|
|---|
| 248 | target,
|
|---|
| 249 | source));
|
|---|
| 250 |
|
|---|
| 251 | target->Length = target->MaximumLength = 0;
|
|---|
| 252 | target->Buffer = (LPSTR)source;
|
|---|
| 253 | if (!source)
|
|---|
| 254 | return;
|
|---|
| 255 |
|
|---|
| 256 | target->MaximumLength = lstrlenA(target->Buffer);
|
|---|
| 257 | target->Length = target->MaximumLength+1;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | /**************************************************************************
|
|---|
| 262 | * RtlInitUnicodeString [NTDLL.403]
|
|---|
| 263 | */
|
|---|
| 264 | VOID WINAPI RtlInitUnicodeString(PUNICODE_STRING target,
|
|---|
| 265 | LPCWSTR source)
|
|---|
| 266 | {
|
|---|
| 267 | dprintf(("NTDLL: RtlInitUnicodeString(%08xh,%08xh)\n",
|
|---|
| 268 | target,
|
|---|
| 269 | source));
|
|---|
| 270 |
|
|---|
| 271 | target->Length = target->MaximumLength = 0;
|
|---|
| 272 | target->Buffer = (LPWSTR)source;
|
|---|
| 273 | if (!source)
|
|---|
| 274 | return;
|
|---|
| 275 |
|
|---|
| 276 | target->MaximumLength = lstrlenW(target->Buffer)*2;
|
|---|
| 277 | target->Length = target->MaximumLength+2;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 | /**************************************************************************
|
|---|
| 282 | * RtlFreeUnicodeString [NTDLL.377]
|
|---|
| 283 | */
|
|---|
| 284 | VOID WINAPI RtlFreeUnicodeString(PUNICODE_STRING str)
|
|---|
| 285 | {
|
|---|
| 286 | dprintf(("NTDLL: RtlFreeUnicodeString(%08xh)\n",
|
|---|
| 287 | str));
|
|---|
| 288 |
|
|---|
| 289 | if (str->Buffer)
|
|---|
| 290 | HeapFree(GetProcessHeap(),
|
|---|
| 291 | 0,
|
|---|
| 292 | str->Buffer);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 | /**************************************************************************
|
|---|
| 297 | * RtlFreeAnsiString [NTDLL.373]
|
|---|
| 298 | */
|
|---|
| 299 | VOID WINAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
|
|---|
| 300 | {
|
|---|
| 301 | dprintf(("NTDLL: RtlFreeAnsiString(%08xh)\n",
|
|---|
| 302 | AnsiString));
|
|---|
| 303 |
|
|---|
| 304 | if( AnsiString->Buffer )
|
|---|
| 305 | HeapFree(GetProcessHeap(),
|
|---|
| 306 | 0,
|
|---|
| 307 | AnsiString->Buffer);
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 | /**************************************************************************
|
|---|
| 312 | * RtlFreeOemString
|
|---|
| 313 | */
|
|---|
| 314 | VOID WINAPI RtlFreeOemString(POEM_STRING OemString)
|
|---|
| 315 | {
|
|---|
| 316 | dprintf(("NTDLL: RtlFreeOemString(%08xh)\n",
|
|---|
| 317 | OemString));
|
|---|
| 318 |
|
|---|
| 319 | if( OemString->Buffer )
|
|---|
| 320 | HeapFree(GetProcessHeap(),
|
|---|
| 321 | 0,
|
|---|
| 322 | OemString->Buffer);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 | /**************************************************************************
|
|---|
| 328 | * RtlUnicodeToOemN [NTDLL.515]
|
|---|
| 329 | */
|
|---|
| 330 | DWORD WINAPI RtlUnicodeToOemN(LPSTR oemstr,
|
|---|
| 331 | DWORD oemlen,
|
|---|
| 332 | LPDWORD reslen,
|
|---|
| 333 | LPWSTR unistr,
|
|---|
| 334 | DWORD unilen)
|
|---|
| 335 | {
|
|---|
| 336 | DWORD len;
|
|---|
| 337 | LPSTR x;
|
|---|
| 338 |
|
|---|
| 339 | dprintf(("NTDLL: RtlUnicodeToOemN(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
|---|
| 340 | oemstr,
|
|---|
| 341 | oemlen,
|
|---|
| 342 | reslen,
|
|---|
| 343 | unistr,
|
|---|
| 344 | unilen));
|
|---|
| 345 |
|
|---|
| 346 | len = oemlen;
|
|---|
| 347 |
|
|---|
| 348 | if (unilen/2 < len)
|
|---|
| 349 | len = unilen/2;
|
|---|
| 350 |
|
|---|
| 351 | x=(LPSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 352 | HEAP_ZERO_MEMORY,
|
|---|
| 353 | len+1);
|
|---|
| 354 |
|
|---|
| 355 | UnicodeToAsciiN(unistr,
|
|---|
| 356 | x,
|
|---|
| 357 | len+1);
|
|---|
| 358 |
|
|---|
| 359 | memcpy(oemstr,
|
|---|
| 360 | x,
|
|---|
| 361 | len);
|
|---|
| 362 |
|
|---|
| 363 | if (reslen)
|
|---|
| 364 | *reslen = len;
|
|---|
| 365 |
|
|---|
| 366 | return 0;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 | /**************************************************************************
|
|---|
| 371 | * RtlUnicodeToMultiByteN [NTDLL.513]
|
|---|
| 372 | */
|
|---|
| 373 | DWORD WINAPI RtlUnicodeToMultiByteN(LPSTR oemstr,
|
|---|
| 374 | DWORD oemlen,
|
|---|
| 375 | LPDWORD reslen,
|
|---|
| 376 | LPWSTR unistr,
|
|---|
| 377 | DWORD unilen)
|
|---|
| 378 | {
|
|---|
| 379 | DWORD len;
|
|---|
| 380 | LPSTR x;
|
|---|
| 381 |
|
|---|
| 382 | dprintf(("NTDLL: RtlUnicodeToMultiByteN(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
|---|
| 383 | oemstr,
|
|---|
| 384 | oemlen,
|
|---|
| 385 | reslen,
|
|---|
| 386 | unistr,
|
|---|
| 387 | unilen));
|
|---|
| 388 |
|
|---|
| 389 | len = oemlen;
|
|---|
| 390 |
|
|---|
| 391 | if (unilen/2 < len)
|
|---|
| 392 | len = unilen/2;
|
|---|
| 393 |
|
|---|
| 394 | x=(LPSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 395 | HEAP_ZERO_MEMORY,
|
|---|
| 396 | len+1);
|
|---|
| 397 |
|
|---|
| 398 | UnicodeToAsciiN(unistr,
|
|---|
| 399 | x,
|
|---|
| 400 | len+1);
|
|---|
| 401 |
|
|---|
| 402 | memcpy(oemstr,
|
|---|
| 403 | x,
|
|---|
| 404 | len);
|
|---|
| 405 |
|
|---|
| 406 | if (reslen)
|
|---|
| 407 | *reslen = len;
|
|---|
| 408 |
|
|---|
| 409 | return 0;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 | /**************************************************************************
|
|---|
| 414 | * RtlUnicodeStringToOemString [NTDLL.511]
|
|---|
| 415 | */
|
|---|
| 416 | DWORD WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,
|
|---|
| 417 | PUNICODE_STRING uni,
|
|---|
| 418 | BOOLEAN alloc)
|
|---|
| 419 | {
|
|---|
| 420 | dprintf(("NTDLL: RtlUnicodeStringToOemString(%08xh,%08xh,%08xh)\n",
|
|---|
| 421 | oem,
|
|---|
| 422 | uni,
|
|---|
| 423 | alloc));
|
|---|
| 424 |
|
|---|
| 425 | if (alloc)
|
|---|
| 426 | {
|
|---|
| 427 | oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 428 | HEAP_ZERO_MEMORY,
|
|---|
| 429 | uni->Length/2)+1;
|
|---|
| 430 | oem->MaximumLength = uni->Length/2+1;
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | oem->Length = uni->Length/2;
|
|---|
| 434 | UnicodeToAsciiN(uni->Buffer,
|
|---|
| 435 | oem->Buffer,
|
|---|
| 436 | oem->MaximumLength);
|
|---|
| 437 | return 0;
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 440 | /**************************************************************************
|
|---|
| 441 | * RtlUnicodeStringToAnsiString [NTDLL.507]
|
|---|
| 442 | */
|
|---|
| 443 | DWORD WINAPI RtlUnicodeStringToAnsiString(PANSI_STRING oem,
|
|---|
| 444 | PUNICODE_STRING uni,
|
|---|
| 445 | BOOLEAN alloc)
|
|---|
| 446 | {
|
|---|
| 447 | dprintf(("NTDLL: RtlUnicodeStringToAnsiString(%08xh,%08xh,%08xh)\n",
|
|---|
| 448 | oem,
|
|---|
| 449 | uni,
|
|---|
| 450 | alloc));
|
|---|
| 451 |
|
|---|
| 452 | if (alloc)
|
|---|
| 453 | {
|
|---|
| 454 | oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 455 | HEAP_ZERO_MEMORY,
|
|---|
| 456 | uni->Length/2)+1;
|
|---|
| 457 | oem->MaximumLength = uni->Length/2+1;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | oem->Length = uni->Length/2;
|
|---|
| 461 | UnicodeToAsciiN(uni->Buffer,
|
|---|
| 462 | oem->Buffer,
|
|---|
| 463 | oem->MaximumLength);
|
|---|
| 464 |
|
|---|
| 465 | return 0;
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | /**************************************************************************
|
|---|
| 469 | * RtlEqualUnicodeString [NTDLL]
|
|---|
| 470 | */
|
|---|
| 471 | DWORD WINAPI RtlEqualUnicodeString(PUNICODE_STRING s1,
|
|---|
| 472 | PUNICODE_STRING s2,
|
|---|
| 473 | DWORD x)
|
|---|
| 474 | {
|
|---|
| 475 | dprintf(("NTDLL: RtlEqualUnicodeString(%08xh,%08xh,%08xh)\n",
|
|---|
| 476 | s1,
|
|---|
| 477 | s2,
|
|---|
| 478 | x));
|
|---|
| 479 |
|
|---|
| 480 | if (s1->Length != s2->Length)
|
|---|
| 481 | return 1;
|
|---|
| 482 |
|
|---|
| 483 | return !lstrncmpW(s1->Buffer,
|
|---|
| 484 | s2->Buffer,
|
|---|
| 485 | s1->Length/2);
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 | /**************************************************************************
|
|---|
| 490 | * RtlUpcaseUnicodeString [NTDLL.520]
|
|---|
| 491 | */
|
|---|
| 492 | DWORD WINAPI RtlUpcaseUnicodeString(PUNICODE_STRING dest,
|
|---|
| 493 | PUNICODE_STRING src,
|
|---|
| 494 | BOOLEAN doalloc)
|
|---|
| 495 | {
|
|---|
| 496 | LPWSTR s,t;
|
|---|
| 497 | DWORD i,len;
|
|---|
| 498 |
|
|---|
| 499 | dprintf(("NTDLL: RtlUpcaseUnicodeString(%08xh,%08xh,%08xh)\n",
|
|---|
| 500 | dest,
|
|---|
| 501 | src,
|
|---|
| 502 | doalloc));
|
|---|
| 503 |
|
|---|
| 504 | len = src->Length;
|
|---|
| 505 | if (doalloc)
|
|---|
| 506 | {
|
|---|
| 507 | dest->MaximumLength = len;
|
|---|
| 508 | dest->Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(),
|
|---|
| 509 | HEAP_ZERO_MEMORY,
|
|---|
| 510 | len);
|
|---|
| 511 | if (!dest->Buffer)
|
|---|
| 512 | return STATUS_NO_MEMORY;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | if (dest->MaximumLength < len)
|
|---|
| 516 | return STATUS_BUFFER_OVERFLOW;
|
|---|
| 517 |
|
|---|
| 518 | s=dest->Buffer;
|
|---|
| 519 | t=src->Buffer;
|
|---|
| 520 |
|
|---|
| 521 | /* len is in bytes */
|
|---|
| 522 | for (i = 0;
|
|---|
| 523 | i < len/2;
|
|---|
| 524 | i++)
|
|---|
| 525 | s[i] = towupper(t[i]);
|
|---|
| 526 |
|
|---|
| 527 | return STATUS_SUCCESS;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 | /**************************************************************************
|
|---|
| 532 | * RtlxOemStringToUnicodeSize [NTDLL.549]
|
|---|
| 533 | */
|
|---|
| 534 | UINT WINAPI RtlxOemStringToUnicodeSize(PSTRING str)
|
|---|
| 535 | {
|
|---|
| 536 | dprintf(("NTDLL: RtlxOemStringToUnicodeSize(%08xh)\n",
|
|---|
| 537 | str));
|
|---|
| 538 |
|
|---|
| 539 | return str->Length*2+2;
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 | /**************************************************************************
|
|---|
| 544 | * RtlxAnsiStringToUnicodeSize [NTDLL.548]
|
|---|
| 545 | */
|
|---|
| 546 | UINT WINAPI RtlxAnsiStringToUnicodeSize(PANSI_STRING str)
|
|---|
| 547 | {
|
|---|
| 548 | dprintf(("NTDLL: RtlxAnsiStringToUnicodeSize(%08xh)\n",
|
|---|
| 549 | str));
|
|---|
| 550 |
|
|---|
| 551 | return str->Length*2+2;
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 | /**************************************************************************
|
|---|
| 556 | * RtlIsTextUnicode [NTDLL.417]
|
|---|
| 557 | *
|
|---|
| 558 | * Apply various feeble heuristics to guess whether
|
|---|
| 559 | * the text buffer contains Unicode.
|
|---|
| 560 | * FIXME: should implement more tests.
|
|---|
| 561 | */
|
|---|
| 562 | DWORD WINAPI RtlIsTextUnicode(LPVOID buf,
|
|---|
| 563 | DWORD len,
|
|---|
| 564 | DWORD *pf)
|
|---|
| 565 | {
|
|---|
| 566 | LPWSTR s = (LPWSTR)buf;
|
|---|
| 567 | DWORD flags = -1,
|
|---|
| 568 | out_flags = 0;
|
|---|
| 569 |
|
|---|
| 570 | dprintf(("NTDLL: RtlIsTextUnicode(%08xh,%08xh,%08xh)\n",
|
|---|
| 571 | buf,
|
|---|
| 572 | len,
|
|---|
| 573 | pf));
|
|---|
| 574 |
|
|---|
| 575 | if (!len)
|
|---|
| 576 | goto out;
|
|---|
| 577 |
|
|---|
| 578 | if (pf)
|
|---|
| 579 | flags = *pf;
|
|---|
| 580 |
|
|---|
| 581 | /*
|
|---|
| 582 | * Apply various tests to the text string. According to the
|
|---|
| 583 | * docs, each test "passed" sets the corresponding flag in
|
|---|
| 584 | * the output flags. But some of the tests are mutually
|
|---|
| 585 | * exclusive, so I don't see how you could pass all tests ...
|
|---|
| 586 | */
|
|---|
| 587 |
|
|---|
| 588 | /* Check for an odd length ... pass if even. */
|
|---|
| 589 | if (!(len & 1))
|
|---|
| 590 | out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
|
|---|
| 591 |
|
|---|
| 592 | /* Check for the special unicode marker byte. */
|
|---|
| 593 | if (*s == 0xFEFF)
|
|---|
| 594 | out_flags |= IS_TEXT_UNICODE_SIGNATURE;
|
|---|
| 595 |
|
|---|
| 596 | /*
|
|---|
| 597 | * Check whether the string passed all of the tests.
|
|---|
| 598 | */
|
|---|
| 599 | flags &= ITU_IMPLEMENTED_TESTS;
|
|---|
| 600 | if ((out_flags & flags) != flags)
|
|---|
| 601 | len = 0;
|
|---|
| 602 |
|
|---|
| 603 | out:
|
|---|
| 604 | if (pf)
|
|---|
| 605 | *pf = out_flags;
|
|---|
| 606 |
|
|---|
| 607 | return len;
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 | /******************************************************************************
|
|---|
| 612 | * RtlCompareUnicodeString [NTDLL]
|
|---|
| 613 | */
|
|---|
| 614 | DWORD WINAPI RtlCompareUnicodeString(PUNICODE_STRING String1,
|
|---|
| 615 | PUNICODE_STRING String2,
|
|---|
| 616 | BOOLEAN CaseInSensitive)
|
|---|
| 617 | {
|
|---|
| 618 | dprintf(("NTDLL: RtlCompareUnicodeString(%08xh,%08xh,%08xh) not implemented.\n",
|
|---|
| 619 | String1,
|
|---|
| 620 | String2,
|
|---|
| 621 | CaseInSensitive));
|
|---|
| 622 |
|
|---|
| 623 | return 0;
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 | /**************************************************************************
|
|---|
| 629 | * RtlUpcaseUnicodeStringToOemString [NTDLL.?]
|
|---|
| 630 | * @@@PH: parameters are pure speculation!
|
|---|
| 631 | */
|
|---|
| 632 | DWORD WINAPI RtlUpcaseUnicodeStringToOemString(PANSI_STRING oem,
|
|---|
| 633 | PUNICODE_STRING uni,
|
|---|
| 634 | BOOLEAN alloc)
|
|---|
| 635 | {
|
|---|
| 636 | DWORD rc;
|
|---|
| 637 |
|
|---|
| 638 | dprintf(("NTDLL: RtlUpcaseUnicodeStringToOemString(%08xh,%08xh,%08xh)\n",
|
|---|
| 639 | oem,
|
|---|
| 640 | uni,
|
|---|
| 641 | alloc));
|
|---|
| 642 |
|
|---|
| 643 | rc = RtlUnicodeStringToOemString(oem,
|
|---|
| 644 | uni,
|
|---|
| 645 | alloc);
|
|---|
| 646 | if (rc == 0)
|
|---|
| 647 | strupr(oem->Buffer);
|
|---|
| 648 |
|
|---|
| 649 | return rc;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|