Add test for uc_mbuf-copy_data

This commit is contained in:
Nils O. Selåsdal
2013-07-02 21:22:38 +02:00
parent bc65b3c421
commit 65c32810cb
3 changed files with 47 additions and 5 deletions
+21 -1
View File
@@ -5,6 +5,7 @@
uint8_t *uc_mbuf_put(struct MBuf *mbuf, uint32_t size)
{
uint8_t *data = mbuf->tail;
if (uc_mbuf_tailroom(mbuf) < size) {
return NULL;
}
@@ -28,6 +29,7 @@ uint8_t *uc_mbuf_push(struct MBuf *mbuf, uint32_t size)
uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size)
{
uint8_t *data = mbuf->head;
if (uc_mbuf_len(mbuf) < size) {
return NULL;
}
@@ -37,7 +39,6 @@ uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size)
return data;
}
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags)
{
mbuf->bufstart = buf;
@@ -97,5 +98,24 @@ void uc_mbuf_zero(struct MBuf *mbuf)
memset(mbuf->bufstart, 0, mbuf->allocated);
}
struct MBuf *uc_mbuf_copy_data(struct MBuf *mbuf)
{
uint32_t len;
struct MBuf *copy;
uint8_t *data;
len = uc_mbuf_len(mbuf);
copy = uc_mbuf_new_hr(len, uc_mbuf_headroom(mbuf));
if (copy == NULL) {
return NULL;
}
data = uc_mbuf_put(copy, len);
memcpy(data, mbuf->head, len);
return copy;
}
#undef UC_INLINE