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

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

Heap fixes + dll load bugfixes

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