1 /* Copyright (C) 2000, 2003, 2004 Free Software Foundation.
3 Ensure all expected transformations of builtin strrchr and rindex
4 occur and perform correctly.
6 Written by Jakub Jelinek, 11/7/2000. */
8 extern void abort (void);
9 extern char *strrchr (const char *, int);
10 extern char *rindex (const char *, int);
12 char *bar
= "hi world";
18 const char *const foo
= "hello world";
20 if (strrchr (foo
, 'x'))
22 if (strrchr (foo
, 'o') != foo
+ 7)
24 if (strrchr (foo
, 'e') != foo
+ 1)
26 if (strrchr (foo
+ 3, 'e'))
28 if (strrchr (foo
, '\0') != foo
+ 11)
30 if (strrchr (bar
, '\0') != bar
+ 8)
32 if (strrchr (bar
+ 4, '\0') != bar
+ 8)
34 if (strrchr (bar
+ (x
++ & 3), '\0') != bar
+ 8)
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)
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)
47 if (__builtin_rindex (foo
, 'o') != foo
+ 7)