Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame^] | 1 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <unistd.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include "msgb.h" |
| 26 | |
| 27 | struct msgb *msgb_alloc(u_int16_t size) |
| 28 | { |
| 29 | struct msgb *msg = malloc(sizeof(*msg) + size); |
| 30 | |
| 31 | if (!msg) |
| 32 | return NULL; |
| 33 | |
| 34 | msg->data_len = size; |
| 35 | msg->len = 0; |
| 36 | msg->data = msg->_data; |
| 37 | |
| 38 | msg->head = msg->data; |
| 39 | msg->data = msg->data; |
| 40 | /* reset tail pointer */ |
| 41 | msg->tail = msg->data - msg->head; |
| 42 | //msg->end = msg->tail + size; |
| 43 | |
| 44 | return msg; |
| 45 | } |
| 46 | |
| 47 | void msgb_free(struct msgb *m) |
| 48 | { |
| 49 | free(m); |
| 50 | } |