blob: f039be0032ace78fa06597cf76726815470a57d9 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* (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
Harald Welte8470bf22008-12-25 23:28:35 +000025#include <openbsc/msgb.h>
Harald Welte52b1f982008-12-23 20:25:15 +000026
27struct msgb *msgb_alloc(u_int16_t size)
28{
29 struct msgb *msg = malloc(sizeof(*msg) + size);
30
31 if (!msg)
32 return NULL;
Harald Welte702d8702008-12-26 20:25:35 +000033 memset(msg, 0, sizeof(*msg)+size);
Harald Welte52b1f982008-12-23 20:25:15 +000034
35 msg->data_len = size;
36 msg->len = 0;
37 msg->data = msg->_data;
38
39 msg->head = msg->data;
40 msg->data = msg->data;
41 /* reset tail pointer */
Harald Welte8470bf22008-12-25 23:28:35 +000042 msg->tail = msg->data;
Harald Welte52b1f982008-12-23 20:25:15 +000043 //msg->end = msg->tail + size;
44
45 return msg;
46}
47
48void msgb_free(struct msgb *m)
49{
50 free(m);
51}
Harald Welte8470bf22008-12-25 23:28:35 +000052
53void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
54{
55 llist_add_tail(&msg->list, queue);
56}
57
58struct msgb *msgb_dequeue(struct llist_head *queue)
59{
60 struct llist_head *lh;
61
62 if (llist_empty(queue))
63 return NULL;
64
65 lh = queue->next;
Harald Weltead384642008-12-26 10:20:07 +000066 llist_del(lh);
67
Harald Welte8470bf22008-12-25 23:28:35 +000068 return llist_entry(lh, struct msgb, list);
69}