[10539] | 1 | /* $Id: heapstring.cpp,v 1.55 2004-03-18 11:13:41 sandervl Exp $ */
|
---|
[471] | 2 | /*
|
---|
| 3 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 4 | *
|
---|
| 5 | * Win32 compatibility string functions for OS/2
|
---|
| 6 | *
|
---|
[3815] | 7 | * NOTE: lstrcpyn* always appends a terminating 0 (unlike strncpy)!
|
---|
| 8 | *
|
---|
[471] | 9 | * Copyright 1999 Patrick Haller
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | /*****************************************************************************
|
---|
| 13 | * Includes *
|
---|
| 14 | *****************************************************************************/
|
---|
| 15 |
|
---|
[1292] | 16 | #include <odin.h>
|
---|
| 17 | #include <odinwrap.h>
|
---|
| 18 | #include <os2sel.h>
|
---|
| 19 |
|
---|
[471] | 20 | #include <os2win.h>
|
---|
| 21 | #include <stdlib.h>
|
---|
| 22 | #include <string.h>
|
---|
[3730] | 23 | #include <stdio.h>
|
---|
[471] | 24 | #include <winnls.h>
|
---|
| 25 | #include <unicode.h>
|
---|
[974] | 26 | #include <ctype.h>
|
---|
[21916] | 27 | #include <wchar.h>
|
---|
| 28 | #ifndef __GNUC__
|
---|
[567] | 29 | #include <wcstr.h>
|
---|
[21916] | 30 | #endif
|
---|
[471] | 31 | #include "heap.h"
|
---|
[21916] | 32 | #include <wine/unicode.h>
|
---|
[471] | 33 | #include "misc.h"
|
---|
[2485] | 34 | #include "codepage.h"
|
---|
[471] | 35 |
|
---|
[5457] | 36 | #define DBG_LOCALLOG DBG_heapstring
|
---|
[2802] | 37 | #include "dbglocal.h"
|
---|
| 38 |
|
---|
[7504] | 39 |
|
---|
[471] | 40 | /*****************************************************************************
|
---|
| 41 | * Defines *
|
---|
| 42 | *****************************************************************************/
|
---|
| 43 |
|
---|
[1292] | 44 | ODINDEBUGCHANNEL(KERNEL32-HEAPSTRING)
|
---|
[471] | 45 |
|
---|
[7504] | 46 |
|
---|
[471] | 47 | /*****************************************************************************
|
---|
[7504] | 48 | * Imported variables *
|
---|
| 49 | *****************************************************************************/
|
---|
| 50 |
|
---|
| 51 | // This macro could be mapped to GetProcessHeap() if there
|
---|
| 52 | // is any change in functionality
|
---|
| 53 | #define GetProcessHeap() Heap_ProcessHeap
|
---|
| 54 |
|
---|
| 55 | extern HANDLE Heap_ProcessHeap;
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | /*****************************************************************************
|
---|
[471] | 59 | * Name :
|
---|
| 60 | * Purpose :
|
---|
| 61 | * Parameters:
|
---|
| 62 | * Variables :
|
---|
| 63 | * Result :
|
---|
| 64 | * Remark :
|
---|
| 65 | * Status :
|
---|
| 66 | *
|
---|
| 67 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 68 | *****************************************************************************/
|
---|
| 69 |
|
---|
[7854] | 70 | int WIN32API lstrlenA(LPCSTR arg1)
|
---|
[471] | 71 | {
|
---|
[1670] | 72 | dprintf2(("KERNEL32: lstrlenA(%s)\n",
|
---|
[471] | 73 | arg1));
|
---|
| 74 |
|
---|
[6318] | 75 | if(arg1 == NULL) {
|
---|
| 76 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 77 | return 0;
|
---|
| 78 | }
|
---|
[6090] | 79 | return strlen(arg1);
|
---|
[471] | 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /*****************************************************************************
|
---|
| 84 | * Name :
|
---|
| 85 | * Purpose :
|
---|
| 86 | * Parameters:
|
---|
| 87 | * Variables :
|
---|
| 88 | * Result :
|
---|
| 89 | * Remark :
|
---|
| 90 | * Status :
|
---|
| 91 | *
|
---|
| 92 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 93 | *****************************************************************************/
|
---|
| 94 |
|
---|
[7854] | 95 | int WIN32API lstrlenW(LPCWSTR str)
|
---|
[471] | 96 | {
|
---|
[7832] | 97 | if(str == NULL) {
|
---|
[6318] | 98 | SetLastError( ERROR_INVALID_PARAMETER );
|
---|
| 99 | return 0;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[7832] | 102 | const WCHAR *s = str;
|
---|
| 103 | while (*s) s++;
|
---|
[1670] | 104 | dprintf2(("KERNEL32: lstrlenW(%08xh) returns %d\n",
|
---|
[7832] | 105 | str, s - str));
|
---|
| 106 |
|
---|
| 107 | return s - str;
|
---|
[471] | 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /*****************************************************************************
|
---|
| 112 | * Name :
|
---|
| 113 | * Purpose :
|
---|
| 114 | * Parameters:
|
---|
| 115 | * Variables :
|
---|
| 116 | * Result :
|
---|
| 117 | * Remark :
|
---|
| 118 | * Status :
|
---|
| 119 | *
|
---|
| 120 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 121 | *****************************************************************************/
|
---|
| 122 |
|
---|
[7854] | 123 | LPSTR WIN32API lstrcatA(LPSTR arg1, LPCSTR arg2)
|
---|
[471] | 124 | {
|
---|
[1670] | 125 | dprintf2(("KERNEL32: lstrcat(%s,%s)\n",
|
---|
[471] | 126 | arg1,
|
---|
| 127 | arg2));
|
---|
| 128 |
|
---|
[2077] | 129 | if(arg2 == NULL)
|
---|
| 130 | return arg1;
|
---|
| 131 | strcat(arg1, arg2);
|
---|
| 132 | return arg1;
|
---|
[471] | 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | /*****************************************************************************
|
---|
| 137 | * Name :
|
---|
| 138 | * Purpose :
|
---|
| 139 | * Parameters:
|
---|
| 140 | * Variables :
|
---|
| 141 | * Result :
|
---|
| 142 | * Remark :
|
---|
| 143 | * Status :
|
---|
| 144 | *
|
---|
| 145 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 146 | *****************************************************************************/
|
---|
| 147 |
|
---|
[7854] | 148 | LPWSTR WIN32API lstrcatW(LPWSTR dst, LPCWSTR src)
|
---|
[471] | 149 | {
|
---|
[7854] | 150 | dprintf2(("KERNEL32: lstrcatW(%08xh,%08xh)\n",
|
---|
[7832] | 151 | dst, src));
|
---|
[471] | 152 |
|
---|
[7832] | 153 | if(src == NULL)
|
---|
| 154 | return dst;
|
---|
[2077] | 155 |
|
---|
[7832] | 156 | strcpyW( dst + strlenW(dst), src );
|
---|
| 157 | return dst;
|
---|
[471] | 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | /*****************************************************************************
|
---|
| 162 | * Name :
|
---|
| 163 | * Purpose :
|
---|
| 164 | * Parameters:
|
---|
| 165 | * Variables :
|
---|
| 166 | * Result :
|
---|
| 167 | * Remark :
|
---|
| 168 | * Status :
|
---|
| 169 | *
|
---|
| 170 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 171 | *****************************************************************************/
|
---|
| 172 |
|
---|
[7854] | 173 | int WIN32API lstrcmpA(LPCSTR arg1, LPCSTR arg2)
|
---|
[471] | 174 | {
|
---|
[7854] | 175 | dprintf2(("KERNEL32: lstrcmpA(%s,%s)\n",
|
---|
[471] | 176 | arg1,
|
---|
| 177 | arg2));
|
---|
| 178 |
|
---|
[2447] | 179 | if(arg1 == NULL)
|
---|
| 180 | return -1;
|
---|
| 181 | if(arg2 == NULL)
|
---|
| 182 | return 1;
|
---|
| 183 |
|
---|
[6090] | 184 | return strcmp(arg1, arg2);
|
---|
[471] | 185 | }
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | /*****************************************************************************
|
---|
| 189 | * Name :
|
---|
| 190 | * Purpose :
|
---|
| 191 | * Parameters:
|
---|
| 192 | * Variables :
|
---|
| 193 | * Result :
|
---|
| 194 | * Remark :
|
---|
| 195 | * Status :
|
---|
| 196 | *
|
---|
| 197 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 198 | *****************************************************************************/
|
---|
| 199 |
|
---|
[7854] | 200 | int WIN32API lstrncmpA(LPCSTR arg1, LPCSTR arg2, int l)
|
---|
[567] | 201 | {
|
---|
[7854] | 202 | dprintf2(("KERNEL32: lstrncmpA(%s,%s,%d)\n",
|
---|
[567] | 203 | arg1,
|
---|
| 204 | arg2,
|
---|
| 205 | l));
|
---|
| 206 |
|
---|
| 207 | return strncmp(arg1, arg2, l);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[974] | 210 | /*****************************************************************************
|
---|
| 211 | * Name : lstrncmpiA
|
---|
| 212 | * Purpose :
|
---|
| 213 | * Parameters:
|
---|
| 214 | * Variables :
|
---|
| 215 | * Result :
|
---|
| 216 | * Remark :
|
---|
| 217 | * Status :
|
---|
| 218 | *
|
---|
| 219 | * Author : Przemyslaw Dobrowolski
|
---|
| 220 | *****************************************************************************/
|
---|
[7854] | 221 | int WIN32API lstrncmpiA(LPCSTR str1, LPCSTR str2, INT n )
|
---|
[974] | 222 | {
|
---|
| 223 | INT firstch,lastch;
|
---|
| 224 | INT result = 0;
|
---|
[567] | 225 |
|
---|
[974] | 226 | if (n)
|
---|
| 227 | {
|
---|
| 228 | do
|
---|
| 229 | {
|
---|
[6366] | 230 | firstch = toupper(*str1);
|
---|
| 231 | lastch = toupper(*str2);
|
---|
[974] | 232 | str1++;
|
---|
| 233 | str2++;
|
---|
[6440] | 234 | } while (--n && *str1 && *str2 && firstch == lastch);
|
---|
[567] | 235 |
|
---|
[974] | 236 | result = firstch - lastch;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | return(result);
|
---|
| 240 | }
|
---|
[1131] | 241 | //TODO: Don't know if this is completely correct
|
---|
[7854] | 242 | int WIN32API lstrncmpiW(LPCWSTR str1, LPCWSTR str2, int n)
|
---|
[1131] | 243 | {
|
---|
| 244 | INT firstch,lastch;
|
---|
| 245 | INT result = 0;
|
---|
[974] | 246 |
|
---|
[1131] | 247 | if (n)
|
---|
| 248 | {
|
---|
| 249 | do
|
---|
| 250 | {
|
---|
[6366] | 251 | firstch = toupperW(*str1);
|
---|
| 252 | lastch = toupperW(*str2);
|
---|
[1131] | 253 | str1++;
|
---|
| 254 | str2++;
|
---|
[6440] | 255 | } while (--n && *str1 && *str2 && firstch == lastch);
|
---|
[974] | 256 |
|
---|
[1131] | 257 | result = firstch - lastch;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | return(result);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[567] | 263 | /*****************************************************************************
|
---|
| 264 | * Name :
|
---|
| 265 | * Purpose :
|
---|
| 266 | * Parameters:
|
---|
| 267 | * Variables :
|
---|
| 268 | * Result :
|
---|
| 269 | * Remark :
|
---|
| 270 | * Status :
|
---|
| 271 | *
|
---|
| 272 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 273 | *****************************************************************************/
|
---|
| 274 |
|
---|
[7854] | 275 | int WIN32API lstrcmpW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
[471] | 276 | {
|
---|
[1997] | 277 | dprintf2(("KERNEL32: lstrcmpW (%08xh, %08xh)\n",
|
---|
[930] | 278 | arg1,
|
---|
| 279 | arg2));
|
---|
[1280] | 280 |
|
---|
| 281 | if(arg1 == NULL)
|
---|
| 282 | return -1;
|
---|
| 283 | if(arg2 == NULL)
|
---|
| 284 | return 1;
|
---|
| 285 |
|
---|
[5457] | 286 | return strcmpW( arg1, arg2 );
|
---|
[471] | 287 | }
|
---|
| 288 |
|
---|
| 289 |
|
---|
| 290 | /*****************************************************************************
|
---|
| 291 | * Name :
|
---|
| 292 | * Purpose :
|
---|
| 293 | * Parameters:
|
---|
| 294 | * Variables :
|
---|
| 295 | * Result :
|
---|
| 296 | * Remark :
|
---|
| 297 | * Status :
|
---|
| 298 | *
|
---|
| 299 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 300 | *****************************************************************************/
|
---|
| 301 |
|
---|
[7854] | 302 | int WIN32API lstrncmpW(LPCWSTR arg1, LPCWSTR arg2, int l)
|
---|
[567] | 303 | {
|
---|
[7854] | 304 | dprintf2(("KERNEL32: lstrncmpW(%08xh,%08xh,%d)\n",
|
---|
[567] | 305 | arg1,
|
---|
| 306 | arg2,
|
---|
| 307 | l));
|
---|
| 308 |
|
---|
| 309 | return wcsncmp((wchar_t*)arg1,
|
---|
| 310 | (wchar_t*)arg2,
|
---|
| 311 | l);
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | /*****************************************************************************
|
---|
| 315 | * Name :
|
---|
| 316 | * Purpose :
|
---|
| 317 | * Parameters:
|
---|
| 318 | * Variables :
|
---|
| 319 | * Result :
|
---|
| 320 | * Remark :
|
---|
| 321 | * Status :
|
---|
| 322 | *
|
---|
| 323 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 324 | *****************************************************************************/
|
---|
| 325 |
|
---|
[7854] | 326 | LPSTR WIN32API lstrcpyA(LPSTR dest, LPCSTR src)
|
---|
[471] | 327 | {
|
---|
[5457] | 328 | if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
|
---|
| 329 | return NULL;
|
---|
[471] | 330 |
|
---|
[5457] | 331 | return strcpy(dest, src);
|
---|
[471] | 332 | }
|
---|
| 333 |
|
---|
| 334 |
|
---|
| 335 | /*****************************************************************************
|
---|
| 336 | * Name :
|
---|
| 337 | * Purpose :
|
---|
| 338 | * Parameters:
|
---|
| 339 | * Variables :
|
---|
| 340 | * Result :
|
---|
| 341 | * Remark :
|
---|
| 342 | * Status :
|
---|
| 343 | *
|
---|
| 344 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 345 | *****************************************************************************/
|
---|
| 346 |
|
---|
[7854] | 347 | LPWSTR WIN32API lstrcpyW(LPWSTR dest, LPCWSTR src)
|
---|
[471] | 348 | {
|
---|
[5457] | 349 | if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
|
---|
| 350 | return NULL;
|
---|
[471] | 351 |
|
---|
[7832] | 352 | WCHAR *p = dest;
|
---|
[21355] | 353 | while ((*p++ = *src++) != 0);
|
---|
[7832] | 354 |
|
---|
[5457] | 355 | return dest;
|
---|
[471] | 356 | }
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 | /*****************************************************************************
|
---|
| 360 | * Name :
|
---|
| 361 | * Purpose :
|
---|
| 362 | * Parameters:
|
---|
| 363 | * Variables :
|
---|
| 364 | * Result :
|
---|
| 365 | * Remark :
|
---|
| 366 | * Status :
|
---|
| 367 | *
|
---|
| 368 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 369 | *****************************************************************************/
|
---|
| 370 |
|
---|
[7854] | 371 | LPSTR WIN32API lstrcpynA(LPSTR arg1, LPCSTR arg2, int arg3)
|
---|
[471] | 372 | {
|
---|
| 373 | register LPSTR p1 = arg1;
|
---|
| 374 | register LPSTR p2 = (LPSTR)arg2;
|
---|
| 375 |
|
---|
[4964] | 376 | if(arg3 == 0) {
|
---|
| 377 | return NULL;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[471] | 380 | //PH: looks like either \0 or arg3 terminate the copy
|
---|
| 381 | //return strncpy(arg1, arg2, arg3);
|
---|
| 382 | arg3--; // pre-decrement to avoid exceeding buffer length
|
---|
| 383 | // results in better code than (arg1 > 1)
|
---|
| 384 |
|
---|
| 385 | for (;*p2 && arg3; arg3--)
|
---|
| 386 | *p1++ = *p2++;
|
---|
| 387 |
|
---|
| 388 | *p1 = 0; //CB: copy arg-1, set end 0
|
---|
| 389 |
|
---|
| 390 | return arg1;
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 | /*****************************************************************************
|
---|
| 395 | * Name :
|
---|
| 396 | * Purpose :
|
---|
| 397 | * Parameters:
|
---|
| 398 | * Variables :
|
---|
| 399 | * Result :
|
---|
| 400 | * Remark :
|
---|
| 401 | * Status :
|
---|
| 402 | *
|
---|
| 403 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 404 | *****************************************************************************/
|
---|
| 405 |
|
---|
[7854] | 406 | LPWSTR WIN32API lstrcpynW(LPWSTR dst, LPCWSTR src, int n)
|
---|
[471] | 407 | {
|
---|
[7832] | 408 | LPWSTR p = dst;
|
---|
[471] | 409 |
|
---|
[7832] | 410 | /* In real windows the whole function is protected by an exception handler
|
---|
| 411 | * that returns ERROR_INVALID_PARAMETER on faulty parameters
|
---|
| 412 | * We currently just check for NULL.
|
---|
| 413 | */
|
---|
| 414 | if (!dst || !src) {
|
---|
[10176] | 415 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 416 | return 0;
|
---|
[7832] | 417 | }
|
---|
| 418 | while ((n-- > 1) && *src) *p++ = *src++;
|
---|
| 419 | if (n >= 0) *p = 0;
|
---|
| 420 | return dst;
|
---|
[471] | 421 | }
|
---|
| 422 |
|
---|
| 423 |
|
---|
| 424 | /*****************************************************************************
|
---|
| 425 | * Name :
|
---|
| 426 | * Purpose :
|
---|
| 427 | * Parameters:
|
---|
| 428 | * Variables :
|
---|
| 429 | * Result :
|
---|
| 430 | * Remark :
|
---|
| 431 | * Status :
|
---|
| 432 | *
|
---|
| 433 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 434 | *****************************************************************************/
|
---|
| 435 |
|
---|
[7854] | 436 | int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
|
---|
[471] | 437 | {
|
---|
[1670] | 438 | dprintf2(("KERNEL32: lstrcmpiA(%s,%s)\n",
|
---|
[471] | 439 | arg1,
|
---|
| 440 | arg2));
|
---|
| 441 |
|
---|
[1605] | 442 | if(arg1 == NULL)
|
---|
| 443 | return -1;
|
---|
| 444 |
|
---|
| 445 | if(arg2 == NULL)
|
---|
| 446 | return 1;
|
---|
| 447 |
|
---|
[21916] | 448 | return stricmp(arg1, arg2);
|
---|
[471] | 449 | }
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 | /*****************************************************************************
|
---|
| 453 | * Name :
|
---|
| 454 | * Purpose :
|
---|
| 455 | * Parameters:
|
---|
| 456 | * Variables :
|
---|
| 457 | * Result :
|
---|
| 458 | * Remark :
|
---|
| 459 | * Status :
|
---|
| 460 | *
|
---|
| 461 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 462 | *****************************************************************************/
|
---|
| 463 |
|
---|
[7846] | 464 | int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
|
---|
[471] | 465 | {
|
---|
[7064] | 466 | if (!str1 || !str2) {
|
---|
[10176] | 467 |
|
---|
[7064] | 468 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 469 | return 0;
|
---|
| 470 | }
|
---|
| 471 | return strcmpiW( str1, str2 );
|
---|
[471] | 472 | }
|
---|
| 473 |
|
---|
[5457] | 474 | //*****************************************************************************
|
---|
[4525] | 475 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
| 476 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
[5457] | 477 | //*****************************************************************************
|
---|
[7846] | 478 | int WIN32API lstrcpynWtoA(LPSTR astring, LPCWSTR ustring, int length)
|
---|
[2485] | 479 | {
|
---|
[4525] | 480 | int ret;
|
---|
| 481 |
|
---|
[5457] | 482 | ret = WideCharToMultiByte(CP_ACP, 0, ustring, -1, astring, length, 0, NULL);
|
---|
[5476] | 483 | if(ret == 0) {
|
---|
| 484 | SetLastError(ERROR_SUCCESS); //WideCharToMultiByte sets it to ERROR_INSUFFICIENT_BUFFER
|
---|
| 485 | ret = length;
|
---|
| 486 | }
|
---|
[4664] | 487 | //Must not always set the last character to 0; some apps send the wrong
|
---|
| 488 | //string size to apis that use this function (i.e. GetMenuStringW (Notes))
|
---|
| 489 | //-> overwrites stack
|
---|
[5457] | 490 | if(ret == length) {
|
---|
[10191] | 491 | #if 1
|
---|
| 492 | lstrtrunc( astring, length );
|
---|
| 493 | #else
|
---|
[5457] | 494 | astring[length-1] = 0;
|
---|
[10191] | 495 | #endif
|
---|
[4664] | 496 | }
|
---|
| 497 | else astring[ret] = 0;
|
---|
[5457] | 498 |
|
---|
[4525] | 499 | return ret;
|
---|
[2485] | 500 | }
|
---|
[471] | 501 |
|
---|
[4525] | 502 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
| 503 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
[10176] | 504 | int WIN32API lstrcpynAtoW(LPWSTR unicode, LPCSTR ascii, int unilen)
|
---|
[2485] | 505 | {
|
---|
[4525] | 506 | int ret;
|
---|
| 507 |
|
---|
[10176] | 508 | ret = MultiByteToWideChar(CP_ACP, 0, ascii, -1, unicode, unilen );
|
---|
[5476] | 509 | if(ret == 0) {
|
---|
| 510 | SetLastError(ERROR_SUCCESS); //MultiByteToWideChar sets it to ERROR_INSUFFICIENT_BUFFER
|
---|
[10176] | 511 | ret = unilen;
|
---|
[5476] | 512 | }
|
---|
[5457] | 513 |
|
---|
[4664] | 514 | //Must not always set the last character to 0; some apps send the wrong
|
---|
| 515 | //string size to apis that use this function (i.e. GetMenuStringW (Notes))
|
---|
| 516 | //-> overwrites stack
|
---|
[10176] | 517 | if(ret == unilen) {
|
---|
| 518 | unicode[unilen-1] = 0;
|
---|
[4664] | 519 | }
|
---|
| 520 | else unicode[ret] = 0;
|
---|
[4525] | 521 | return ret;
|
---|
[2485] | 522 | }
|
---|
[471] | 523 |
|
---|
| 524 | /*****************************************************************************
|
---|
| 525 | * Name :
|
---|
| 526 | * Purpose : Converts unicode string to ascii string
|
---|
| 527 | * Parameters:
|
---|
| 528 | * Variables :
|
---|
| 529 | * Result : returns length of ascii string
|
---|
| 530 | * Remark :
|
---|
| 531 | * Status :
|
---|
| 532 | *
|
---|
| 533 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 534 | *****************************************************************************/
|
---|
| 535 |
|
---|
[7846] | 536 | LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
|
---|
[471] | 537 | {
|
---|
[5457] | 538 | //@@@PH huh? wuz dat?
|
---|
| 539 | if (unicode == NULL)
|
---|
| 540 | {
|
---|
| 541 | DebugInt3();
|
---|
| 542 | if (ascii != NULL) ((LPWSTR)ascii)[0] = 0; //CB: set at least end
|
---|
| 543 | return NULL;
|
---|
| 544 | }
|
---|
[471] | 545 |
|
---|
[5457] | 546 | if (ascii == NULL) {
|
---|
| 547 | DebugInt3();
|
---|
| 548 | return NULL; /* garbage in, garbage out ! */
|
---|
| 549 | }
|
---|
[471] | 550 |
|
---|
[5457] | 551 | /* forward to function with len parameter */
|
---|
| 552 | lstrcpynWtoA(ascii,
|
---|
[471] | 553 | unicode,
|
---|
[10176] | 554 | WideCharToMultiByte( CP_ACP, 0, unicode, -1, 0, 0, 0, 0 )); //end included
|
---|
[471] | 555 |
|
---|
[5457] | 556 | return ascii;
|
---|
[471] | 557 | }
|
---|
| 558 |
|
---|
| 559 |
|
---|
| 560 | /*****************************************************************************
|
---|
| 561 | * Name :
|
---|
| 562 | * Purpose : Copies the full string from ascii to unicode
|
---|
| 563 | * Parameters:
|
---|
| 564 | * Variables :
|
---|
| 565 | * Result :
|
---|
| 566 | * Remark :
|
---|
| 567 | * Status :
|
---|
| 568 | *
|
---|
| 569 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 570 | *****************************************************************************/
|
---|
| 571 |
|
---|
[7846] | 572 | LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
|
---|
[471] | 573 | {
|
---|
[5457] | 574 | /* achimha for security, strlen might trap if garbage in */
|
---|
| 575 | /* @@@PH 98/06/07 */
|
---|
| 576 | if (ascii == NULL)
|
---|
| 577 | {
|
---|
[21361] | 578 | //DebugInt3();
|
---|
[5457] | 579 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
| 580 | return NULL;
|
---|
| 581 | }
|
---|
[471] | 582 |
|
---|
[5457] | 583 | if (unicode == NULL) {
|
---|
[21361] | 584 | //DebugInt3();
|
---|
[5457] | 585 | return NULL; /* garbage in, garbage out ! */
|
---|
| 586 | }
|
---|
[471] | 587 |
|
---|
[5457] | 588 | /* forward to call with length parameter */
|
---|
[10176] | 589 | lstrcpynAtoW(unicode, ascii, MultiByteToWideChar( CP_ACP, 0, ascii, -1, 0, 0 )); //end included
|
---|
[5457] | 590 | return (unicode);
|
---|
[471] | 591 | }
|
---|
| 592 |
|
---|
[10176] | 593 | /*****************************************************************************
|
---|
| 594 | * NAME
|
---|
| 595 | * lstrlenWtoA
|
---|
| 596 | *
|
---|
| 597 | * PURPOSE
|
---|
| 598 | * calculate the length of string when unicode string was converted to
|
---|
| 599 | * ansi string.
|
---|
| 600 | *
|
---|
| 601 | * PARAMETERS
|
---|
| 602 | * ustring - unicode string
|
---|
| 603 | * ulen - length of ustring
|
---|
| 604 | *
|
---|
| 605 | * RESULT
|
---|
| 606 | * Success
|
---|
| 607 | * if ulen < 0, length of null-terminated unicode string NOT including
|
---|
| 608 | * null-terminator.
|
---|
| 609 | * otherwise, length of string when first ulen characters of ustring
|
---|
| 610 | * converted to ansi string.
|
---|
| 611 | *
|
---|
| 612 | * Failure
|
---|
| 613 | * return 0.
|
---|
| 614 | *
|
---|
| 615 | * REMARK
|
---|
| 616 | * this function is not Win32 API but helper for convenient.
|
---|
| 617 | *
|
---|
| 618 | * AUTHOR : KO Myung-Hun
|
---|
| 619 | *****************************************************************************/
|
---|
[471] | 620 |
|
---|
[10176] | 621 | int WIN32API lstrlenWtoA( LPCWSTR ustring, int ulen )
|
---|
| 622 | {
|
---|
| 623 | int ret;
|
---|
[471] | 624 |
|
---|
[10176] | 625 | if( ulen < 0 )
|
---|
| 626 | ulen = lstrlenW( ustring );
|
---|
[471] | 627 |
|
---|
[10191] | 628 | if( !IsDBCSEnv() ) return ulen;
|
---|
| 629 |
|
---|
[10176] | 630 | ret = WideCharToMultiByte( CP_ACP, 0, ustring, ulen, 0, 0, 0, 0 );
|
---|
| 631 | if(ret == 0) {
|
---|
| 632 | SetLastError(ERROR_SUCCESS); //WideCharToMultiByte sets it to ERROR_INSUFFICIENT_BUFFER
|
---|
| 633 | return 0;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | return ret;
|
---|
| 637 | }
|
---|
| 638 |
|
---|
[471] | 639 | /*****************************************************************************
|
---|
[10176] | 640 | * NAME
|
---|
| 641 | * lstrlenAtoW
|
---|
| 642 | *
|
---|
| 643 | * PURPOSE
|
---|
| 644 | * return the length of string when ansi string was converted to
|
---|
| 645 | * unicode string.
|
---|
| 646 | *
|
---|
| 647 | * PARAMETERS
|
---|
| 648 | * astring - ansi string
|
---|
| 649 | * alen - length of astring
|
---|
| 650 | *
|
---|
| 651 | * RESULT
|
---|
| 652 | * Success
|
---|
| 653 | * if alen < 0, length of null-terminated ansi string NOT including
|
---|
| 654 | * null-terminator.
|
---|
| 655 | * otherwise, length of string when first alen characters of astring
|
---|
| 656 | * converted to unicode string.
|
---|
| 657 | *
|
---|
| 658 | * Failure
|
---|
| 659 | * return 0.
|
---|
| 660 | *
|
---|
| 661 | * REMARK
|
---|
| 662 | * this function is not Win32 API but helper for convenient.
|
---|
| 663 | *
|
---|
| 664 | * AUTHOR : KO Myung-Hun
|
---|
| 665 | *****************************************************************************/
|
---|
| 666 |
|
---|
| 667 | int WIN32API lstrlenAtoW( LPCSTR astring, int alen )
|
---|
| 668 | {
|
---|
| 669 | int ret;
|
---|
| 670 |
|
---|
| 671 | if( alen < 0 )
|
---|
| 672 | alen = strlen( astring );
|
---|
| 673 |
|
---|
[10191] | 674 | if( !IsDBCSEnv() ) return alen;
|
---|
| 675 |
|
---|
[10176] | 676 | ret = MultiByteToWideChar( CP_ACP, 0, astring, alen, 0, 0 );
|
---|
| 677 | if(ret == 0) {
|
---|
| 678 | SetLastError(ERROR_SUCCESS); //MultiByteToWideChar sets it to ERROR_INSUFFICIENT_BUFFER
|
---|
| 679 | return 0;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | return ret;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | /*****************************************************************************
|
---|
[10191] | 686 | * NAME
|
---|
| 687 | * lstrtrunc
|
---|
| 688 | *
|
---|
| 689 | * PURPOSE
|
---|
| 690 | * truncate ansi string
|
---|
| 691 | *
|
---|
| 692 | * PARAMETERS
|
---|
| 693 | * max - max length of truncated string including null-terminator
|
---|
| 694 | *
|
---|
| 695 | * RESULT
|
---|
| 696 | * Success
|
---|
| 697 | * return the length of truncated string not including null-terminator
|
---|
| 698 | *
|
---|
| 699 | * Failure
|
---|
| 700 | * return 0.
|
---|
| 701 | *
|
---|
| 702 | * REMARK
|
---|
| 703 | * this function is not Win32 API but helper for convenient.
|
---|
| 704 | *
|
---|
| 705 | * AUTHOR : KO Myung-Hun
|
---|
| 706 | *****************************************************************************/
|
---|
| 707 |
|
---|
| 708 | int WIN32API lstrtrunc( LPSTR astring, int max )
|
---|
| 709 | {
|
---|
| 710 | int i;
|
---|
| 711 |
|
---|
| 712 | if( !astring || ( max < 1 ))
|
---|
| 713 | return 0;
|
---|
| 714 |
|
---|
| 715 | astring[ max - 1 ] = 0;
|
---|
| 716 |
|
---|
| 717 | if( !IsDBCSEnv() ) return max;
|
---|
| 718 |
|
---|
| 719 | max = strlen( astring );
|
---|
| 720 | for( i = 0; i < max; i++ )
|
---|
| 721 | if( IsDBCSLeadByte( astring[ i ]))
|
---|
| 722 | i++;
|
---|
| 723 |
|
---|
| 724 | if( i > max ) // broken DBCS lead byte ?
|
---|
| 725 | astring[ --max ] = 0; // then remove DBCS lead byte
|
---|
| 726 |
|
---|
| 727 | return max;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | /*****************************************************************************
|
---|
[471] | 731 | * Name :
|
---|
| 732 | * Purpose :
|
---|
| 733 | * Parameters:
|
---|
| 734 | * Variables :
|
---|
| 735 | * Result :
|
---|
| 736 | * Remark :
|
---|
| 737 | * Status :
|
---|
| 738 | *
|
---|
| 739 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 740 | *****************************************************************************/
|
---|
| 741 |
|
---|
[7846] | 742 | LPVOID WIN32API HEAP_xalloc(HANDLE heap, DWORD flags, DWORD size )
|
---|
[471] | 743 | {
|
---|
| 744 | LPVOID p = HeapAlloc( heap, flags, size );
|
---|
| 745 | if (!p)
|
---|
| 746 | {
|
---|
[1670] | 747 | dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
|
---|
[471] | 748 | heap,
|
---|
| 749 | flags,
|
---|
| 750 | size));
|
---|
| 751 | }
|
---|
| 752 | return p;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | /*****************************************************************************
|
---|
| 757 | * Name :
|
---|
| 758 | * Purpose :
|
---|
| 759 | * Parameters:
|
---|
| 760 | * Variables :
|
---|
| 761 | * Result :
|
---|
| 762 | * Remark :
|
---|
| 763 | * Status :
|
---|
| 764 | *
|
---|
| 765 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 766 | *****************************************************************************/
|
---|
| 767 |
|
---|
[7854] | 768 | LPVOID WIN32API HEAP_xrealloc(HANDLE heap, DWORD flags, LPVOID lpMem,
|
---|
| 769 | DWORD size )
|
---|
[471] | 770 | {
|
---|
| 771 | LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
|
---|
| 772 | if (!p)
|
---|
| 773 | {
|
---|
[1670] | 774 | dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
|
---|
[471] | 775 | heap,
|
---|
| 776 | flags,
|
---|
| 777 | lpMem,
|
---|
| 778 | size));
|
---|
| 779 | }
|
---|
| 780 | return p;
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 |
|
---|
| 784 | /*****************************************************************************
|
---|
| 785 | * Name :
|
---|
| 786 | * Purpose :
|
---|
| 787 | * Parameters:
|
---|
| 788 | * Variables :
|
---|
| 789 | * Result :
|
---|
| 790 | * Remark :
|
---|
| 791 | * Status :
|
---|
| 792 | *
|
---|
| 793 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 794 | *****************************************************************************/
|
---|
| 795 |
|
---|
[7854] | 796 | LPVOID WIN32API HEAP_malloc(DWORD size )
|
---|
[471] | 797 | {
|
---|
| 798 | LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
|
---|
| 799 | if (!p)
|
---|
| 800 | {
|
---|
[1670] | 801 | dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
|
---|
[471] | 802 | size));
|
---|
| 803 | }
|
---|
| 804 | return p;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 |
|
---|
| 808 | /*****************************************************************************
|
---|
| 809 | * Name :
|
---|
| 810 | * Purpose :
|
---|
| 811 | * Parameters:
|
---|
| 812 | * Variables :
|
---|
| 813 | * Result :
|
---|
| 814 | * Remark :
|
---|
| 815 | * Status :
|
---|
| 816 | *
|
---|
| 817 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 818 | *****************************************************************************/
|
---|
| 819 |
|
---|
[7854] | 820 | DWORD WIN32API HEAP_size(LPVOID lpMem)
|
---|
[4363] | 821 | {
|
---|
| 822 | return HeapSize( GetProcessHeap(), 0, lpMem );
|
---|
| 823 | }
|
---|
| 824 |
|
---|
| 825 |
|
---|
| 826 | /*****************************************************************************
|
---|
| 827 | * Name :
|
---|
| 828 | * Purpose :
|
---|
| 829 | * Parameters:
|
---|
| 830 | * Variables :
|
---|
| 831 | * Result :
|
---|
| 832 | * Remark :
|
---|
| 833 | * Status :
|
---|
| 834 | *
|
---|
| 835 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 836 | *****************************************************************************/
|
---|
| 837 |
|
---|
[7854] | 838 | LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
|
---|
[471] | 839 | {
|
---|
| 840 | LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
|
---|
| 841 | if (!p)
|
---|
| 842 | {
|
---|
[1670] | 843 | dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
|
---|
[471] | 844 | lpMem,
|
---|
| 845 | size));
|
---|
| 846 | }
|
---|
| 847 | return p;
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 |
|
---|
| 851 | /*****************************************************************************
|
---|
| 852 | * Name :
|
---|
| 853 | * Purpose :
|
---|
| 854 | * Parameters:
|
---|
| 855 | * Variables :
|
---|
| 856 | * Result :
|
---|
| 857 | * Remark :
|
---|
| 858 | * Status :
|
---|
| 859 | *
|
---|
| 860 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 861 | *****************************************************************************/
|
---|
| 862 |
|
---|
[7854] | 863 | BOOL WIN32API HEAP_free(LPVOID lpMem)
|
---|
[471] | 864 | {
|
---|
[7504] | 865 | return HeapFree( GetProcessHeap(), 0, lpMem);
|
---|
[471] | 866 | }
|
---|
| 867 |
|
---|
| 868 |
|
---|
| 869 | /*****************************************************************************
|
---|
| 870 | * Name :
|
---|
| 871 | * Purpose :
|
---|
| 872 | * Parameters:
|
---|
| 873 | * Variables :
|
---|
| 874 | * Result :
|
---|
| 875 | * Remark :
|
---|
| 876 | * Status :
|
---|
| 877 | *
|
---|
| 878 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 879 | *****************************************************************************/
|
---|
| 880 |
|
---|
[7854] | 881 | LPSTR WIN32API HEAP_strdupA(HANDLE heap, DWORD flags, LPCSTR str )
|
---|
[471] | 882 | {
|
---|
[7064] | 883 | int iLength = lstrlenA(str) + 1;
|
---|
| 884 | LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, iLength );
|
---|
| 885 | memcpy( p, str, iLength );
|
---|
| 886 | return p;
|
---|
[471] | 887 | }
|
---|
| 888 |
|
---|
| 889 |
|
---|
| 890 | /*****************************************************************************
|
---|
| 891 | * Name :
|
---|
| 892 | * Purpose :
|
---|
| 893 | * Parameters:
|
---|
| 894 | * Variables :
|
---|
| 895 | * Result :
|
---|
| 896 | * Remark :
|
---|
| 897 | * Status :
|
---|
| 898 | *
|
---|
| 899 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 900 | *****************************************************************************/
|
---|
| 901 |
|
---|
[7854] | 902 | LPWSTR WIN32API HEAP_strdupW(HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
[471] | 903 | {
|
---|
[5457] | 904 | INT len = lstrlenW(str) + 1;
|
---|
| 905 | LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
|
---|
[10539] | 906 | memcpy( p, str, len * sizeof(WCHAR) );
|
---|
[5457] | 907 | return p;
|
---|
[471] | 908 | }
|
---|
| 909 |
|
---|
| 910 |
|
---|
| 911 | /*****************************************************************************
|
---|
| 912 | * Name :
|
---|
| 913 | * Purpose :
|
---|
| 914 | * Parameters:
|
---|
| 915 | * Variables :
|
---|
| 916 | * Result :
|
---|
| 917 | * Remark :
|
---|
| 918 | * Status :
|
---|
| 919 | *
|
---|
| 920 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 921 | *****************************************************************************/
|
---|
| 922 |
|
---|
[7854] | 923 | LPWSTR WIN32API HEAP_strdupAtoW(HANDLE heap, DWORD flags, LPCSTR str )
|
---|
[471] | 924 | {
|
---|
[5457] | 925 | LPWSTR ret;
|
---|
| 926 | int len;
|
---|
[471] | 927 |
|
---|
[5457] | 928 | if (!str) return NULL;
|
---|
| 929 |
|
---|
| 930 | len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
|
---|
| 931 | ret = (LPWSTR)HEAP_xalloc( heap, flags, len*sizeof(WCHAR));
|
---|
| 932 | MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
---|
| 933 |
|
---|
| 934 | return ret;
|
---|
[471] | 935 | }
|
---|
| 936 |
|
---|
| 937 |
|
---|
| 938 | /*****************************************************************************
|
---|
| 939 | * Name :
|
---|
| 940 | * Purpose :
|
---|
| 941 | * Parameters:
|
---|
| 942 | * Variables :
|
---|
| 943 | * Result :
|
---|
| 944 | * Remark :
|
---|
| 945 | * Status :
|
---|
| 946 | *
|
---|
| 947 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
| 948 | *****************************************************************************/
|
---|
| 949 |
|
---|
[7854] | 950 | LPSTR WIN32API HEAP_strdupWtoA(HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
[471] | 951 | {
|
---|
[5457] | 952 | LPSTR ret;
|
---|
| 953 | int len;
|
---|
[471] | 954 |
|
---|
[5457] | 955 | if (!str) return NULL;
|
---|
| 956 |
|
---|
| 957 | len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, 0, NULL);
|
---|
| 958 | ret = (LPSTR)HEAP_xalloc( heap, flags, len);
|
---|
| 959 | WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, 0, NULL );
|
---|
| 960 | return ret;
|
---|
[471] | 961 | }
|
---|
| 962 |
|
---|
| 963 |
|
---|
[634] | 964 |
|
---|
[794] | 965 |
|
---|