diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2024-03-04 20:00:17 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-03-05 16:28:06 +0100 |
commit | b823168b76ff9b2ae12730197dd73a06ade728d6 (patch) | |
tree | b536fea9ecfd3d8b5a958bd304a12ea5b72676e7 /lib | |
parent | 402dae62ce82283bab70da32c06fff4e012e45c9 (diff) | |
download | barebox-b823168b76ff9b2ae12730197dd73a06ade728d6.tar.gz barebox-b823168b76ff9b2ae12730197dd73a06ade728d6.tar.xz |
lib: string: import Linux strreplace helper
This helper replaces all occurrences of a given character in a string.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20240304190038.3486881-93-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/string.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index 695e50bc8f..374f326143 100644 --- a/lib/string.c +++ b/lib/string.c @@ -1028,3 +1028,24 @@ char *strjoin(const char *separator, char **arr, size_t arrlen) return buf; } EXPORT_SYMBOL(strjoin); + +/** + * strreplace - Replace all occurrences of character in string. + * @str: The string to operate on. + * @old: The character being replaced. + * @new: The character @old is replaced with. + * + * Replaces the each @old character with a @new one in the given string @str. + * + * Return: pointer to the string @str itself. + */ +char *strreplace(char *str, char old, char new) +{ + char *s = str; + + for (; *s; ++s) + if (*s == old) + *s = new; + return str; +} +EXPORT_SYMBOL(strreplace); |