mirror of https://gerrit.osmocom.org/libosmocore
msgb: introduce msgb_trim() and msgb_l3trim() to trim msgb's
This commit is contained in:
parent
7be8c2b686
commit
b0f91513cd
|
@ -312,6 +312,34 @@ static inline void msgb_reserve(struct msgb *msg, int len)
|
||||||
msg->tail += 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
|
/*! \brief Allocate message buffer with specified headroom
|
||||||
* \param[in] size size in bytes, including headroom
|
* \param[in] size size in bytes, including headroom
|
||||||
* \param[in] headroom headroom in bytes
|
* \param[in] headroom headroom in bytes
|
||||||
|
|
Loading…
Reference in New Issue