Alters the behavior of the 'Create NAT on tunnel' to also add the appropriate NAT...
[tomato.git] / release / src / router / busybox / libbb / strrstr.c
blobd8823fc5117631b5cda95690158d32f4f272b4c9
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Utility routines.
5 * Copyright (C) 2008 Bernhard Reutner-Fischer
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
10 #ifdef __DO_STRRSTR_TEST
11 #include <stdlib.h>
12 #include <string.h>
13 #include <stdio.h>
14 #else
15 #include "libbb.h"
16 #endif
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)
24 char *r = NULL;
26 if (!needle[0])
27 return (char*)haystack + strlen(haystack);
28 while (1) {
29 char *p = strstr(haystack, needle);
30 if (!p)
31 return r;
32 r = p;
33 haystack = p + 1;
37 #ifdef __DO_STRRSTR_TEST
38 int main(int argc, char **argv)
40 static const struct {
41 const char *h, *n;
42 int pos;
43 } test_array[] = {
44 /* 0123456789 */
45 { "baaabaaab", "aaa", 5 },
46 { "baaabaaaab", "aaa", 6 },
47 { "baaabaab", "aaa", 1 },
48 { "aaa", "aaa", 0 },
49 { "aaa", "a", 2 },
50 { "aaa", "bbb", -1 },
51 { "a", "aaa", -1 },
52 { "aaa", "", 3 },
53 { "", "aaa", -1 },
54 { "", "", 0 },
57 int i;
59 i = 0;
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);
63 if (r == NULL)
64 r = test_array[i].h - 1;
65 printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED");
66 i++;
69 return 0;
71 #endif