Skip to content

Commit

Permalink
perf tools: Add memdup function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Sep 11, 2012
1 parent bdde371 commit b232e07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tools/perf/util/include/linux/string.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#include <string.h>

void *memdup(const void *src, size_t len);
18 changes: 17 additions & 1 deletion tools/perf/util/string.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "util.h"
#include "string.h"
#include "linux/string.h"

#define K 1024LL
/*
Expand Down Expand Up @@ -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;
}

0 comments on commit b232e07

Please sign in to comment.