1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strncat occur and
6 Written by Kaveh R. Ghazi, 11/27/2000. */
8 extern void abort (void);
9 typedef __SIZE_TYPE__
size_t;
10 extern char *strncat (char *, const char *, size_t);
11 extern char *strcpy (char *, const char *);
12 extern char *strcmp (const char *, const char *);
17 const char *const s1
= "hello world";
18 const char *const s2
= "";
22 if (strncat (dst
, "", 100) != dst
|| strcmp (dst
, s1
))
25 if (strncat (dst
, s2
, 100) != dst
|| strcmp (dst
, s1
))
27 strcpy (dst
, s1
); d2
= dst
;
28 if (strncat (++d2
, s2
, 100) != dst
+1 || d2
!= dst
+1 || strcmp (dst
, s1
))
30 strcpy (dst
, s1
); d2
= dst
;
31 if (strncat (++d2
+5, s2
, 100) != dst
+6 || d2
!= dst
+1 || strcmp (dst
, s1
))
33 strcpy (dst
, s1
); d2
= dst
;
34 if (strncat (++d2
+5, s1
+11, 100) != dst
+6 || d2
!= dst
+1 || strcmp (dst
, s1
))
36 strcpy (dst
, s1
); d2
= dst
;
37 if (strncat (++d2
+5, s1
, 0) != dst
+6 || d2
!= dst
+1 || strcmp (dst
, s1
))
39 strcpy (dst
, s1
); d2
= dst
;
40 if (strncat (++d2
+5, "", ++x
) != dst
+6 || d2
!= dst
+1 || x
!= 124
45 if (strncat (dst
, "foo", 3) != dst
|| strcmp (dst
, "hello worldfoo"))
48 if (strncat (dst
, "foo", 100) != dst
|| strcmp (dst
, "hello worldfoo"))
51 if (strncat (dst
, s1
, 100) != dst
|| strcmp (dst
, "hello worldhello world"))
53 strcpy (dst
, s1
); d2
= dst
;
54 if (strncat (++d2
, s1
, 100) != dst
+1 || d2
!= dst
+1
55 || strcmp (dst
, "hello worldhello world"))
57 strcpy (dst
, s1
); d2
= dst
;
58 if (strncat (++d2
+5, s1
, 100) != dst
+6 || d2
!= dst
+1
59 || strcmp (dst
, "hello worldhello world"))
61 strcpy (dst
, s1
); d2
= dst
;
62 if (strncat (++d2
+5, s1
+5, 100) != dst
+6 || d2
!= dst
+1
63 || strcmp (dst
, "hello world world"))
66 /* Test at least one instance of the __builtin_ style. We do this
67 to ensure that it works and that the prototype is correct. */
69 if (__builtin_strncat (dst
, "", 100) != dst
|| strcmp (dst
, s1
))
76 /* When optimizing, all the above cases should be transformed into
77 something else. So any remaining calls to the original function
80 strncat (char *s1
, const char *s2
, size_t n
)