git: 9319e47c1ab5 - stable/14 - LinuxKPI: Add strnchr function

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Thu, 01 Aug 2024 22:27:18 UTC
The branch stable/14 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=9319e47c1ab562d577d4359599aecb80a3dd7dbf

commit 9319e47c1ab562d577d4359599aecb80a3dd7dbf
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-04-08 06:47:42 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-08-01 21:09:37 +0000

    LinuxKPI: Add strnchr function
    
    strnchr() finds a character in a length limited string.
    
    Sponsored by:   Serenity CyberSecurity, LLC
    Reviewed by:    emaste
    MFC after:      1 month
    
    (cherry picked from commit 19703887666da09c79c571bc78f0923bae62be91)
---
 sys/compat/linuxkpi/common/include/linux/string.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index 9302c95e8636..1fae23ad902a 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -226,6 +226,21 @@ strscpy_pad(char* dst, const char* src, size_t len)
 	return (strscpy(dst, src, len));
 }
 
+static inline char *
+strnchr(const char *cp, size_t n, int ch)
+{
+	char *p;
+
+	for (p = __DECONST(char *, cp); n--; ++p) {
+		if (*p == ch)
+			return (p);
+		if (*p == '\0')
+			break;
+	}
+
+	return (NULL);
+}
+
 static inline void *
 memset32(uint32_t *b, uint32_t c, size_t len)
 {