Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
b232e073 bdde3716

+19 -1
+2
tools/perf/util/include/linux/string.h
··· 1 1 #include <string.h> 2 + 3 + void *memdup(const void *src, size_t len);
+17 -1
tools/perf/util/string.c
··· 1 1 #include "util.h" 2 - #include "string.h" 2 + #include "linux/string.h" 3 3 4 4 #define K 1024LL 5 5 /* ··· 334 334 *(end + 1) = '\0'; 335 335 336 336 return s; 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; 337 353 }