]>
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 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with Quagga; see the file COPYING. If not, write to the Free | |
22 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 | * 02111-1307, USA. | |
24 | */ | |
25 | ||
26 | #include "linear_allocator.h" | |
27 | ||
28 | #include "qpb_allocator.h" | |
29 | ||
30 | /* | |
31 | * _qpb_alloc | |
32 | */ | |
ac4d0be5 | 33 | static void *_qpb_alloc(void *allocator_data, size_t size) |
dad253b4 | 34 | { |
ac4d0be5 | 35 | return linear_allocator_alloc(allocator_data, size); |
dad253b4 AS |
36 | } |
37 | ||
38 | /* | |
39 | * _qpb_free | |
40 | */ | |
ac4d0be5 | 41 | static void _qpb_free(void *allocator_data, void *ptr) |
dad253b4 | 42 | { |
ac4d0be5 | 43 | linear_allocator_free(allocator_data, ptr); |
dad253b4 AS |
44 | } |
45 | ||
ac4d0be5 | 46 | static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL, |
47 | 8192, NULL}; | |
dad253b4 AS |
48 | |
49 | /* | |
50 | * qpb_allocator_init_linear | |
51 | * | |
52 | * Initialize qpb_allocator_t with the given linear allocator. | |
53 | */ | |
ac4d0be5 | 54 | void qpb_allocator_init_linear(qpb_allocator_t *allocator, |
55 | linear_allocator_t *linear_allocator) | |
dad253b4 | 56 | { |
ac4d0be5 | 57 | *allocator = allocator_template; |
58 | allocator->allocator_data = linear_allocator; | |
dad253b4 | 59 | } |