1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 2008 Bernhard Reutner-Fischer
7 * Licensed under GPLv2 or later, see file License in this tarball for details.
10 #ifdef __DO_STRRSTR_TEST
19 * The strrstr() function finds the last occurrence of the substring needle
20 * in the string haystack. The terminating nul characters are not compared.
22 char* FAST_FUNC strrstr(const char *haystack, const char *needle)
27 return (char*)haystack + strlen(haystack);
29 char *p = strstr(haystack, needle);
37 #ifdef __DO_STRRSTR_TEST
38 int main(int argc, char **argv)
45 { "baaabaaab", "aaa", 5 },
46 { "baaabaaaab", "aaa", 6 },
47 { "baaabaab", "aaa", 1 },
60 while (i < sizeof(test_array) / sizeof(test_array[0])) {
61 const char *r = strrstr(test_array[i].h, test_array[i].n);
62 printf("'%s' vs. '%s': '%s' - ", test_array[i].h, test_array[i].n, r);
64 r = test_array[i].h - 1;
65 printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED");