1 /* Copyright (C) 2000, 2003 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 int strcmp (const char *, const char *);
18 const char *const s1 = "hello world";
19 const char *const s2 = "";
23 if (strncat (dst, "", 100) != dst || strcmp (dst, s1))
26 if (strncat (dst, s2, 100) != dst || strcmp (dst, s1))
28 strcpy (dst, s1); d2 = dst;
29 if (strncat (++d2, s2, 100) != dst+1 || d2 != dst+1 || strcmp (dst, s1))
31 strcpy (dst, s1); d2 = dst;
32 if (strncat (++d2+5, s2, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
34 strcpy (dst, s1); d2 = dst;
35 if (strncat (++d2+5, s1+11, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
37 strcpy (dst, s1); d2 = dst;
38 if (strncat (++d2+5, s1, 0) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
40 strcpy (dst, s1); d2 = dst;
41 if (strncat (++d2+5, "", ++x) != dst+6 || d2 != dst+1 || x != 124
46 if (strncat (dst, "foo", 3) != dst || strcmp (dst, "hello worldfoo"))
49 if (strncat (dst, "foo", 100) != dst || strcmp (dst, "hello worldfoo"))
52 if (strncat (dst, s1, 100) != dst || strcmp (dst, "hello worldhello world"))
54 strcpy (dst, s1); d2 = dst;
55 if (strncat (++d2, s1, 100) != dst+1 || d2 != dst+1
56 || strcmp (dst, "hello worldhello world"))
58 strcpy (dst, s1); d2 = dst;
59 if (strncat (++d2+5, s1, 100) != dst+6 || d2 != dst+1
60 || strcmp (dst, "hello worldhello world"))
62 strcpy (dst, s1); d2 = dst;
63 if (strncat (++d2+5, s1+5, 100) != dst+6 || d2 != dst+1
64 || strcmp (dst, "hello world world"))
67 /* Test at least one instance of the __builtin_ style. We do this
68 to ensure that it works and that the prototype is correct. */
70 if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1))