Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTP Resend #626

Merged
merged 4 commits into from
Dec 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
mbuf: add mbuf_dup
  • Loading branch information
sreimers committed Dec 28, 2022
commit 9845276341b56eda2e5b4fa870b7278f36423e11
1 change: 1 addition & 0 deletions include/re_mbuf.h
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ struct pl;
struct re_printf;

struct mbuf *mbuf_alloc(size_t size);
struct mbuf *mbuf_dup(struct mbuf *mbd);
struct mbuf *mbuf_alloc_ref(struct mbuf *mbr);
void mbuf_init(struct mbuf *mb);
void mbuf_reset(struct mbuf *mb);
28 changes: 28 additions & 0 deletions src/mbuf/mbuf.c
Original file line number Diff line number Diff line change
@@ -48,6 +48,34 @@ struct mbuf *mbuf_alloc(size_t size)
}


/**
* Duplicate memory buffer
*
* @param mbd Memory buffer to duplicate
*
* @return Duplicated memory buffer, NULL if no memory
*/
struct mbuf *mbuf_dup(struct mbuf *mbd)
{
struct mbuf *mb;

if (!mbd)
return NULL;

mb = mbuf_alloc(mbd->size);
if (!mb)
return NULL;

mb->size = mbd->size;
mb->pos = mbd->pos;
mb->end = mbd->end;

memcpy(mb->buf, mbd->buf, mbd->size);

return mb;
}


/**
* Allocate a new memory buffer with a reference to another mbuf
*