summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-11-16 11:36:29 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-11-18 17:51:02 -0300
commit4ddd32741da87657113d964588ce13ee64b34820 (patch)
treec6ef98fadb95631fb72bf05c45a6f97b9ca92c04 /tools/lib
parent9a13c6587e2f0d5e80ce02f5f9ef62788b48d163 (diff)
downloadlinux-4ddd32741da87657113d964588ce13ee64b34820.tar.gz
linux-4ddd32741da87657113d964588ce13ee64b34820.tar.bz2
linux-4ddd32741da87657113d964588ce13ee64b34820.zip
tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c
That will contain more string functions with counterparts, sometimes verbatim copies, in the kernel. Acked-by: Wang Nan <wangnan0@huawei.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/n/tip-rah6g97kn21vfgmlramorz6o@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/string.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/lib/string.c b/tools/lib/string.c
new file mode 100644
index 000000000000..ecfd43a9b24e
--- /dev/null
+++ b/tools/lib/string.c
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <string.h>
+#include <linux/string.h>
+
+/**
+ * memdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ */
+void *memdup(const void *src, size_t len)
+{
+ void *p = malloc(len);
+
+ if (p)
+ memcpy(p, src, len);
+
+ return p;
+}