Implement strcasestr

This commit is contained in:
Colin Leroy-Mira
2024-03-18 18:40:45 +01:00
parent 86317711e0
commit 82165c1a77
3 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
/*
** strcasestr.c
**
** Colin Leroy-Mira, 2024
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*****************************************************************************/
/* Code */
/*****************************************************************************/
char* __fastcall__ strcasestr(const char *str, const char *substr) {
size_t len_a = strlen(str);
size_t len_b = strlen(substr);
const char *end_str;
if (len_a < len_b)
return NULL;
len_a -= len_b;
for (end_str = str + len_a + 1; str < end_str; str++) {
if (!strncasecmp(str, substr, len_b))
return (char *)str;
}
return NULL;
}