source: trunk/src/kernel32/heapstring.cpp@ 1640

Last change on this file since 1640 was 1605, checked in by sandervl, 26 years ago

EBs fixes + added export for msacm32

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