| 671 | |
| 672 | |
| 673 | static const char *lmemfind (const char *s1, size_t l1, |
| 674 | const char *s2, size_t l2) { |
| 675 | if (l2 == 0) return s1; /* empty strings are everywhere */ |
| 676 | else if (l2 > l1) return NULL; /* avoids a negative 'l1' */ |
| 677 | else { |
| 678 | const char *init; /* to search for a '*s2' inside 's1' */ |
| 679 | l2--; /* 1st char will be checked by 'memchr' */ |
| 680 | l1 = l1-l2; /* 's2' cannot be found after that */ |
| 681 | while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { |
| 682 | init++; /* 1st char is already checked */ |
| 683 | if (memcmp(init, s2+1, l2) == 0) |
| 684 | return init-1; |
| 685 | else { /* correct 'l1' and 's1' to try again */ |
| 686 | l1 -= init-s1; |
| 687 | s1 = init; |
| 688 | } |
| 689 | } |
| 690 | return NULL; /* not found */ |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
| 695 | /* |