Added support in winebuild for resolving function imports (-sym option).
[wine/multimedia.git] / dlls / crtdll / memory.c
blobb6192e047fb7dc909cd3174ea9b668af3cfb8d09
1 /*
2 * CRTDLL memory functions
3 *
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * Implementation Notes:
10 * MT Safe.
13 #include "crtdll.h"
16 DEFAULT_DEBUG_CHANNEL(crtdll);
18 static new_handler_type new_handler;
21 /*********************************************************************
22 * new (CRTDLL.001)
24 * Allocate memory.
26 LPVOID __cdecl CRTDLL_new(DWORD size)
28 VOID* result;
29 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
30 (*new_handler)();
31 return result;
35 /*********************************************************************
36 * delete (CRTDLL.002)
38 * Free memory created with new.
40 VOID __cdecl CRTDLL_delete(LPVOID ptr)
42 HeapFree(GetProcessHeap(),0,ptr);
46 /*********************************************************************
47 * set_new_handler(CRTDLL.003)
49 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
51 new_handler_type old_handler = new_handler;
52 new_handler = func;
53 return old_handler;
57 /*********************************************************************
58 * _expand (CRTDLL.088)
60 * Increase the size of a block of memory allocated with malloc()
61 * or realloc().
63 LPVOID __cdecl CRTDLL__expand(LPVOID ptr, INT size)
65 return HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, ptr, size );
69 /*********************************************************************
70 * _msize (CRTDLL.234)
72 * Return the actual used size of an allocated block of memory.
75 LONG __cdecl CRTDLL__msize(LPVOID mem)
77 LONG size = HeapSize(GetProcessHeap(),0,mem);
78 if (size == -1)
80 WARN(":Probably called with non wine-allocated memory, ret = -1\n");
81 /* At least the win98/nt crtdlls also return -1 in this case */
83 return size;
87 /*********************************************************************
88 * calloc (CRTDLL.350)
90 * Allocate memory from the heap and initialise it to zero.
92 LPVOID __cdecl CRTDLL_calloc(DWORD size, DWORD count)
94 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
98 /*********************************************************************
99 * free (CRTDLL.375)
101 * Free a block of memory allocated with malloc()
103 VOID __cdecl CRTDLL_free(LPVOID ptr)
105 HeapFree(GetProcessHeap(),0,ptr);
109 /*********************************************************************
110 * malloc (CRTDLL.424)
112 * Alocate memory from the heap.
114 LPVOID __cdecl CRTDLL_malloc(DWORD size)
116 LPVOID ret = HeapAlloc(GetProcessHeap(),0,size);
117 if (!ret)
118 __CRTDLL__set_errno(GetLastError());
119 return ret;
123 /*********************************************************************
124 * realloc (CRTDLL.444)
126 * Resize a block of memory allocated with malloc() or realloc().
128 LPVOID __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
130 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );