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

Last change on this file since 1570 was 1484, checked in by phaller, 26 years ago

Fix: console (unicode) updates

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