git: a5e2a27dca4b - main - LinuxKPI: add strreplace() to string.h
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 25 Oct 2021 16:14:52 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=a5e2a27dca4bd5f4795b42ac598d4fff1c3a6eae
commit a5e2a27dca4bd5f4795b42ac598d4fff1c3a6eae
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2021-10-22 11:00:36 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2021-10-25 16:12:10 +0000
LinuxKPI: add strreplace() to string.h
Add strreplace() needed by a driver.
MFC after: 3 days
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D32597
---
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)
{