1/* Copyright (C) 2000, 2003, 2004 Free Software Foundation. 2 3 Ensure all expected transformations of builtin strrchr and rindex 4 occur and perform correctly. 5 6 Written by Jakub Jelinek, 11/7/2000. */ 7 8extern void abort (void); 9extern char *strrchr (const char *, int); 10extern char *rindex (const char *, int); 11 12char *bar = "hi world"; 13int x = 7; 14 15void 16main_test (void) 17{ 18 const char *const foo = "hello world"; 19 20 if (strrchr (foo, 'x')) 21 abort (); 22 if (strrchr (foo, 'o') != foo + 7) 23 abort (); 24 if (strrchr (foo, 'e') != foo + 1) 25 abort (); 26 if (strrchr (foo + 3, 'e')) 27 abort (); 28 if (strrchr (foo, '\0') != foo + 11) 29 abort (); 30 if (strrchr (bar, '\0') != bar + 8) 31 abort (); 32 if (strrchr (bar + 4, '\0') != bar + 8) 33 abort (); 34 if (strrchr (bar + (x++ & 3), '\0') != bar + 8) 35 abort (); 36 if (x != 8) 37 abort (); 38 /* Test only one instance of rindex since the code path is the same 39 as that of strrchr. */ 40 if (rindex ("hello", 'z') != 0) 41 abort (); 42 43 /* Test at least one instance of the __builtin_ style. We do this 44 to ensure that it works and that the prototype is correct. */ 45 if (__builtin_strrchr (foo, 'o') != foo + 7) 46 abort (); 47 if (__builtin_rindex (foo, 'o') != foo + 7) 48 abort (); 49} 50