[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / apibuf.c
1 /*
2 * Copyright 2002 Andriy Palamarchuk
3 *
4 * Net API buffer calls
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "netapi32.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
24
25 /************************************************************
26 * NetApiBufferAllocate (NETAPI32.@)
27 */
28 NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID* Buffer)
29 {
30 TRACE("(%d, %p)\n", ByteCount, Buffer);
31
32 if (Buffer == NULL) return ERROR_INVALID_PARAMETER;
33 *Buffer = HeapAlloc(GetProcessHeap(), 0, ByteCount);
34 if (*Buffer)
35 return NERR_Success;
36 else
37 return GetLastError();
38 }
39
40 /************************************************************
41 * NetApiBufferFree (NETAPI32.@)
42 */
43 NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
44 {
45 TRACE("(%p)\n", Buffer);
46 HeapFree(GetProcessHeap(), 0, Buffer);
47 return NERR_Success;
48 }
49
50 /************************************************************
51 * NetApiBufferReallocate (NETAPI32.@)
52 */
53 NET_API_STATUS WINAPI NetApiBufferReallocate(LPVOID OldBuffer, DWORD NewByteCount,
54 LPVOID* NewBuffer)
55 {
56 TRACE("(%p, %d, %p)\n", OldBuffer, NewByteCount, NewBuffer);
57 if (NewByteCount)
58 {
59 if (OldBuffer)
60 *NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount);
61 else
62 *NewBuffer = HeapAlloc(GetProcessHeap(), 0, NewByteCount);
63 return *NewBuffer ? NERR_Success : GetLastError();
64 }
65 else
66 {
67 if (!HeapFree(GetProcessHeap(), 0, OldBuffer)) return GetLastError();
68 *NewBuffer = 0;
69 return NERR_Success;
70 }
71 }
72
73 /************************************************************
74 * NetApiBufferSize (NETAPI32.@)
75 */
76 NET_API_STATUS WINAPI NetApiBufferSize(LPVOID Buffer, LPDWORD ByteCount)
77 {
78 DWORD dw;
79
80 TRACE("(%p, %p)\n", Buffer, ByteCount);
81 if (Buffer == NULL)
82 return ERROR_INVALID_PARAMETER;
83 dw = HeapSize(GetProcessHeap(), 0, Buffer);
84 TRACE("size: %d\n", dw);
85 if (dw != 0xFFFFFFFF)
86 *ByteCount = dw;
87 else
88 *ByteCount = 0;
89
90 return NERR_Success;
91 }