1 /* Copyright (C) 2000 Free Software Foundation. 2 3 Ensure all expected transformations of builtin strspn occur and 4 perform correctly. 5 6 Written by Kaveh R. Ghazi, 11/27/2000. */ 7 8 extern void abort (void); 9 typedef __SIZE_TYPE__ size_t; 10 extern size_t strspn (const char *, const char *); 11 extern char *strcpy (char *, const char *); 12 13 int main () 14 { 15 const char *const s1 = "hello world"; 16 char dst[64], *d2; 17 18 if (strspn (s1, "hello") != 5) 19 abort(); 20 if (strspn (s1+4, "hello") != 1) 21 abort(); 22 if (strspn (s1, "z") != 0) 23 abort(); 24 if (strspn (s1, "hello world") != 11) 25 abort(); 26 if (strspn (s1, "") != 0) 27 abort(); 28 strcpy (dst, s1); 29 if (strspn (dst, "") != 0) 30 abort(); 31 strcpy (dst, s1); d2 = dst; 32 if (strspn (++d2, "") != 0 || d2 != dst+1) 33 abort(); 34 strcpy (dst, s1); d2 = dst; 35 if (strspn (++d2+5, "") != 0 || d2 != dst+1) 36 abort(); 37 if (strspn ("", s1) != 0) 38 abort(); 39 strcpy (dst, s1); 40 if (strspn ("", dst) != 0) 41 abort(); 42 strcpy (dst, s1); d2 = dst; 43 if (strspn ("", ++d2) != 0 || d2 != dst+1) 44 abort(); 45 strcpy (dst, s1); d2 = dst; 46 if (strspn ("", ++d2+5) != 0 || d2 != dst+1) 47 abort(); 48 49 /* Test at least one instance of the __builtin_ style. We do this 50 to ensure that it works and that the prototype is correct. */ 51 if (__builtin_strspn (s1, "hello") != 5) 52 abort(); 53 54 return 0; 55 } 56 57 #ifdef __OPTIMIZE__ 58 /* When optimizing, all the above cases should be transformed into 59 something else. So any remaining calls to the original function 60 should abort. */ 61 static size_t 62 strspn (const char *s1, const char *s2) 63 { 64 abort(); 65 } 66 #endif 67