lib/string: Add standard strstr() function
Adding implementation of standard library strstr() See https://review.coreboot.org/c/coreboot/+/43741 for context. Change-Id: I63e26e98ed2dd15542f81c0a3a5e353bb93b7350 Signed-off-by: jbk@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/44085 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
e968e3762e
commit
683ac6f204
|
@ -29,6 +29,7 @@ int strcmp(const char *s1, const char *s2);
|
|||
int strncmp(const char *s1, const char *s2, int maxlen);
|
||||
int strspn(const char *str, const char *spn);
|
||||
int strcspn(const char *str, const char *spn);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
char *strtok_r(char *str, const char *delim, char **ptr);
|
||||
char *strtok(char *str, const char *delim);
|
||||
long atol(const char *str);
|
||||
|
|
|
@ -163,6 +163,16 @@ int strcspn(const char *str, const char *spn)
|
|||
return ret;
|
||||
}
|
||||
|
||||
char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
size_t needle_len = strlen(needle);
|
||||
for (; *haystack; haystack++) {
|
||||
if (!strncmp(haystack, needle, needle_len))
|
||||
return (char *)haystack;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strtok_r(char *str, const char *delim, char **ptr)
|
||||
{
|
||||
char *start;
|
||||
|
|
Loading…
Reference in New Issue