git: 9d2d8a27d017 - stable/13 - LinuxKPI: add strreplace() to string.h

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Fri, 19 Nov 2021 00:02:46 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=9d2d8a27d017c19e685c78a9cb7c6802ea793749

commit 9d2d8a27d017c19e685c78a9cb7c6802ea793749
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2021-10-22 11:00:36 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2021-11-19 00:01:26 +0000

    LinuxKPI: add strreplace() to string.h
    
    Add strreplace() needed by a driver.
    
    (cherry picked from commit a5e2a27dca4bd5f4795b42ac598d4fff1c3a6eae)
---
 sys/compat/linuxkpi/common/include/linux/string.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index 659a48d93596..a757464bf02b 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -167,6 +167,19 @@ str_has_prefix(const char *str, const char *prefix)
 	return (strncmp(str, prefix, len) == 0 ? len : 0);
 }
 
+static inline char *
+strreplace(char *str, char old, char new)
+{
+	char *p;
+
+	p = strchrnul(str, old);
+	while (p != NULL && *p != '\0') {
+		*p = new;
+		p = strchrnul(str, old);
+	}
+	return (p);
+}
+
 static inline ssize_t
 strscpy(char* dst, const char* src, size_t len)
 {