summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-14 21:53:41 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-14 21:54:17 +0100
commitb0f91513cd8d06262711e18734cf415f8a17d7a6 (patch)
tree322b96f4905903cd7ea07abb5114825faae607d5 /include/osmocom/core
parent7be8c2b686701cf0b71eec0bd083d3b33e9a5c41 (diff)
msgb: introduce msgb_trim() and msgb_l3trim() to trim msgb's
Diffstat (limited to 'include/osmocom/core')
-rw-r--r--include/osmocom/core/msgb.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 9f46e6c6..ea2ee533 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -312,6 +312,34 @@ static inline void msgb_reserve(struct msgb *msg, int len)
msg->tail += len;
}
+/*! \brief Trim the msgb to a given absolute length
+ * \param[in] msg message buffer
+ * \param[in] len new total length of buffer
+ * \returns 0 in case of success, negative in case of error
+ */
+static inline int msgb_trim(struct msgb *msg, int len)
+{
+ if (msg->len < len)
+ return -1;
+
+ msg->len -= len;
+ msg->tail -= len;
+ if (msg->tail < msg->data)
+ msg->tail = msg->data;
+
+ return 0;
+}
+
+/*! \brief Trim the msgb to a given layer3 length
+ * \pram[in] msg message buffer
+ * \param[in] l3len new layer3 length
+ * \returns 0 in case of success, negative in case of error
+ */
+static inline int msgb_l3trim(struct msgb *msg, int l3len)
+{
+ return msgb_trim(msg, (msg->l3h - msg->data) + l3len);
+}
+
/*! \brief Allocate message buffer with specified headroom
* \param[in] size size in bytes, including headroom
* \param[in] headroom headroom in bytes