[FFmpeg-cvslog] avutil/mem: add av_memdup()

Michael Niedermayer git at videolan.org
Thu May 2 13:50:55 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Apr 28 00:49:14 2013 +0200| [89b5039ff265e0519261b07aa9bdd3ed7df6090c] | committer: Michael Niedermayer

avutil/mem: add av_memdup()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=89b5039ff265e0519261b07aa9bdd3ed7df6090c
---

 libavutil/mem.c |   11 +++++++++++
 libavutil/mem.h |    8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 687ec55..cfa4cbd 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -229,6 +229,17 @@ char *av_strdup(const char *s)
     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)
 {
     /* see similar ffmpeg.c:grow_array() */
diff --git a/libavutil/mem.h b/libavutil/mem.h
index ced9453..02395b7 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -180,6 +180,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;
 
 /**
+ * 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
  * av_realloc() and set the pointer pointing to it to NULL.
  * @param ptr Pointer to the pointer to the memory block which should



More information about the ffmpeg-cvslog mailing list