]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
tools lib: Adopt strreplace() from the kernel
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 26 Jun 2019 15:24:03 +0000 (12:24 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 2 Jul 2019 01:50:40 +0000 (22:50 -0300)
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>
tools/include/linux/string.h
tools/lib/string.c

index e436f8037c87a5281207c72320f437020f00bbbf..a76d4df1043561273df21498086a061ff8c158fe 100644 (file)
@@ -19,6 +19,8 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);
 
 char *str_error_r(int errnum, char *buf, size_t buflen);
 
+char *strreplace(char *s, char old, char new);
+
 /**
  * strstarts - does @str start with @prefix?
  * @str: string to examine
index 80472e6b3829c3f519e59ce5e2c26cd7e47bc814..f2ae1b87c71952146c8ba03604ad44672808d97c 100644 (file)
@@ -145,3 +145,19 @@ char *strim(char *s)
 
        return skip_spaces(s);
 }
+
+/**
+ * strreplace - Replace all occurrences of character in string.
+ * @s: The string to operate on.
+ * @old: The character being replaced.
+ * @new: The character @old is replaced with.
+ *
+ * Returns pointer to the nul byte at the end of @s.
+ */
+char *strreplace(char *s, char old, char new)
+{
+       for (; *s; ++s)
+               if (*s == old)
+                       *s = new;
+       return s;
+}