From 503a04f0e951fdf36598568e6b8dba33bbf4aa2d Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Oct 2022 17:54:33 +0200 Subject: [PATCH] libc: Add strpbrk() --- libs/libc/include/string.h | 3 +++ libs/libc/src/string.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/libs/libc/include/string.h b/libs/libc/include/string.h index 5e495514..2d79f1a2 100644 --- a/libs/libc/include/string.h +++ b/libs/libc/include/string.h @@ -58,6 +58,9 @@ extern "C" /* Returns the length of the initial segment of str which consists entirely of bytes in accept. */ size_t strspn(const char* str, const char* accept); + /* Returns a pointer to the first occurrence of any character of b in a. */ + char* strpbrk(const char* a, const char* b); + /* Compares strings a and b. You might prefer to use the safer strncmp function. */ int strcmp(const char* a, const char* b); diff --git a/libs/libc/src/string.cpp b/libs/libc/src/string.cpp index 85e0e8b3..e4e1d235 100644 --- a/libs/libc/src/string.cpp +++ b/libs/libc/src/string.cpp @@ -167,6 +167,16 @@ extern "C" return s - str; } + char* strpbrk(const char* a, const char* b) + { + while (*a) + { + if (strchr(b, *a)) return const_cast(a); + a++; + } + return NULL; + } + char* strcat(char* dest, const char* src) { size_t dest_len = strlen(dest);