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

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

Changed definition of lstrcpy(n)AtoW/WtoA + CreateProcessA logging change

File size: 24.4 KB
Line 
1/* $Id: heapstring.cpp,v 1.20 1999-12-05 10:02:30 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
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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("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 dprintf2(("KERNEL32: lstrcmpiA(%s,%s)\n",
445 arg1,
446 arg2));
447
448 if(arg1 == NULL)
449 return -1;
450
451 if(arg2 == NULL)
452 return 1;
453
454 return O32_lstrcmpi(arg1, arg2);
455}
456
457
458/*****************************************************************************
459 * Name :
460 * Purpose :
461 * Parameters:
462 * Variables :
463 * Result :
464 * Remark :
465 * Status :
466 *
467 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
468 *****************************************************************************/
469
470int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
471{
472 char *astr1, *astr2;
473 int rc;
474
475 dprintf2(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
476 arg1,
477 arg2));
478
479 if(arg1 == NULL)
480 return -1;
481
482 if(arg2 == NULL)
483 return 1;
484
485 // NOTE: This function has no equivalent in uunidef.h
486 astr1 = UnicodeToAsciiString((LPWSTR)arg1);
487 astr2 = UnicodeToAsciiString((LPWSTR)arg2);
488 rc = lstrcmpiA(astr1, astr2);
489 FreeAsciiString(astr2);
490 FreeAsciiString(astr1);
491 return(rc);
492}
493
494
495/*****************************************************************************
496 * Name :
497 * Purpose :
498 * Parameters:
499 * Variables :
500 * Result :
501 * Remark :
502 * Status :
503 *
504 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
505 *****************************************************************************/
506
507// unilen: length of astring buffer (including 0 terminator)
508// returns string length
509
510int WIN32API lstrcpynWtoA(LPSTR astring,
511 LPCWSTR ustring,
512 int unilen)
513{
514 int i;
515 int rc;
516 size_t uni_chars_left;
517 size_t out_bytes_left;
518 size_t num_subs;
519 UniChar* in_buf;
520 char* out_buf;
521
522 if (ustring == NULL)
523 {
524 if (astring != NULL && unilen > 0)
525 astring[0] = 0;
526 return 0;
527 }
528
529 if (astring == NULL || unilen <= 0)
530 return 0;
531
532 if (getUconvObject())
533 {
534 if (unilen == 1)
535 {
536 astring[0] = 0;
537 return 0; //no data
538 }
539
540 //SvL: Determine length of unicode string
541 uni_chars_left = UniStrlen((UniChar*)ustring)+1;
542 uni_chars_left = min(uni_chars_left, unilen);
543 unilen = uni_chars_left;
544
545 out_bytes_left = uni_chars_left; //size in bytes == elements
546 in_buf = (UniChar*)ustring;
547 out_buf = astring;
548 rc = UniUconvFromUcs(uconv_object,
549 &in_buf, &uni_chars_left,
550 (void**)&out_buf, &out_bytes_left,
551 &num_subs);
552
553 unilen -= 1+out_bytes_left; //end + left bytes
554 astring[unilen] = 0; //terminate
555
556 return unilen;
557
558 }
559 else
560 {
561 /* idiots unicode conversion :) */
562 for (i = 0; i < unilen-1; i++)
563 {
564 astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
565 if (ustring[i] == 0) return i; //asta la vista, baby
566 }
567
568 astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
569
570 return(unilen-1);
571 }
572}
573
574
575/*****************************************************************************
576 * Name :
577 * Purpose :
578 * Parameters:
579 * Variables :
580 * Result :
581 * Remark :
582 * Status :
583 *
584 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
585 *****************************************************************************/
586
587// asciilen: max length of unicode buffer (including end 0)
588// @@@PH 0 termination is NOT necessarily included !
589int WIN32API lstrcpynAtoW(LPWSTR unicode,
590 LPCSTR ascii,
591 int asciilen)
592{
593 int rc;
594 int i;
595 size_t uni_chars_left;
596 size_t in_bytes_left;
597 size_t num_subs;
598 UniChar* out_buf;
599 char* in_buf;
600
601 dprintf2(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
602 ascii,
603 unicode,
604 asciilen));
605
606 //CB: no input, set at least terminator
607 if (ascii == NULL)
608 {
609 if (unicode != NULL && asciilen > 0) unicode[0] = 0;
610 return 0;
611 }
612
613 if (unicode == NULL || asciilen <= 0)
614 return 0; //nothing to do
615
616 if (getUconvObject())
617 {
618 //@@@PH what's this?
619 if ((asciilen == 1) && (*ascii == '\0') )
620 {
621 unicode[0] = 0;
622 return 0;
623 }
624
625 in_buf = (LPSTR)ascii;
626
627 //@@@PH what's this?
628 //in_bytes_left = asciilen-1; //buffer size in bytes
629
630 //SvL: Determine length of ascii string
631 in_bytes_left = strlen(in_buf)+1;
632 in_bytes_left = min(in_bytes_left, asciilen); //buffer size in bytes
633
634 out_buf = (UniChar*)unicode;
635
636 uni_chars_left = in_bytes_left; //elements
637
638 rc = UniUconvToUcs( uconv_object,
639 (void**)&in_buf, &in_bytes_left,
640 &out_buf, &uni_chars_left,
641 &num_subs );
642
643 //@@@PH what's this?
644 //unicode[asciilen-1-in_bytes_left] = 0;
645
646 //@@@PH what's this?
647 //return asciilen - 1;
648 return asciilen;
649 }
650 else
651 { //poor man's conversion
652
653// for(i = 0;i < asciilen-1;i++)
654 for(i = 0;i < asciilen;i++)
655 {
656 unicode[i] = ascii[i];
657 if (ascii[i] == 0)
658 //return i-1; //work done
659 return i; //work done
660 }
661
662// unicode[asciilen-1] = 0;
663// return asciilen-1;
664 return asciilen;
665 }
666}
667
668
669/*****************************************************************************
670 * Name :
671 * Purpose : Converts unicode string to ascii string
672 * Parameters:
673 * Variables :
674 * Result : returns length of ascii string
675 * Remark :
676 * Status :
677 *
678 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
679 *****************************************************************************/
680
681LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
682{
683 //@@@PH huh? wuz dat?
684 if (unicode == NULL)
685 {
686 if (unicode != NULL) ((LPWSTR)unicode)[0] = 0; //CB: set at least end
687 return NULL;
688 }
689
690 if (unicode == NULL)
691 return NULL; /* garbage in, garbage out ! */
692
693 /* forward to function with len parameter */
694 lstrcpynWtoA(ascii,
695 unicode,
696 UniStrlen((UniChar*)unicode)+1); //end included
697
698 return ascii;
699}
700
701
702/*****************************************************************************
703 * Name :
704 * Purpose : Copies the full string from ascii to unicode
705 * Parameters:
706 * Variables :
707 * Result :
708 * Remark :
709 * Status :
710 *
711 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
712 *****************************************************************************/
713
714LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
715{
716 /* achimha for security, strlen might trap if garbage in */
717 /* @@@PH 98/06/07 */
718 if (ascii == NULL)
719 {
720 if (unicode != NULL) unicode[0] = 0; //CB: set at least end
721 return NULL;
722 }
723
724 if (unicode == NULL)
725 return NULL; /* garbage in, garbage out ! */
726
727 /* forward to call with length parameter */
728 lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
729 return (unicode);
730}
731
732
733
734
735/*****************************************************************************
736 * Name :
737 * Purpose :
738 * Parameters:
739 * Variables :
740 * Result :
741 * Remark :
742 * Status :
743 *
744 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
745 *****************************************************************************/
746
747LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
748{
749 LPVOID p = HeapAlloc( heap, flags, size );
750 if (!p)
751 {
752 dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
753 heap,
754 flags,
755 size));
756 }
757 return p;
758}
759
760
761/*****************************************************************************
762 * Name :
763 * Purpose :
764 * Parameters:
765 * Variables :
766 * Result :
767 * Remark :
768 * Status :
769 *
770 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
771 *****************************************************************************/
772
773LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
774{
775 LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
776 if (!p)
777 {
778 dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
779 heap,
780 flags,
781 lpMem,
782 size));
783 }
784 return p;
785}
786
787
788/*****************************************************************************
789 * Name :
790 * Purpose :
791 * Parameters:
792 * Variables :
793 * Result :
794 * Remark :
795 * Status :
796 *
797 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
798 *****************************************************************************/
799
800LPVOID WIN32API HEAP_malloc(DWORD size )
801{
802 LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
803 if (!p)
804 {
805 dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
806 size));
807 }
808 return p;
809}
810
811
812/*****************************************************************************
813 * Name :
814 * Purpose :
815 * Parameters:
816 * Variables :
817 * Result :
818 * Remark :
819 * Status :
820 *
821 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
822 *****************************************************************************/
823
824LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
825{
826 LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
827 if (!p)
828 {
829 dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
830 lpMem,
831 size));
832 }
833 return p;
834}
835
836
837/*****************************************************************************
838 * Name :
839 * Purpose :
840 * Parameters:
841 * Variables :
842 * Result :
843 * Remark :
844 * Status :
845 *
846 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
847 *****************************************************************************/
848
849VOID WIN32API HEAP_free(LPVOID lpMem)
850{
851 dprintf2(("KERNEL32: HEAP_free(%08xh)\n",
852 lpMem));
853
854 HeapFree( GetProcessHeap(), 0, lpMem);
855}
856
857
858/*****************************************************************************
859 * Name :
860 * Purpose :
861 * Parameters:
862 * Variables :
863 * Result :
864 * Remark :
865 * Status :
866 *
867 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
868 *****************************************************************************/
869
870LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
871{
872 LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
873 strcpy( p, str );
874 return p;
875}
876
877
878/*****************************************************************************
879 * Name :
880 * Purpose :
881 * Parameters:
882 * Variables :
883 * Result :
884 * Remark :
885 * Status :
886 *
887 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
888 *****************************************************************************/
889
890LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
891{
892 INT len = lstrlenW(str) + 1;
893 LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
894 lstrcpyW( p, str );
895 return p;
896}
897
898
899/*****************************************************************************
900 * Name :
901 * Purpose :
902 * Parameters:
903 * Variables :
904 * Result :
905 * Remark :
906 * Status :
907 *
908 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
909 *****************************************************************************/
910
911LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
912{
913 LPWSTR ret;
914
915 if (!str) return NULL;
916 ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
917 lstrcpyAtoW( ret, (LPSTR)str );
918 return ret;
919}
920
921
922/*****************************************************************************
923 * Name :
924 * Purpose :
925 * Parameters:
926 * Variables :
927 * Result :
928 * Remark :
929 * Status :
930 *
931 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
932 *****************************************************************************/
933
934LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
935{
936 LPSTR ret;
937
938 if (!str) return NULL;
939 ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
940 lstrcpyWtoA( ret, (LPWSTR)str );
941 return ret;
942}
943
944
945/*****************************************************************************
946 * Name : WideCharToLocal
947 * Purpose : similar lstrcpyWtoA, should handle codepages properly
948 * Parameters:
949 * Variables :
950 * Result : strlen of the destination string
951 * Remark :
952 * Status :
953 *
954 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
955 *****************************************************************************/
956
957INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
958{
959 dprintf2(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
960 pLocal,
961 pWide,
962 dwChars));
963
964 *pLocal = 0;
965 WideCharToMultiByte(CP_ACP,
966 0,
967 pWide,
968 -1,
969 pLocal,
970 dwChars,
971 NULL,
972 NULL);
973
974 return strlen(pLocal);
975}
976
977
978/*****************************************************************************
979 * Name : LocalToWideChar
980 * Purpose : similar lstrcpyAtoW, should handle codepages properly
981 * Parameters:
982 * Variables :
983 * Result : strlen of the destination string
984 * Remark :
985 * Status :
986 *
987 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
988 *****************************************************************************/
989
990INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
991{
992 *pWide = 0;
993
994 dprintf2(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
995 pLocal,
996 pWide,
997 dwChars));
998
999 MultiByteToWideChar(CP_ACP,
1000 0,
1001 pLocal,
1002 -1,
1003 pWide,
1004 dwChars);
1005
1006 return lstrlenW(pWide);
1007}
1008
1009
1010
1011
1012
1013
1014#if 0
1015
1016
1017/*****************************************************************************
1018 * Name :
1019 * Purpose :
1020 * Parameters:
1021 * Variables :
1022 * Result :
1023 * Remark :
1024 * Status :
1025 *
1026 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1027 *****************************************************************************/
1028
1029// Converts unicode string to ascii string
1030// returns pointer to ascii string
1031char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
1032{
1033 char *astring;
1034
1035 if(ustring == NULL) return(NULL);
1036
1037 astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
1038 UnicodeToAscii( ustring, astring );
1039 return(astring);
1040}
1041
1042
1043/*****************************************************************************
1044 * Name :
1045 * Purpose :
1046 * Parameters:
1047 * Variables :
1048 * Result :
1049 * Remark :
1050 * Status :
1051 *
1052 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1053 *****************************************************************************/
1054
1055// Converts ascii string to unicode string
1056// returns pointer to unicode string
1057WCHAR * WIN32API AsciiToUnicodeString(char *astring)
1058{
1059 WCHAR *ustring;
1060
1061 if(astring == NULL)
1062 return(NULL);
1063
1064 ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
1065 AsciiToUnicode( astring, ustring );
1066 return(ustring);
1067}
1068
1069#endif
1070
1071
1072
Note: See TracBrowser for help on using the repository browser.