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

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

Added new logging feature

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