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

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>

+36 -19
+9
tools/include/linux/string.h
··· 1 + #ifndef _TOOLS_LINUX_STRING_H_ 2 + #define _TOOLS_LINUX_STRING_H_ 3 + 4 + 5 + #include <linux/types.h> /* for size_t */ 6 + 7 + void *memdup(const void *src, size_t len); 8 + 9 + #endif /* _LINUX_STRING_H_ */
+19
tools/lib/string.c
··· 1 + #include <stdlib.h> 2 + #include <string.h> 3 + #include <linux/string.h> 4 + 5 + /** 6 + * memdup - duplicate region of memory 7 + * 8 + * @src: memory region to duplicate 9 + * @len: memory region length 10 + */ 11 + void *memdup(const void *src, size_t len) 12 + { 13 + void *p = malloc(len); 14 + 15 + if (p) 16 + memcpy(p, src, len); 17 + 18 + return p; 19 + }
+2
tools/perf/MANIFEST
··· 22 22 tools/lib/bpf 23 23 tools/lib/hweight.c 24 24 tools/lib/rbtree.c 25 + tools/lib/string.c 25 26 tools/lib/symbol/kallsyms.c 26 27 tools/lib/symbol/kallsyms.h 27 28 tools/lib/util/find_next_bit.c ··· 51 50 tools/include/linux/poison.h 52 51 tools/include/linux/rbtree.h 53 52 tools/include/linux/rbtree_augmented.h 53 + tools/include/linux/string.h 54 54 tools/include/linux/types.h 55 55 tools/include/linux/err.h 56 56 include/asm-generic/bitops/arch_hweight.h
+6
tools/perf/util/Build
··· 21 21 libperf-y += perf_regs.o 22 22 libperf-y += path.o 23 23 libperf-y += rbtree.o 24 + libperf-y += libstring.o 24 25 libperf-y += bitmap.o 25 26 libperf-y += hweight.o 26 27 libperf-y += run-command.o ··· 139 138 140 139 CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" 141 140 CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" 141 + CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" 142 142 CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" 143 143 CFLAGS_parse-events.o += -Wno-redundant-decls 144 144 ··· 152 150 $(call if_changed_dep,cc_o_c) 153 151 154 152 $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE 153 + $(call rule_mkdir) 154 + $(call if_changed_dep,cc_o_c) 155 + 156 + $(OUTPUT)util/libstring.o: ../lib/string.c FORCE 155 157 $(call rule_mkdir) 156 158 $(call if_changed_dep,cc_o_c) 157 159
-3
tools/perf/util/include/linux/string.h
··· 1 - #include <string.h> 2 - 3 - void *memdup(const void *src, size_t len);
-16
tools/perf/util/string.c
··· 342 342 return s; 343 343 } 344 344 345 - /** 346 - * memdup - duplicate region of memory 347 - * @src: memory region to duplicate 348 - * @len: memory region length 349 - */ 350 - void *memdup(const void *src, size_t len) 351 - { 352 - void *p; 353 - 354 - p = malloc(len); 355 - if (p) 356 - memcpy(p, src, len); 357 - 358 - return p; 359 - } 360 - 361 345 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) 362 346 { 363 347 /*