- Update address of Free Software Foundation.
[reactos.git] / reactos / dll / win32 / gdi32 / misc / heap.c
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 * $Id:
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS GDI32
21 * PURPOSE:
22 * FILE: lib/gdi32/misc/heap.c
23 * PROGRAMER:
24 * REVISION HISTORY:
25 * NOTES:
26 */
27
28 #include "precomp.h"
29 #include <debug.h>
30
31 // global variables in a dll are process-global
32 HANDLE hProcessHeap = NULL;
33
34
35 PVOID
36 HEAP_alloc ( DWORD len )
37 {
38 /* make sure hProcessHeap gets initialized by GdiProcessSetup before we get here */
39 assert(hProcessHeap);
40 return RtlAllocateHeap ( hProcessHeap, 0, len );
41 }
42
43 NTSTATUS
44 HEAP_strdupA2W ( LPWSTR* ppszW, LPCSTR lpszA )
45 {
46 ULONG len;
47 NTSTATUS Status;
48
49 *ppszW = NULL;
50 if ( !lpszA )
51 return STATUS_SUCCESS;
52 len = lstrlenA(lpszA);
53
54 *ppszW = HEAP_alloc ( (len+1) * sizeof(WCHAR) );
55 if ( !*ppszW )
56 return STATUS_NO_MEMORY;
57 Status = RtlMultiByteToUnicodeN ( *ppszW, len*sizeof(WCHAR), NULL, (PCHAR)lpszA, len );
58 (*ppszW)[len] = L'\0';
59 return Status;
60 }
61
62
63 VOID
64 HEAP_free ( LPVOID memory )
65 {
66 /* make sure hProcessHeap gets initialized by GdiProcessSetup before we get here */
67 assert(hProcessHeap);
68
69 RtlFreeHeap ( hProcessHeap, 0, memory );
70 }