diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h index 3b2f5900276f0ef72b52e5a9c5c5f3d8a3176612..6f19c548ecc0bc96680a6a529ee844b829578396 100644 --- a/tools/perf/util/include/linux/string.h +++ b/tools/perf/util/include/linux/string.h @@ -1 +1,3 @@ #include + +void *memdup(const void *src, size_t len); diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 199bc4d8905d4ff75d31a60471673fac68470aec..32170590892d1f7f72a4e0629764f0806a0e5c62 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -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; +}