git: 19703887666d - main - LinuxKPI: Add strnchr function
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 08 Apr 2024 06:49:08 UTC
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) {