1 | /* $Id: heapstring.cpp,v 1.10 1999-09-14 13:44:21 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
5 | *
|
---|
6 | * Win32 compatibility string functions for OS/2
|
---|
7 | *
|
---|
8 | * Copyright 1999 Patrick Haller
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*****************************************************************************
|
---|
12 | * Includes *
|
---|
13 | *****************************************************************************/
|
---|
14 |
|
---|
15 | #include <os2win.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 | #include <string.h>
|
---|
18 | #include <winnls.h>
|
---|
19 | #include <unicode.h>
|
---|
20 | #include <wcstr.h>
|
---|
21 | #include "heap.h"
|
---|
22 | #include <heapstring.h>
|
---|
23 | #include "misc.h"
|
---|
24 |
|
---|
25 |
|
---|
26 | /*****************************************************************************
|
---|
27 | * Defines *
|
---|
28 | *****************************************************************************/
|
---|
29 |
|
---|
30 |
|
---|
31 | /*****************************************************************************
|
---|
32 | * Name :
|
---|
33 | * Purpose :
|
---|
34 | * Parameters:
|
---|
35 | * Variables :
|
---|
36 | * Result :
|
---|
37 | * Remark :
|
---|
38 | * Status :
|
---|
39 | *
|
---|
40 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
41 | *****************************************************************************/
|
---|
42 |
|
---|
43 | static UconvObject uconv_object = NULL;
|
---|
44 |
|
---|
45 | static BOOL getUconvObject( void )
|
---|
46 | {
|
---|
47 | int rc;
|
---|
48 | BOOL ret;
|
---|
49 |
|
---|
50 | if ( uconv_object )
|
---|
51 | ret = TRUE;
|
---|
52 | else
|
---|
53 | {
|
---|
54 | rc = UniCreateUconvObject( (UniChar*)L"",
|
---|
55 | &uconv_object );
|
---|
56 | if ( rc == ULS_SUCCESS )
|
---|
57 | ret = TRUE;
|
---|
58 | else
|
---|
59 | {
|
---|
60 | uconv_object = NULL; // to make sure
|
---|
61 | return FALSE;
|
---|
62 | }
|
---|
63 | dprintf(("KERNEL32: HeapString: UniCreateUconvObject(%d)\n",
|
---|
64 | rc));
|
---|
65 | }
|
---|
66 | return ret;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /*****************************************************************************
|
---|
71 | * Name :
|
---|
72 | * Purpose :
|
---|
73 | * Parameters:
|
---|
74 | * Variables :
|
---|
75 | * Result :
|
---|
76 | * Remark :
|
---|
77 | * Status :
|
---|
78 | *
|
---|
79 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
80 | *****************************************************************************/
|
---|
81 |
|
---|
82 | int WIN32API lstrlenA(LPCSTR arg1)
|
---|
83 | {
|
---|
84 | dprintf(("KERNEL32: lstrlenA(%s)\n",
|
---|
85 | arg1));
|
---|
86 |
|
---|
87 | return O32_lstrlen(arg1);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /*****************************************************************************
|
---|
92 | * Name :
|
---|
93 | * Purpose :
|
---|
94 | * Parameters:
|
---|
95 | * Variables :
|
---|
96 | * Result :
|
---|
97 | * Remark :
|
---|
98 | * Status :
|
---|
99 | *
|
---|
100 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
101 | *****************************************************************************/
|
---|
102 |
|
---|
103 | int WIN32API lstrlenW(LPCWSTR arg1)
|
---|
104 | {
|
---|
105 | int rc;
|
---|
106 |
|
---|
107 | rc = UniStrlen( (UniChar*)arg1);
|
---|
108 | dprintf(("KERNEL32: lstrlenW(%08xh) returns %d\n",
|
---|
109 | arg1,
|
---|
110 | rc));
|
---|
111 | return rc;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | /*****************************************************************************
|
---|
116 | * Name :
|
---|
117 | * Purpose :
|
---|
118 | * Parameters:
|
---|
119 | * Variables :
|
---|
120 | * Result :
|
---|
121 | * Remark :
|
---|
122 | * Status :
|
---|
123 | *
|
---|
124 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
125 | *****************************************************************************/
|
---|
126 |
|
---|
127 | LPSTR WIN32API lstrcatA(LPSTR arg1, LPCSTR arg2)
|
---|
128 | {
|
---|
129 | dprintf(("KERNEL32: lstrcat(%s,%s)\n",
|
---|
130 | arg1,
|
---|
131 | arg2));
|
---|
132 |
|
---|
133 | return O32_lstrcat(arg1, arg2);
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /*****************************************************************************
|
---|
138 | * Name :
|
---|
139 | * Purpose :
|
---|
140 | * Parameters:
|
---|
141 | * Variables :
|
---|
142 | * Result :
|
---|
143 | * Remark :
|
---|
144 | * Status :
|
---|
145 | *
|
---|
146 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
147 | *****************************************************************************/
|
---|
148 |
|
---|
149 | LPWSTR WIN32API lstrcatW(LPWSTR arg1, LPCWSTR arg2)
|
---|
150 | {
|
---|
151 | dprintf(("KERNEL32: OS2lstrcatW(%08xh,%08xh)\n",
|
---|
152 | arg1,
|
---|
153 | arg2));
|
---|
154 |
|
---|
155 | UniStrcat( (UniChar*) arg1, (UniChar*) arg2 );
|
---|
156 | return arg1;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | /*****************************************************************************
|
---|
161 | * Name :
|
---|
162 | * Purpose :
|
---|
163 | * Parameters:
|
---|
164 | * Variables :
|
---|
165 | * Result :
|
---|
166 | * Remark :
|
---|
167 | * Status :
|
---|
168 | *
|
---|
169 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
170 | *****************************************************************************/
|
---|
171 |
|
---|
172 | int WIN32API lstrcmpA(LPCSTR arg1, LPCSTR arg2)
|
---|
173 | {
|
---|
174 | dprintf(("KERNEL32: OS2lstrcmpA(%s,%s)\n",
|
---|
175 | arg1,
|
---|
176 | arg2));
|
---|
177 |
|
---|
178 | return O32_lstrcmp(arg1, arg2);
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /*****************************************************************************
|
---|
183 | * Name :
|
---|
184 | * Purpose :
|
---|
185 | * Parameters:
|
---|
186 | * Variables :
|
---|
187 | * Result :
|
---|
188 | * Remark :
|
---|
189 | * Status :
|
---|
190 | *
|
---|
191 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
192 | *****************************************************************************/
|
---|
193 |
|
---|
194 | int WIN32API lstrncmpA(LPCSTR arg1, LPCSTR arg2, int l)
|
---|
195 | {
|
---|
196 | dprintf(("KERNEL32: OS2lstrncmpA(%s,%s,%d)\n",
|
---|
197 | arg1,
|
---|
198 | arg2,
|
---|
199 | l));
|
---|
200 |
|
---|
201 | return strncmp(arg1, arg2, l);
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | /*****************************************************************************
|
---|
207 | * Name :
|
---|
208 | * Purpose :
|
---|
209 | * Parameters:
|
---|
210 | * Variables :
|
---|
211 | * Result :
|
---|
212 | * Remark :
|
---|
213 | * Status :
|
---|
214 | *
|
---|
215 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
216 | *****************************************************************************/
|
---|
217 |
|
---|
218 | int WIN32API lstrcmpW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
219 | {
|
---|
220 | dprintf(("KERNEL32: lstrcmpW (%08xh-%ls, %08xh-%ls\n",
|
---|
221 | arg1,
|
---|
222 | arg1,
|
---|
223 | arg2,
|
---|
224 | arg2));
|
---|
225 | // return UniStrcmp( (UniChar*)arg1,
|
---|
226 | // (UniChar*)arg2 );
|
---|
227 | return wcscmp( (wchar_t*)arg1,
|
---|
228 | (wchar_t*)arg2 );
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | /*****************************************************************************
|
---|
233 | * Name :
|
---|
234 | * Purpose :
|
---|
235 | * Parameters:
|
---|
236 | * Variables :
|
---|
237 | * Result :
|
---|
238 | * Remark :
|
---|
239 | * Status :
|
---|
240 | *
|
---|
241 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
242 | *****************************************************************************/
|
---|
243 |
|
---|
244 | int WIN32API lstrncmpW(LPCWSTR arg1, LPCWSTR arg2, int l)
|
---|
245 | {
|
---|
246 | dprintf(("KERNEL32: OS2lstrncmpW(%08xh,%08xh,%d)\n",
|
---|
247 | arg1,
|
---|
248 | arg2,
|
---|
249 | l));
|
---|
250 |
|
---|
251 | return wcsncmp((wchar_t*)arg1,
|
---|
252 | (wchar_t*)arg2,
|
---|
253 | l);
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*****************************************************************************
|
---|
257 | * Name :
|
---|
258 | * Purpose :
|
---|
259 | * Parameters:
|
---|
260 | * Variables :
|
---|
261 | * Result :
|
---|
262 | * Remark :
|
---|
263 | * Status :
|
---|
264 | *
|
---|
265 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
266 | *****************************************************************************/
|
---|
267 |
|
---|
268 | LPSTR WIN32API lstrcpyA(LPSTR arg1, LPCSTR arg2)
|
---|
269 | {
|
---|
270 | dprintf(("KERNEL32: lstrcpy(%08xh,%s)\n",
|
---|
271 | arg1,
|
---|
272 | arg2));
|
---|
273 |
|
---|
274 | return O32_lstrcpy(arg1, arg2);
|
---|
275 | }
|
---|
276 |
|
---|
277 |
|
---|
278 | /*****************************************************************************
|
---|
279 | * Name :
|
---|
280 | * Purpose :
|
---|
281 | * Parameters:
|
---|
282 | * Variables :
|
---|
283 | * Result :
|
---|
284 | * Remark :
|
---|
285 | * Status :
|
---|
286 | *
|
---|
287 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
288 | *****************************************************************************/
|
---|
289 |
|
---|
290 | LPWSTR WIN32API lstrcpyW(LPWSTR dest, LPCWSTR src)
|
---|
291 | {
|
---|
292 | dprintf(("KERNEL32: lstrcpyW(%08xh,%08xh)",
|
---|
293 | dest,
|
---|
294 | src));
|
---|
295 |
|
---|
296 | UniStrcpy( (UniChar*)dest,
|
---|
297 | (UniChar*)src );
|
---|
298 | return dest;
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | /*****************************************************************************
|
---|
303 | * Name :
|
---|
304 | * Purpose :
|
---|
305 | * Parameters:
|
---|
306 | * Variables :
|
---|
307 | * Result :
|
---|
308 | * Remark :
|
---|
309 | * Status :
|
---|
310 | *
|
---|
311 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
312 | *****************************************************************************/
|
---|
313 |
|
---|
314 | LPSTR WIN32API lstrcpynA(LPSTR arg1, LPCSTR arg2, int arg3)
|
---|
315 | {
|
---|
316 | register LPSTR p1 = arg1;
|
---|
317 | register LPSTR p2 = (LPSTR)arg2;
|
---|
318 |
|
---|
319 | dprintf(("KERNEL32: OS2lstrcpyA(%08xh, %08xh, %08xh)\n",
|
---|
320 | arg1,
|
---|
321 | arg2,
|
---|
322 | arg3));
|
---|
323 |
|
---|
324 | //PH: looks like either \0 or arg3 terminate the copy
|
---|
325 | //return strncpy(arg1, arg2, arg3);
|
---|
326 | arg3--; // pre-decrement to avoid exceeding buffer length
|
---|
327 | // results in better code than (arg1 > 1)
|
---|
328 |
|
---|
329 | for (;*p2 && arg3; arg3--)
|
---|
330 | *p1++ = *p2++;
|
---|
331 |
|
---|
332 | *p1 = 0; //CB: copy arg-1, set end 0
|
---|
333 |
|
---|
334 | return arg1;
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | /*****************************************************************************
|
---|
339 | * Name :
|
---|
340 | * Purpose :
|
---|
341 | * Parameters:
|
---|
342 | * Variables :
|
---|
343 | * Result :
|
---|
344 | * Remark :
|
---|
345 | * Status :
|
---|
346 | *
|
---|
347 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
348 | *****************************************************************************/
|
---|
349 |
|
---|
350 | LPWSTR WIN32API lstrcpynW(LPWSTR dest, LPCWSTR src, int arg3)
|
---|
351 | {
|
---|
352 | dprintf(("KERNEL32: lstrcpynW(%08xh,%08xh,%08xh)",
|
---|
353 | dest,
|
---|
354 | src,
|
---|
355 | arg3));
|
---|
356 |
|
---|
357 | if (arg3 == 0)
|
---|
358 | return NULL;
|
---|
359 |
|
---|
360 | UniStrncpy( (UniChar*)dest,
|
---|
361 | (UniChar*)src,
|
---|
362 | arg3-1); //CB: copy arg3-1 characters
|
---|
363 | dest[arg3-1] = 0; //CB: set end
|
---|
364 | return dest;
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 | /*****************************************************************************
|
---|
369 | * Name :
|
---|
370 | * Purpose :
|
---|
371 | * Parameters:
|
---|
372 | * Variables :
|
---|
373 | * Result :
|
---|
374 | * Remark :
|
---|
375 | * Status :
|
---|
376 | *
|
---|
377 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
378 | *****************************************************************************/
|
---|
379 |
|
---|
380 | int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
|
---|
381 | {
|
---|
382 | dprintf(("KERNEL32: lstrcmpiA(%s,%s)\n",
|
---|
383 | arg1,
|
---|
384 | arg2));
|
---|
385 |
|
---|
386 | return O32_lstrcmpi(arg1, arg2);
|
---|
387 | }
|
---|
388 |
|
---|
389 |
|
---|
390 | /*****************************************************************************
|
---|
391 | * Name :
|
---|
392 | * Purpose :
|
---|
393 | * Parameters:
|
---|
394 | * Variables :
|
---|
395 | * Result :
|
---|
396 | * Remark :
|
---|
397 | * Status :
|
---|
398 | *
|
---|
399 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
400 | *****************************************************************************/
|
---|
401 |
|
---|
402 | int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
403 | {
|
---|
404 | char *astr1, *astr2;
|
---|
405 | int rc;
|
---|
406 |
|
---|
407 | dprintf(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
|
---|
408 | arg1,
|
---|
409 | arg2));
|
---|
410 |
|
---|
411 | // NOTE: This function has no equivalent in uunidef.h
|
---|
412 | astr1 = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
413 | astr2 = UnicodeToAsciiString((LPWSTR)arg2);
|
---|
414 | rc = O32_lstrcmpi(astr1, astr2);
|
---|
415 | FreeAsciiString(astr2);
|
---|
416 | FreeAsciiString(astr1);
|
---|
417 | return(rc);
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | /*****************************************************************************
|
---|
422 | * Name :
|
---|
423 | * Purpose :
|
---|
424 | * Parameters:
|
---|
425 | * Variables :
|
---|
426 | * Result :
|
---|
427 | * Remark :
|
---|
428 | * Status :
|
---|
429 | *
|
---|
430 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
431 | *****************************************************************************/
|
---|
432 |
|
---|
433 | // unilen: length of astring buffer (including 0 terminator)
|
---|
434 | // returns string length
|
---|
435 |
|
---|
436 | int WIN32API lstrcpynWtoA(LPSTR astring,
|
---|
437 | LPWSTR ustring,
|
---|
438 | int unilen)
|
---|
439 | {
|
---|
440 | int i;
|
---|
441 | int rc;
|
---|
442 | size_t uni_chars_left;
|
---|
443 | size_t out_bytes_left;
|
---|
444 | size_t num_subs;
|
---|
445 | UniChar* in_buf;
|
---|
446 | char* out_buf;
|
---|
447 |
|
---|
448 | if (ustring == NULL)
|
---|
449 | {
|
---|
450 | if (astring != NULL && unilen > 0)
|
---|
451 | astring[0] = 0;
|
---|
452 | return 0;
|
---|
453 | }
|
---|
454 |
|
---|
455 | if (astring == NULL || unilen <= 0)
|
---|
456 | return 0;
|
---|
457 |
|
---|
458 | if (getUconvObject())
|
---|
459 | {
|
---|
460 | if (unilen == 1)
|
---|
461 | {
|
---|
462 | astring[0] = 0;
|
---|
463 | return 0; //no data
|
---|
464 | }
|
---|
465 |
|
---|
466 | uni_chars_left = unilen-1; //elements
|
---|
467 | out_bytes_left = uni_chars_left; //size in bytes == elements
|
---|
468 | in_buf = (UniChar*)ustring;
|
---|
469 | out_buf = astring;
|
---|
470 | rc = UniUconvFromUcs(uconv_object,
|
---|
471 | &in_buf, &uni_chars_left,
|
---|
472 | (void**)&out_buf, &out_bytes_left,
|
---|
473 | &num_subs);
|
---|
474 |
|
---|
475 | unilen -= 1+out_bytes_left; //end + left bytes
|
---|
476 | astring[unilen] = 0; //terminate
|
---|
477 |
|
---|
478 | return unilen;
|
---|
479 |
|
---|
480 | }
|
---|
481 | else
|
---|
482 | {
|
---|
483 | /* idiots unicode conversion :) */
|
---|
484 | for (i = 0; i < unilen-1; i++)
|
---|
485 | {
|
---|
486 | astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
|
---|
487 | if (ustring[i] == 0) return i; //asta la vista, baby
|
---|
488 | }
|
---|
489 |
|
---|
490 | astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
|
---|
491 |
|
---|
492 | return(unilen-1);
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 |
|
---|
497 | /*****************************************************************************
|
---|
498 | * Name :
|
---|
499 | * Purpose :
|
---|
500 | * Parameters:
|
---|
501 | * Variables :
|
---|
502 | * Result :
|
---|
503 | * Remark :
|
---|
504 | * Status :
|
---|
505 | *
|
---|
506 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
507 | *****************************************************************************/
|
---|
508 |
|
---|
509 | // asciilen: max length of unicode buffer (including end 0)
|
---|
510 |
|
---|
511 | int WIN32API lstrcpynAtoW(LPWSTR unicode,
|
---|
512 | LPSTR ascii,
|
---|
513 | int asciilen)
|
---|
514 | {
|
---|
515 | int rc;
|
---|
516 | int i;
|
---|
517 | size_t uni_chars_left;
|
---|
518 | size_t in_bytes_left;
|
---|
519 | size_t num_subs;
|
---|
520 | UniChar* out_buf;
|
---|
521 | char* in_buf;
|
---|
522 |
|
---|
523 | dprintf(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh)\n",
|
---|
524 | ascii,
|
---|
525 | unicode));
|
---|
526 |
|
---|
527 | //CB: no input, set at least terminator
|
---|
528 | if (ascii == NULL)
|
---|
529 | {
|
---|
530 | if (unicode != NULL && asciilen > 0) unicode[0] = 0;
|
---|
531 | return 0;
|
---|
532 | }
|
---|
533 |
|
---|
534 | if (unicode == NULL || asciilen <= 0)
|
---|
535 | return 0; //nothing to do
|
---|
536 |
|
---|
537 | if (getUconvObject())
|
---|
538 | {
|
---|
539 | if (asciilen == 1)
|
---|
540 | {
|
---|
541 | unicode[0] = 0;
|
---|
542 | return 0;
|
---|
543 | }
|
---|
544 |
|
---|
545 | in_buf = ascii;
|
---|
546 | in_bytes_left = asciilen-1; //buffer size in bytes
|
---|
547 | out_buf = (UniChar*)unicode;
|
---|
548 |
|
---|
549 | uni_chars_left = in_bytes_left; //elements
|
---|
550 |
|
---|
551 | rc = UniUconvToUcs( uconv_object,
|
---|
552 | (void**)&in_buf, &in_bytes_left,
|
---|
553 | &out_buf, &uni_chars_left,
|
---|
554 | &num_subs );
|
---|
555 |
|
---|
556 | unicode[asciilen-1-in_bytes_left] = 0;
|
---|
557 |
|
---|
558 | //if (rc != ULS_SUCCESS && in_bytes_left > 0) //CB: never the case during my tests
|
---|
559 | // dprintf(("KERNEL32: AsciiToUnicode failed, %d bytes left!\n",in_bytes_left));
|
---|
560 | return asciilen - 1;
|
---|
561 | }
|
---|
562 | else
|
---|
563 | { //poor man's conversion
|
---|
564 |
|
---|
565 | for(i = 0;i < asciilen-1;i++)
|
---|
566 | {
|
---|
567 | unicode[i] = ascii[i];
|
---|
568 | if (ascii[i] == 0)
|
---|
569 | return i-1; //work done
|
---|
570 | }
|
---|
571 |
|
---|
572 | unicode[asciilen-1] = 0;
|
---|
573 | return asciilen-1;
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 |
|
---|
578 | /*****************************************************************************
|
---|
579 | * Name :
|
---|
580 | * Purpose : Converts unicode string to ascii string
|
---|
581 | * Parameters:
|
---|
582 | * Variables :
|
---|
583 | * Result : returns length of ascii string
|
---|
584 | * Remark :
|
---|
585 | * Status :
|
---|
586 | *
|
---|
587 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
588 | *****************************************************************************/
|
---|
589 |
|
---|
590 | LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPWSTR unicode)
|
---|
591 | {
|
---|
592 | if (unicode == NULL)
|
---|
593 | {
|
---|
594 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
595 | return NULL;
|
---|
596 | }
|
---|
597 |
|
---|
598 | if (unicode == NULL)
|
---|
599 | return NULL; /* garbage in, garbage out ! */
|
---|
600 |
|
---|
601 | /* forward to function with len parameter */
|
---|
602 | lstrcpynWtoA(ascii,
|
---|
603 | unicode,
|
---|
604 | UniStrlen((UniChar*)unicode)+1); //end included
|
---|
605 |
|
---|
606 | return ascii;
|
---|
607 | }
|
---|
608 |
|
---|
609 |
|
---|
610 | /*****************************************************************************
|
---|
611 | * Name :
|
---|
612 | * Purpose : Copies the full string from ascii to unicode
|
---|
613 | * Parameters:
|
---|
614 | * Variables :
|
---|
615 | * Result :
|
---|
616 | * Remark :
|
---|
617 | * Status :
|
---|
618 | *
|
---|
619 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
620 | *****************************************************************************/
|
---|
621 |
|
---|
622 | LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPSTR ascii)
|
---|
623 | {
|
---|
624 | /* achimha for security, strlen might trap if garbage in */
|
---|
625 | /* @@@PH 98/06/07 */
|
---|
626 | if (ascii == NULL)
|
---|
627 | {
|
---|
628 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
629 | return NULL;
|
---|
630 | }
|
---|
631 |
|
---|
632 | if (unicode == NULL)
|
---|
633 | return NULL; /* garbage in, garbage out ! */
|
---|
634 |
|
---|
635 | /* forward to call with length parameter */
|
---|
636 | lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
|
---|
637 | return (unicode);
|
---|
638 | }
|
---|
639 |
|
---|
640 |
|
---|
641 |
|
---|
642 |
|
---|
643 | /*****************************************************************************
|
---|
644 | * Name :
|
---|
645 | * Purpose :
|
---|
646 | * Parameters:
|
---|
647 | * Variables :
|
---|
648 | * Result :
|
---|
649 | * Remark :
|
---|
650 | * Status :
|
---|
651 | *
|
---|
652 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
653 | *****************************************************************************/
|
---|
654 |
|
---|
655 | LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
|
---|
656 | {
|
---|
657 | LPVOID p = HeapAlloc( heap, flags, size );
|
---|
658 | if (!p)
|
---|
659 | {
|
---|
660 | dprintf(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
|
---|
661 | heap,
|
---|
662 | flags,
|
---|
663 | size));
|
---|
664 | }
|
---|
665 | return p;
|
---|
666 | }
|
---|
667 |
|
---|
668 |
|
---|
669 | /*****************************************************************************
|
---|
670 | * Name :
|
---|
671 | * Purpose :
|
---|
672 | * Parameters:
|
---|
673 | * Variables :
|
---|
674 | * Result :
|
---|
675 | * Remark :
|
---|
676 | * Status :
|
---|
677 | *
|
---|
678 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
679 | *****************************************************************************/
|
---|
680 |
|
---|
681 | LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
|
---|
682 | {
|
---|
683 | LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
|
---|
684 | if (!p)
|
---|
685 | {
|
---|
686 | dprintf(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
|
---|
687 | heap,
|
---|
688 | flags,
|
---|
689 | lpMem,
|
---|
690 | size));
|
---|
691 | }
|
---|
692 | return p;
|
---|
693 | }
|
---|
694 |
|
---|
695 |
|
---|
696 | /*****************************************************************************
|
---|
697 | * Name :
|
---|
698 | * Purpose :
|
---|
699 | * Parameters:
|
---|
700 | * Variables :
|
---|
701 | * Result :
|
---|
702 | * Remark :
|
---|
703 | * Status :
|
---|
704 | *
|
---|
705 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
706 | *****************************************************************************/
|
---|
707 |
|
---|
708 | LPVOID WIN32API HEAP_malloc(DWORD size )
|
---|
709 | {
|
---|
710 | LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
|
---|
711 | if (!p)
|
---|
712 | {
|
---|
713 | dprintf(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
|
---|
714 | size));
|
---|
715 | }
|
---|
716 | return p;
|
---|
717 | }
|
---|
718 |
|
---|
719 |
|
---|
720 | /*****************************************************************************
|
---|
721 | * Name :
|
---|
722 | * Purpose :
|
---|
723 | * Parameters:
|
---|
724 | * Variables :
|
---|
725 | * Result :
|
---|
726 | * Remark :
|
---|
727 | * Status :
|
---|
728 | *
|
---|
729 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
730 | *****************************************************************************/
|
---|
731 |
|
---|
732 | LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
|
---|
733 | {
|
---|
734 | LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
|
---|
735 | if (!p)
|
---|
736 | {
|
---|
737 | dprintf(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
|
---|
738 | lpMem,
|
---|
739 | size));
|
---|
740 | }
|
---|
741 | return p;
|
---|
742 | }
|
---|
743 |
|
---|
744 |
|
---|
745 | /*****************************************************************************
|
---|
746 | * Name :
|
---|
747 | * Purpose :
|
---|
748 | * Parameters:
|
---|
749 | * Variables :
|
---|
750 | * Result :
|
---|
751 | * Remark :
|
---|
752 | * Status :
|
---|
753 | *
|
---|
754 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
755 | *****************************************************************************/
|
---|
756 |
|
---|
757 | VOID WIN32API HEAP_free(LPVOID lpMem)
|
---|
758 | {
|
---|
759 | dprintf(("KERNEL32: HEAP_free(%08xh)\n",
|
---|
760 | lpMem));
|
---|
761 |
|
---|
762 | HeapFree( GetProcessHeap(), 0, lpMem);
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | /*****************************************************************************
|
---|
767 | * Name :
|
---|
768 | * Purpose :
|
---|
769 | * Parameters:
|
---|
770 | * Variables :
|
---|
771 | * Result :
|
---|
772 | * Remark :
|
---|
773 | * Status :
|
---|
774 | *
|
---|
775 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
776 | *****************************************************************************/
|
---|
777 |
|
---|
778 | LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
779 | {
|
---|
780 | LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
|
---|
781 | strcpy( p, str );
|
---|
782 | return p;
|
---|
783 | }
|
---|
784 |
|
---|
785 |
|
---|
786 | /*****************************************************************************
|
---|
787 | * Name :
|
---|
788 | * Purpose :
|
---|
789 | * Parameters:
|
---|
790 | * Variables :
|
---|
791 | * Result :
|
---|
792 | * Remark :
|
---|
793 | * Status :
|
---|
794 | *
|
---|
795 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
796 | *****************************************************************************/
|
---|
797 |
|
---|
798 | LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
799 | {
|
---|
800 | INT len = lstrlenW(str) + 1;
|
---|
801 | LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
|
---|
802 | lstrcpyW( p, str );
|
---|
803 | return p;
|
---|
804 | }
|
---|
805 |
|
---|
806 |
|
---|
807 | /*****************************************************************************
|
---|
808 | * Name :
|
---|
809 | * Purpose :
|
---|
810 | * Parameters:
|
---|
811 | * Variables :
|
---|
812 | * Result :
|
---|
813 | * Remark :
|
---|
814 | * Status :
|
---|
815 | *
|
---|
816 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
817 | *****************************************************************************/
|
---|
818 |
|
---|
819 | LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
820 | {
|
---|
821 | LPWSTR ret;
|
---|
822 |
|
---|
823 | if (!str) return NULL;
|
---|
824 | ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
|
---|
825 | lstrcpyAtoW( ret, (LPSTR)str );
|
---|
826 | return ret;
|
---|
827 | }
|
---|
828 |
|
---|
829 |
|
---|
830 | /*****************************************************************************
|
---|
831 | * Name :
|
---|
832 | * Purpose :
|
---|
833 | * Parameters:
|
---|
834 | * Variables :
|
---|
835 | * Result :
|
---|
836 | * Remark :
|
---|
837 | * Status :
|
---|
838 | *
|
---|
839 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
840 | *****************************************************************************/
|
---|
841 |
|
---|
842 | LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
843 | {
|
---|
844 | LPSTR ret;
|
---|
845 |
|
---|
846 | if (!str) return NULL;
|
---|
847 | ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
|
---|
848 | lstrcpyWtoA( ret, (LPWSTR)str );
|
---|
849 | return ret;
|
---|
850 | }
|
---|
851 |
|
---|
852 |
|
---|
853 | /*****************************************************************************
|
---|
854 | * Name : WideCharToLocal
|
---|
855 | * Purpose : similar lstrcpyWtoA, should handle codepages properly
|
---|
856 | * Parameters:
|
---|
857 | * Variables :
|
---|
858 | * Result : strlen of the destination string
|
---|
859 | * Remark :
|
---|
860 | * Status :
|
---|
861 | *
|
---|
862 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
863 | *****************************************************************************/
|
---|
864 |
|
---|
865 | INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
|
---|
866 | {
|
---|
867 | dprintf(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
|
---|
868 | pLocal,
|
---|
869 | pWide,
|
---|
870 | dwChars));
|
---|
871 |
|
---|
872 | *pLocal = 0;
|
---|
873 | WideCharToMultiByte(CP_ACP,
|
---|
874 | 0,
|
---|
875 | pWide,
|
---|
876 | -1,
|
---|
877 | pLocal,
|
---|
878 | dwChars,
|
---|
879 | NULL,
|
---|
880 | NULL);
|
---|
881 |
|
---|
882 | return strlen(pLocal);
|
---|
883 | }
|
---|
884 |
|
---|
885 |
|
---|
886 | /*****************************************************************************
|
---|
887 | * Name : LocalToWideChar
|
---|
888 | * Purpose : similar lstrcpyAtoW, should handle codepages properly
|
---|
889 | * Parameters:
|
---|
890 | * Variables :
|
---|
891 | * Result : strlen of the destination string
|
---|
892 | * Remark :
|
---|
893 | * Status :
|
---|
894 | *
|
---|
895 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
896 | *****************************************************************************/
|
---|
897 |
|
---|
898 | INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
|
---|
899 | {
|
---|
900 | *pWide = 0;
|
---|
901 |
|
---|
902 | dprintf(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
|
---|
903 | pLocal,
|
---|
904 | pWide,
|
---|
905 | dwChars));
|
---|
906 |
|
---|
907 | MultiByteToWideChar(CP_ACP,
|
---|
908 | 0,
|
---|
909 | pLocal,
|
---|
910 | -1,
|
---|
911 | pWide,
|
---|
912 | dwChars);
|
---|
913 |
|
---|
914 | return lstrlenW(pWide);
|
---|
915 | }
|
---|
916 |
|
---|
917 |
|
---|
918 |
|
---|
919 |
|
---|
920 |
|
---|
921 |
|
---|
922 | #if 0
|
---|
923 |
|
---|
924 |
|
---|
925 | /*****************************************************************************
|
---|
926 | * Name :
|
---|
927 | * Purpose :
|
---|
928 | * Parameters:
|
---|
929 | * Variables :
|
---|
930 | * Result :
|
---|
931 | * Remark :
|
---|
932 | * Status :
|
---|
933 | *
|
---|
934 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
935 | *****************************************************************************/
|
---|
936 |
|
---|
937 | // Converts unicode string to ascii string
|
---|
938 | // returns pointer to ascii string
|
---|
939 | char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
|
---|
940 | {
|
---|
941 | char *astring;
|
---|
942 |
|
---|
943 | if(ustring == NULL) return(NULL);
|
---|
944 |
|
---|
945 | astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
|
---|
946 | UnicodeToAscii( ustring, astring );
|
---|
947 | return(astring);
|
---|
948 | }
|
---|
949 |
|
---|
950 |
|
---|
951 | /*****************************************************************************
|
---|
952 | * Name :
|
---|
953 | * Purpose :
|
---|
954 | * Parameters:
|
---|
955 | * Variables :
|
---|
956 | * Result :
|
---|
957 | * Remark :
|
---|
958 | * Status :
|
---|
959 | *
|
---|
960 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
961 | *****************************************************************************/
|
---|
962 |
|
---|
963 | // Converts ascii string to unicode string
|
---|
964 | // returns pointer to unicode string
|
---|
965 | WCHAR * WIN32API AsciiToUnicodeString(char *astring)
|
---|
966 | {
|
---|
967 | WCHAR *ustring;
|
---|
968 |
|
---|
969 | if(astring == NULL)
|
---|
970 | return(NULL);
|
---|
971 |
|
---|
972 | ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
|
---|
973 | AsciiToUnicode( astring, ustring );
|
---|
974 | return(ustring);
|
---|
975 | }
|
---|
976 |
|
---|
977 | #endif
|
---|
978 |
|
---|
979 |
|
---|
980 |
|
---|