perf tools: Add memdup function
authorJiri Olsa <jolsa@redhat.com>
Mon, 10 Sep 2012 16:50:17 +0000 (18:50 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 11 Sep 2012 15:04:41 +0000 (12:04 -0300)
Adding memdup function to duplicate region of memory.

  void *memdup(const void *src, size_t len)

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1347295819-23177-3-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/include/linux/string.h
tools/perf/util/string.c

index 3b2f5900276f0ef72b52e5a9c5c5f3d8a3176612..6f19c548ecc0bc96680a6a529ee844b829578396 100644 (file)
@@ -1 +1,3 @@
 #include <string.h>
+
+void *memdup(const void *src, size_t len);
index 199bc4d8905d4ff75d31a60471673fac68470aec..32170590892d1f7f72a4e0629764f0806a0e5c62 100644 (file)
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "string.h"
+#include "linux/string.h"
 
 #define K 1024LL
 /*
@@ -335,3 +335,19 @@ char *rtrim(char *s)
 
        return s;
 }
+
+/**
+ * memdup - duplicate region of memory
+ * @src: memory region to duplicate
+ * @len: memory region length
+ */
+void *memdup(const void *src, size_t len)
+{
+       void *p;
+
+       p = malloc(len);
+       if (p)
+               memcpy(p, src, len);
+
+       return p;
+}