Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Apr 2024 06:49:08 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 19703887666d - main - LinuxKPI: Add strnchr function
Message-ID:  <202404080649.4386n8og032621@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=19703887666da09c79c571bc78f0923bae62be91

commit 19703887666da09c79c571bc78f0923bae62be91
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-04-08 06:47:42 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-04-08 06:47:42 +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
---
 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 f745c2f6d343..13c8fee602dd 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -214,6 +214,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)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404080649.4386n8og032621>