]>
Commit | Line | Data |
---|---|---|
dad253b4 AS |
1 | /* |
2 | * qpb_allocator.c | |
3 | * | |
4 | * @copyright Copyright (C) 2016 Sproute Networks, Inc. | |
5 | * | |
6 | * @author Avneesh Sachdev <avneesh@sproute.com> | |
7 | * | |
8 | * This file is part of Quagga. | |
9 | * | |
10 | * Quagga is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2, or (at your option) any | |
13 | * later version. | |
14 | * | |
15 | * Quagga is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
896014f4 DL |
20 | * You should have received a copy of the GNU General Public License along |
21 | * with this program; see the file COPYING; if not, write to the Free Software | |
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
dad253b4 AS |
23 | */ |
24 | ||
b45ac5f5 DL |
25 | #ifdef HAVE_CONFIG_H |
26 | #include "config.h" | |
27 | #endif | |
28 | ||
dad253b4 AS |
29 | #include "linear_allocator.h" |
30 | ||
31 | #include "qpb_allocator.h" | |
32 | ||
33 | /* | |
34 | * _qpb_alloc | |
35 | */ | |
d62a17ae | 36 | static void *_qpb_alloc(void *allocator_data, size_t size) |
dad253b4 | 37 | { |
d62a17ae | 38 | return linear_allocator_alloc(allocator_data, size); |
dad253b4 AS |
39 | } |
40 | ||
41 | /* | |
42 | * _qpb_free | |
43 | */ | |
d62a17ae | 44 | static void _qpb_free(void *allocator_data, void *ptr) |
dad253b4 | 45 | { |
d62a17ae | 46 | linear_allocator_free(allocator_data, ptr); |
dad253b4 AS |
47 | } |
48 | ||
a805d3bb | 49 | static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL}; |
dad253b4 AS |
50 | |
51 | /* | |
52 | * qpb_allocator_init_linear | |
53 | * | |
54 | * Initialize qpb_allocator_t with the given linear allocator. | |
55 | */ | |
d62a17ae | 56 | void qpb_allocator_init_linear(qpb_allocator_t *allocator, |
57 | linear_allocator_t *linear_allocator) | |
dad253b4 | 58 | { |
d62a17ae | 59 | *allocator = allocator_template; |
60 | allocator->allocator_data = linear_allocator; | |
dad253b4 | 61 | } |