diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-09-10 12:50:17 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-11 11:04:41 -0400 |
commit | b232e0732b1d763834c3d5b098d25d59337ba075 (patch) | |
tree | 8efb458e33231aa64779c0bfa5bf34dbf7f0d819 | |
parent | bdde37163e1fd474509aab90f5eaacee46100107 (diff) |
perf tools: Add memdup function
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>
-rw-r--r-- | tools/perf/util/include/linux/string.h | 2 | ||||
-rw-r--r-- | tools/perf/util/string.c | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h index 3b2f5900276..6f19c548ecc 100644 --- a/tools/perf/util/include/linux/string.h +++ b/tools/perf/util/include/linux/string.h | |||
@@ -1 +1,3 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | |||
3 | void *memdup(const void *src, size_t len); | ||
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 199bc4d8905..32170590892 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -1,5 +1,5 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "string.h" | 2 | #include "linux/string.h" |
3 | 3 | ||
4 | #define K 1024LL | 4 | #define K 1024LL |
5 | /* | 5 | /* |
@@ -335,3 +335,19 @@ char *rtrim(char *s) | |||
335 | 335 | ||
336 | return s; | 336 | return s; |
337 | } | 337 | } |
338 | |||
339 | /** | ||
340 | * memdup - duplicate region of memory | ||
341 | * @src: memory region to duplicate | ||
342 | * @len: memory region length | ||
343 | */ | ||
344 | void *memdup(const void *src, size_t len) | ||
345 | { | ||
346 | void *p; | ||
347 | |||
348 | p = malloc(len); | ||
349 | if (p) | ||
350 | memcpy(p, src, len); | ||
351 | |||
352 | return p; | ||
353 | } | ||