blob: ce390e84a4c00fdc75cd455760f966de4268ec8d [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* (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 <string.h>
23#include <stdlib.h>
24#include <sys/types.h>
25
26#include <openbsc/msgb.h>
27
28struct msgb *msgb_alloc(u_int16_t size)
29{
30 struct msgb *msg = malloc(sizeof(*msg) + size);
31
32 if (!msg)
33 return NULL;
34 memset(msg, 0, sizeof(*msg)+size);
35
36 msg->data_len = size;
37 msg->len = 0;
38 msg->data = msg->_data;
39
40 msg->head = msg->data;
41 msg->data = msg->data;
42 /* reset tail pointer */
43 msg->tail = msg->data;
44 //msg->end = msg->tail + size;
45
46 return msg;
47}
48
49void msgb_free(struct msgb *m)
50{
51 free(m);
52}
53
54void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
55{
56 llist_add_tail(&msg->list, queue);
57}
58
59struct msgb *msgb_dequeue(struct llist_head *queue)
60{
61 struct llist_head *lh;
62
63 if (llist_empty(queue))
64 return NULL;
65
66 lh = queue->next;
67 llist_del(lh);
68
69 return llist_entry(lh, struct msgb, list);
70}