summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-06-26 11:24:03 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-07-01 21:50:40 -0400
commit2a60689a33a61f000bd90596b1289babcb861cd9 (patch)
tree3c47e4a88c0bbdde57bf42b8a5f1b9b6f08eee51 /tools/lib
parent13c230ab6e56c6ae3a968f01f4c6505b794cecad (diff)
tools lib: Adopt strreplace() from the kernel
We'll use it to further reduce the size of tools/perf/util/string.c, replacing the strxfrchar() equivalent function we have there. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-x3r61ikjrso1buygxwke8id3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/string.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 80472e6b3829..f2ae1b87c719 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -145,3 +145,19 @@ char *strim(char *s)
145 145
146 return skip_spaces(s); 146 return skip_spaces(s);
147} 147}
148
149/**
150 * strreplace - Replace all occurrences of character in string.
151 * @s: The string to operate on.
152 * @old: The character being replaced.
153 * @new: The character @old is replaced with.
154 *
155 * Returns pointer to the nul byte at the end of @s.
156 */
157char *strreplace(char *s, char old, char new)
158{
159 for (; *s; ++s)
160 if (*s == old)
161 *s = new;
162 return s;
163}