mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 18:11:20 +00:00
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>
This commit is contained in:
parent
13c230ab6e
commit
2a60689a33
2 changed files with 18 additions and 0 deletions
|
@ -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 *str_error_r(int errnum, char *buf, size_t buflen);
|
||||||
|
|
||||||
|
char *strreplace(char *s, char old, char new);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strstarts - does @str start with @prefix?
|
* strstarts - does @str start with @prefix?
|
||||||
* @str: string to examine
|
* @str: string to examine
|
||||||
|
|
|
@ -145,3 +145,19 @@ char *strim(char *s)
|
||||||
|
|
||||||
return skip_spaces(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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue