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

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

check for null pointers in lstrcmpA

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