mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
lib/string_helpers: Change returned value of the strreplace()
It's more useful to return the pointer to the string itself with strreplace(), so it may be used like attr->name = strreplace(name, '/', '_'); While at it, amend the kernel documentation. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230605170553.7835-3-andriy.shevchenko@linux.intel.com
This commit is contained in:
parent
7afb6d8fa8
commit
d01a77afd6
2 changed files with 9 additions and 5 deletions
|
@ -169,7 +169,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *memchr_inv(const void *s, int c, size_t n);
|
void *memchr_inv(const void *s, int c, size_t n);
|
||||||
char *strreplace(char *s, char old, char new);
|
char *strreplace(char *str, char old, char new);
|
||||||
|
|
||||||
extern void kfree_const(const void *x);
|
extern void kfree_const(const void *x);
|
||||||
|
|
||||||
|
|
|
@ -979,18 +979,22 @@ EXPORT_SYMBOL(__sysfs_match_string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strreplace - Replace all occurrences of character in string.
|
* strreplace - Replace all occurrences of character in string.
|
||||||
* @s: The string to operate on.
|
* @str: The string to operate on.
|
||||||
* @old: The character being replaced.
|
* @old: The character being replaced.
|
||||||
* @new: The character @old is replaced with.
|
* @new: The character @old is replaced with.
|
||||||
*
|
*
|
||||||
* Returns pointer to the nul byte at the end of @s.
|
* Replaces the each @old character with a @new one in the given string @str.
|
||||||
|
*
|
||||||
|
* Return: pointer to the string @str itself.
|
||||||
*/
|
*/
|
||||||
char *strreplace(char *s, char old, char new)
|
char *strreplace(char *str, char old, char new)
|
||||||
{
|
{
|
||||||
|
char *s = str;
|
||||||
|
|
||||||
for (; *s; ++s)
|
for (; *s; ++s)
|
||||||
if (*s == old)
|
if (*s == old)
|
||||||
*s = new;
|
*s = new;
|
||||||
return s;
|
return str;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(strreplace);
|
EXPORT_SYMBOL(strreplace);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue