xref: /reactos/dll/win32/netapi32/apibuf.c (revision 8a978a17)
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))
68             return GetLastError();
69         *NewBuffer = 0;
70         return NERR_Success;
71     }
72 }
73 
74 /************************************************************
75  *                NetApiBufferSize  (NETAPI32.@)
76  */
77 NET_API_STATUS WINAPI NetApiBufferSize(LPVOID Buffer, LPDWORD ByteCount)
78 {
79     DWORD dw;
80 
81     TRACE("(%p, %p)\n", Buffer, ByteCount);
82     if (Buffer == NULL)
83         return ERROR_INVALID_PARAMETER;
84     dw = HeapSize(GetProcessHeap(), 0, Buffer);
85     TRACE("size: %d\n", dw);
86     if (dw != 0xFFFFFFFF)
87         *ByteCount = dw;
88     else
89         *ByteCount = 0;
90 
91     return NERR_Success;
92 }
93