xref: /reactos/win32ss/gdi/gdi32/misc/heap.c (revision 1734f297)
1 /*
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17 /*
18  * COPYRIGHT:        See COPYING in the top level directory
19  * PROJECT:          ReactOS GDI32
20  * PURPOSE:
21  * FILE:             win32ss/gdi/gdi32/misc/heap.c
22  * PROGRAMER:
23  * REVISION HISTORY:
24  * NOTES:
25  */
26 
27 #include <precomp.h>
28 #include <debug.h>
29 
30 // global variables in a dll are process-global
31 HANDLE hProcessHeap = NULL;
32 
33 
34 PVOID
35 HEAP_alloc ( DWORD len )
36 {
37     /* make sure hProcessHeap gets initialized by GdiProcessSetup before we get here */
38     assert(hProcessHeap);
39     return RtlAllocateHeap ( hProcessHeap, 0, len );
40 }
41 
42 NTSTATUS
43 HEAP_strdupA2W ( LPWSTR* ppszW, LPCSTR lpszA )
44 {
45     ULONG len;
46     NTSTATUS Status;
47 
48     *ppszW = NULL;
49     if ( !lpszA )
50         return STATUS_SUCCESS;
51     len = lstrlenA(lpszA);
52 
53     *ppszW = HEAP_alloc ( (len+1) * sizeof(WCHAR) );
54     if ( !*ppszW )
55         return STATUS_NO_MEMORY;
56     Status = RtlMultiByteToUnicodeN ( *ppszW, len*sizeof(WCHAR), NULL, (PCHAR)lpszA, len );
57     (*ppszW)[len] = L'\0';
58     return Status;
59 }
60 
61 
62 VOID
63 HEAP_free ( LPVOID memory )
64 {
65     /* make sure hProcessHeap gets initialized by GdiProcessSetup before we get here */
66     assert(hProcessHeap);
67 
68     RtlFreeHeap ( hProcessHeap, 0, memory );
69 }
70