diff --git a/kernel/include/std/string.h b/kernel/include/std/string.h index 6ea5d3fb..508ba10a 100644 --- a/kernel/include/std/string.h +++ b/kernel/include/std/string.h @@ -11,6 +11,8 @@ char* strncpy(char* dest, const char* src, size_t n); int strncmp(const char* s1, const char* s2, size_t n); char* strncat(char* dest, const char* src, size_t n); +char* strstr(char* haystack, char* needle); + void* memcpy(void* dest, const void* src, size_t n); void* memset(void* dest, int c, size_t n); int memcmp(const void* a, const void* b, size_t n); diff --git a/kernel/src/std/string.cpp b/kernel/src/std/string.cpp index 31919154..f0d130cd 100644 --- a/kernel/src/std/string.cpp +++ b/kernel/src/std/string.cpp @@ -66,6 +66,26 @@ char* strcat(char* dest, const char* src) return dest; } +char* strstr(char* haystack, char* needle) +{ + size_t needle_size = strlen(needle); + size_t haystack_size = strlen(haystack); + while (*haystack) + { + if (*haystack == *needle) + { + if (needle_size <= haystack_size) + { + if (!strncmp(haystack, needle, needle_size)) return haystack; + } + else { return NULL; } + } + haystack++; + haystack_size--; + } + return NULL; +} + void* memcpy(void* dest, const void* src, size_t n) { for (size_t i = 0; i < n; ++i) { *((char*)dest + i) = *((char*)src + i); }