Commit 89b5039f authored by Michael Niedermayer's avatar Michael Niedermayer

avutil/mem: add av_memdup()

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 663794f6
...@@ -229,6 +229,17 @@ char *av_strdup(const char *s) ...@@ -229,6 +229,17 @@ char *av_strdup(const char *s)
return ptr; return ptr;
} }
void *av_memdup(const void *p, size_t size)
{
void *ptr = NULL;
if (p) {
ptr = av_malloc(size);
if (ptr)
memcpy(ptr, p, size);
}
return ptr;
}
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem) void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
{ {
/* see similar ffmpeg.c:grow_array() */ /* see similar ffmpeg.c:grow_array() */
......
...@@ -179,6 +179,14 @@ av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si ...@@ -179,6 +179,14 @@ av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si
*/ */
char *av_strdup(const char *s) av_malloc_attrib; char *av_strdup(const char *s) av_malloc_attrib;
/**
* Duplicate the buffer p.
* @param p buffer to be duplicated
* @return Pointer to a newly allocated buffer containing a
* copy of p or NULL if the buffer cannot be allocated.
*/
void *av_memdup(const void *p, size_t size);
/** /**
* Free a memory block which has been allocated with av_malloc(z)() or * Free a memory block which has been allocated with av_malloc(z)() or
* av_realloc() and set the pointer pointing to it to NULL. * av_realloc() and set the pointer pointing to it to NULL.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment