summaryrefslogtreecommitdiff
path: root/apps/plugins/picotts/strstr.c
blob: 48a4129db380eff72ffaf64a5a1579a08635c846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "plugin.h"

char *strstr(const char *haystack, const char *needle) {
  size_t nl=rb->strlen(needle);
  size_t hl=rb->strlen(haystack);
  int i;
  if (!nl) goto found;
  if (nl>hl) return 0;
  for (i=hl-nl+1;LIKELY(i); --i) {
    if (*haystack==*needle && !rb->memcmp(haystack,needle,nl))
found:
      return (char*)haystack;
    ++haystack;
  }
  return 0;
}