summaryrefslogtreecommitdiff
path: root/userland/libc/string/strstr.c
blob: 9de0954262f65ac668c31dc6a1cdb2e1ff0b2612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <string.h>

char *strstr(const char *s1, const char *s2) {
  // If s2 points to a string with zero length, the function shall return s1.
  if ('\0' == *s2)
    return (char*)s1;
  for (; *s1; s1++) {
    const char *t1 = s1;
    const char *t2 = s2;
    int is_dif = 0;
    for (; *t2 && *t1; t1++, t2++) {
      if (*t2 != *t1) {
        is_dif = 1;
        break;
      }
    }
    if (!is_dif)
      return (char*)s1;
  }
  return NULL;
}